From c1ec410c8bf342e7d578237c6be543b605501010 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 10 Mar 2020 18:06:45 +0100 Subject: [PATCH] create cell uri on the extension host, expose as `NotebookCell#uri` --- src/vs/vscode.proposed.d.ts | 1 + .../api/browser/mainThreadNotebook.ts | 15 ++++----------- .../workbench/api/common/extHost.protocol.ts | 1 + src/vs/workbench/api/common/extHostNotebook.ts | 18 ++++++++++++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 9834f3e20a0..311be8bb15b 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1527,6 +1527,7 @@ declare module 'vscode' { export type CellOutput = CellStreamOutput | CellErrorOutput | CellDisplayOutput; export interface NotebookCell { + readonly uri: Uri; handle: number; language: string; cellKind: CellKind; diff --git a/src/vs/workbench/api/browser/mainThreadNotebook.ts b/src/vs/workbench/api/browser/mainThreadNotebook.ts index 485b66b5e91..b1b01c635e4 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebook.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebook.ts @@ -9,7 +9,7 @@ import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { URI, UriComponents } from 'vs/base/common/uri'; import { INotebookService, IMainNotebookController } from 'vs/workbench/contrib/notebook/browser/notebookService'; import { Emitter, Event } from 'vs/base/common/event'; -import { ICell, IOutput, INotebook, INotebookMimeTypeSelector, NOTEBOOK_DISPLAY_ORDER, NotebookCellsSplice, NotebookCellOutputsSplice, generateCellPath, CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { ICell, IOutput, INotebook, INotebookMimeTypeSelector, NOTEBOOK_DISPLAY_ORDER, NotebookCellsSplice, NotebookCellOutputsSplice, CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { PieceTreeTextBufferFactory, PieceTreeTextBufferBuilder } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder'; @@ -37,12 +37,11 @@ export class MainThreadCell implements ICell { this._onDidChangeDirtyState.fire(newState); } - readonly uri: URI; private _buffer: PieceTreeTextBufferFactory | null = null; constructor( - parent: MainThreadNotebookDocument, + readonly uri: URI, public handle: number, public source: string[], public language: string, @@ -50,12 +49,6 @@ export class MainThreadCell implements ICell { outputs: IOutput[] ) { this._outputs = outputs; - this.uri = URI.from({ - scheme: 'vscode-notebook', - authority: parent.viewType, - path: generateCellPath(cellKind, handle), - query: parent.uri.toString() - }); } spliceNotebookCellOutputs(splices: NotebookCellOutputsSplice[]): void { @@ -134,7 +127,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook async createRawCell(viewType: string, uri: URI, index: number, language: string, type: CellKind): Promise { let cell = await this._proxy.$createEmptyCell(viewType, uri, index, language, type); if (cell) { - let mainCell = new MainThreadCell(this, cell.handle, cell.source, cell.language, cell.cellKind, cell.outputs); + let mainCell = new MainThreadCell(URI.revive(cell.uri), cell.handle, cell.source, cell.language, cell.cellKind, cell.outputs); this._mapping.set(cell.handle, mainCell); this.cells.splice(index, 0, mainCell); @@ -178,7 +171,7 @@ export class MainThreadNotebookDocument extends Disposable implements INotebook splices.reverse().forEach(splice => { let cellDtos = splice[2]; let newCells = cellDtos.map(cell => { - let mainCell = new MainThreadCell(this, cell.handle, cell.source, cell.language, cell.cellKind, cell.outputs || []); + let mainCell = new MainThreadCell(URI.revive(cell.uri), cell.handle, cell.source, cell.language, cell.cellKind, cell.outputs || []); this._mapping.set(cell.handle, mainCell); let dirtyStateListener = mainCell.onDidChangeDirtyState((cellState) => { this.isDirty = this.isDirty || cellState; diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 96fcbf3bebf..d7eb4d7e86d 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -648,6 +648,7 @@ export enum CellOutputKind { export interface ICellDto { handle: number; + uri: UriComponents, source: string[]; language: string; cellKind: CellKind; diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 614d3b1594d..d0f274f21a4 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -12,13 +12,11 @@ import { DisposableStore, Disposable } from 'vs/base/common/lifecycle'; import { readonly } from 'vs/base/common/errors'; import { Emitter, Event } from 'vs/base/common/event'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; -import { INotebookDisplayOrder, parseCellUri, parseCellHandle, ITransformedDisplayOutputDto, IOrderedMimeType, IStreamOutput, IErrorOutput, mimeTypeSupportedByCore, IOutput, sortMimeTypes, diff } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { INotebookDisplayOrder, parseCellUri, parseCellHandle, ITransformedDisplayOutputDto, IOrderedMimeType, IStreamOutput, IErrorOutput, mimeTypeSupportedByCore, IOutput, sortMimeTypes, diff, generateCellPath } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { ISplice } from 'vs/base/common/sequence'; export class ExtHostCell implements vscode.NotebookCell { - private static _handlePool: number = 0; - readonly handle = ExtHostCell._handlePool++; public source: string[]; private _outputs: any[]; private _onDidChangeOutputs = new Emitter[]>(); @@ -28,6 +26,8 @@ export class ExtHostCell implements vscode.NotebookCell { private _outputMapping = new Set(); constructor( + readonly handle: number, + readonly uri: URI, private _content: string, public cellKind: CellKind, public language: string, @@ -182,6 +182,7 @@ export class ExtHostNotebookDocument extends Disposable implements vscode.Notebo } return { + uri: cell.uri, handle: cell.handle, source: cell.source, language: cell.language, @@ -330,6 +331,7 @@ export class ExtHostNotebookDocument extends Disposable implements vscode.Notebo export class ExtHostNotebookEditor extends Disposable implements vscode.NotebookEditor { private _viewColumn: vscode.ViewColumn | undefined; + private static _cellhandlePool: number = 0; constructor( viewType: string, @@ -385,7 +387,14 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook } createCell(content: string, language: string, type: CellKind, outputs: vscode.CellOutput[]): vscode.NotebookCell { - let cell = new ExtHostCell(content, type, language, outputs); + const handle = ExtHostNotebookEditor._cellhandlePool++; + const uri = URI.from({ + scheme: 'vscode-notebook', + authority: this.document.viewType, + path: generateCellPath(type, handle), + query: this.document.uri.toString() + }); + const cell = new ExtHostCell(handle, uri, content, type, language, outputs); return cell; } @@ -581,6 +590,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN return { + uri: rawCell.uri, handle: rawCell.handle, source: rawCell.source, language: rawCell.language,