提交 6db3625e 编写于 作者: J Johannes Rieken

add ICell#uri and expose INotebook#viewType

上级 fc460707
...@@ -41,7 +41,10 @@ export class MainThreadCell implements ICell { ...@@ -41,7 +41,10 @@ export class MainThreadCell implements ICell {
this._onDidChangeDirtyState.fire(newState); this._onDidChangeDirtyState.fire(newState);
} }
readonly uri: URI;
constructor( constructor(
parent: MainThreadNotebookDocument,
public handle: number, public handle: number,
public source: string[], public source: string[],
public language: string, public language: string,
...@@ -49,6 +52,12 @@ export class MainThreadCell implements ICell { ...@@ -49,6 +52,12 @@ export class MainThreadCell implements ICell {
outputs: IOutput[] outputs: IOutput[]
) { ) {
this._outputs = outputs; this._outputs = outputs;
this.uri = URI.from({
scheme: 'vscode-notebook',
authority: parent.viewType,
path: `/cell_${handle}.${cell_type === 'markdown' ? 'md' : 'py'}`,
query: parent.uri.toString()
});
} }
save() { save() {
...@@ -114,7 +123,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook ...@@ -114,7 +123,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook
if (this.cells.length === 0) { if (this.cells.length === 0) {
newCells.forEach(cell => { newCells.forEach(cell => {
let mainCell = new MainThreadCell(cell.handle, cell.source, cell.language, cell.cell_type, cell.outputs); let mainCell = new MainThreadCell(this, cell.handle, cell.source, cell.language, cell.cell_type, cell.outputs);
this._mapping.set(cell.handle, mainCell); this._mapping.set(cell.handle, mainCell);
this.cells.push(mainCell); this.cells.push(mainCell);
let dirtyStateListener = mainCell.onDidChangeDirtyState((cellState) => { let dirtyStateListener = mainCell.onDidChangeDirtyState((cellState) => {
...@@ -141,7 +150,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook ...@@ -141,7 +150,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook
async createRawCell(viewType: string, uri: URI, index: number, language: string, type: 'markdown' | 'code'): Promise<MainThreadCell | undefined> { async createRawCell(viewType: string, uri: URI, index: number, language: string, type: 'markdown' | 'code'): Promise<MainThreadCell | undefined> {
let cell = await this._proxy.$createEmptyCell(viewType, uri, index, language, type); let cell = await this._proxy.$createEmptyCell(viewType, uri, index, language, type);
if (cell) { if (cell) {
let mainCell = new MainThreadCell(cell.handle, cell.source, cell.language, cell.cell_type, cell.outputs); let mainCell = new MainThreadCell(this, cell.handle, cell.source, cell.language, cell.cell_type, cell.outputs);
this._mapping.set(cell.handle, mainCell); this._mapping.set(cell.handle, mainCell);
this.cells.splice(index, 0, mainCell); this.cells.splice(index, 0, mainCell);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as glob from 'vs/base/common/glob'; import * as glob from 'vs/base/common/glob';
import { ExtHostNotebookShape, IMainContext, MainThreadNotebookShape, MainContext } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostNotebookShape, IMainContext, MainThreadNotebookShape, MainContext, ICellDto } from 'vs/workbench/api/common/extHost.protocol';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { Disposable as VSCodeDisposable } from './extHostTypes'; import { Disposable as VSCodeDisposable } from './extHostTypes';
import { URI, UriComponents } from 'vs/base/common/uri'; import { URI, UriComponents } from 'vs/base/common/uri';
...@@ -13,7 +13,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle'; ...@@ -13,7 +13,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { readonly } from 'vs/base/common/errors'; import { readonly } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { ICell, INotebookDisplayOrder } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { INotebookDisplayOrder } from 'vs/workbench/contrib/notebook/common/notebookCommon';
interface ExtHostOutputDisplayOrder { interface ExtHostOutputDisplayOrder {
defaultOrder: glob.ParsedPattern[]; defaultOrder: glob.ParsedPattern[];
...@@ -500,7 +500,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN ...@@ -500,7 +500,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
return provider.provider.executeCell(document!, cell); return provider.provider.executeCell(document!, cell);
} }
async $createEmptyCell(viewType: string, uri: URI, index: number, language: string, type: 'markdown' | 'code'): Promise<ICell | undefined> { async $createEmptyCell(viewType: string, uri: URI, index: number, language: string, type: 'markdown' | 'code'): Promise<ICellDto | undefined> {
let provider = this._notebookProviders.get(viewType); let provider = this._notebookProviders.get(viewType);
if (provider) { if (provider) {
......
...@@ -121,7 +121,7 @@ class CellContentProvider implements ITextModelContentProvider { ...@@ -121,7 +121,7 @@ class CellContentProvider implements ITextModelContentProvider {
return null; return null;
} }
for (let cell of notebook.cells) { for (let cell of notebook.cells) {
if (cell.handle === data.cellHandle) { if (cell.uri.toString() === resource.toString()) {
return this._modelService.createModel( return this._modelService.createModel(
cell.source.join('\n'), cell.source.join('\n'),
this._modeService.createByFilepathOrFirstLine(resource, cell.source[0]), this._modeService.createByFilepathOrFirstLine(resource, cell.source[0]),
......
...@@ -24,7 +24,7 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; ...@@ -24,7 +24,7 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorOptions, IEditorMemento, IEditorControl } from 'vs/workbench/common/editor'; import { EditorOptions, IEditorMemento, IEditorControl } from 'vs/workbench/common/editor';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookEditorInput, NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput'; import { NotebookEditorInput, NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { INotebookService, createCellUri, parseCellUri } from 'vs/workbench/contrib/notebook/browser/notebookService'; import { INotebookService, parseCellUri } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/output/outputRenderer'; import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/output/outputRenderer';
import { BackLayerWebView } from 'vs/workbench/contrib/notebook/browser/renderers/backLayerWebView'; import { BackLayerWebView } from 'vs/workbench/contrib/notebook/browser/renderers/backLayerWebView';
import { CodeCellRenderer, MarkdownCellRenderer, NotebookCellListDelegate } from 'vs/workbench/contrib/notebook/browser/renderers/cellRenderer'; import { CodeCellRenderer, MarkdownCellRenderer, NotebookCellListDelegate } from 'vs/workbench/contrib/notebook/browser/renderers/cellRenderer';
...@@ -160,7 +160,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { ...@@ -160,7 +160,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
if (data && that.notebook?.uri.toString() === data.notebook.toString()) { if (data && that.notebook?.uri.toString() === data.notebook.toString()) {
for (let i = 0; i < that.list!.length; i++) { for (let i = 0; i < that.list!.length; i++) {
const item = that.list!.element(i); const item = that.list!.element(i);
if (item.cell.handle === data.cellHandle) { if (item.cell.uri.toString() === input.resource.toString()) {
that.list!.reveal(i, 0.2); that.list!.reveal(i, 0.2);
const editor = that.renderedEditors.get(item); const editor = that.renderedEditors.get(item);
if (!editor) { if (!editor) {
...@@ -318,7 +318,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { ...@@ -318,7 +318,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
this.webview.updateRendererPreloads(this.notebook.renderers); this.webview.updateRendererPreloads(this.notebook.renderers);
this.viewType = input.viewType; this.viewType = input.viewType;
this.viewCells = await Promise.all(this.notebook!.cells.map(async cell => { this.viewCells = await Promise.all(this.notebook!.cells.map(async cell => {
const uri = createCellUri(input.viewType!, this.notebook!, cell); const uri = cell.uri;
const ref = await this.textModelService.createModelReference(uri); const ref = await this.textModelService.createModelReference(uri);
const isEditing = viewState && viewState.editingCells[cell.handle]; const isEditing = viewState && viewState.editingCells[cell.handle];
return this.instantiationService.createInstance(CellViewModel, input.viewType!, this.notebook!.handle, cell, ref.object.textEditorModel, !!isEditing); return this.instantiationService.createInstance(CellViewModel, input.viewType!, this.notebook!.handle, cell, ref.object.textEditorModel, !!isEditing);
...@@ -453,7 +453,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { ...@@ -453,7 +453,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
const insertIndex = direction === 'above' ? index : index + 1; const insertIndex = direction === 'above' ? index : index + 1;
let newModeCell = await this.notebookService.createNotebookCell(this.viewType!, this.notebook!.uri, insertIndex, language, type); let newModeCell = await this.notebookService.createNotebookCell(this.viewType!, this.notebook!.uri, insertIndex, language, type);
let uri = createCellUri(this.viewType!, this.notebook!, newModeCell!); let uri = newModeCell!.uri;
let ref = await this.textModelService.createModelReference(uri); let ref = await this.textModelService.createModelReference(uri);
let newCell = this.instantiationService.createInstance(CellViewModel, this.viewType!, this.notebook!.handle, newModeCell!, ref.object.textEditorModel, false); let newCell = this.instantiationService.createInstance(CellViewModel, this.viewType!, this.notebook!.handle, newModeCell!, ref.object.textEditorModel, false);
......
...@@ -11,31 +11,16 @@ import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/noteb ...@@ -11,31 +11,16 @@ import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/noteb
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol'; import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import { INotebook, ICell, INotebookMimeTypeSelector } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { INotebook, ICell, INotebookMimeTypeSelector } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { basename, extname } from 'vs/base/common/path';
export function createCellUri(viewType: string, notebook: INotebook, cell: ICell): URI { export function parseCellUri(resource: URI): { viewType: string, notebook: URI } | undefined {
//vscode-notebook://<viewType>/cell_<cellHandle>.ext
// @todo Jo,Peng: `authority` will be transformed to lower case in `URI.toString()`, so we won't retrive the same viewType later on.
return URI.from({
scheme: 'vscode-notebook',
authority: viewType,
path: `/cell_${cell.handle}.${cell.cell_type === 'markdown' ? 'md' : 'py'}`,
query: notebook.uri.toString()
});
}
export function parseCellUri(resource: URI): { viewType: string, notebook: URI, cellHandle: number } | undefined {
//vscode-notebook://<viewType>/cell_<cellHandle>.ext //vscode-notebook://<viewType>/cell_<cellHandle>.ext
if (resource.scheme !== 'vscode-notebook') { if (resource.scheme !== 'vscode-notebook') {
return undefined; return undefined;
} }
const match = /cell_(\d+)/.exec(basename(resource.path, extname(resource.path))); // @todo Jo,Peng: `authority` will be transformed to lower case in `URI.toString()`, so we won't retrive the same viewType later on.
if (!match) {
return undefined;
}
const viewType = resource.authority; const viewType = resource.authority;
const notebook = URI.parse(resource.query); const notebook = URI.parse(resource.query);
return { viewType, notebook, cellHandle: parseInt(match[1]) }; return { viewType, notebook };
} }
function MODEL_ID(resource: URI): string { function MODEL_ID(resource: URI): string {
......
...@@ -94,6 +94,7 @@ export type IOutput = IGenericOutput; ...@@ -94,6 +94,7 @@ export type IOutput = IGenericOutput;
* @internal * @internal
*/ */
export interface ICell { export interface ICell {
readonly uri: URI;
handle: number; handle: number;
source: string[]; source: string[];
language: string; language: string;
...@@ -122,6 +123,7 @@ export interface IMetadata { ...@@ -122,6 +123,7 @@ export interface IMetadata {
*/ */
export interface INotebook { export interface INotebook {
handle: number; handle: number;
viewType: string;
// metadata: IMetadata; // metadata: IMetadata;
readonly uri: URI; readonly uri: URI;
languages: string[]; languages: string[];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册