diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 2cd2da1b021..0566d3c40b5 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -962,16 +962,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN // Serialized INotebookCellActionContext processArgument: (arg) => { if (arg && arg.$mid === 12) { - const documentHandle = arg.notebookEditor?.notebookHandle; + const notebookUri = arg.notebookEditor?.notebookUri; const cellHandle = arg.cell.handle; - for (const value of this._editors) { - if (value[1].editor.notebookData.handle === documentHandle) { - const cell = value[1].editor.notebookData.getCell(cellHandle); - if (cell) { - return cell.cell; - } - } + const data = this._documents.get(notebookUri); + const cell = data?.getCell(cellHandle); + if (cell) { + return cell.cell; } } return arg; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index a60746ceea9..03021e5ba4d 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -266,9 +266,9 @@ export class NotebookEditor extends EditorPane { super.dispose(); } - toJSON(): object { - return { - notebookHandle: this.viewModel?.handle - }; - } + // toJSON(): object { + // return { + // notebookHandle: this.viewModel?.handle + // }; + // } } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index b2588dd631b..03aac260dd6 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -1735,9 +1735,9 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor super.dispose(); } - toJSON(): object { + toJSON(): { notebookUri: URI | undefined } { return { - notebookHandle: this.viewModel?.handle + notebookUri: this.viewModel?.uri, }; } } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts index ad28bde4973..3743654a065 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts @@ -225,7 +225,6 @@ class ModelData implements IDisposable { } export class NotebookService extends Disposable implements INotebookService, ICustomEditorViewTypesHandler { declare readonly _serviceBrand: undefined; - static mainthreadNotebookDocumentHandle: number = 0; private readonly _notebookProviders = new Map(); notebookProviderInfoStore: NotebookProviderInfoStore; notebookRenderersInfoStore: NotebookOutputRendererInfoStore = new NotebookOutputRendererInfoStore(); @@ -622,7 +621,7 @@ export class NotebookService extends Disposable implements INotebookService, ICu return notebookModel; } else { - notebookModel = this._instantiationService.createInstance(NotebookTextModel, NotebookService.mainthreadNotebookDocumentHandle++, viewType, provider.controller.supportBackup, uri); + notebookModel = this._instantiationService.createInstance(NotebookTextModel, viewType, provider.controller.supportBackup, uri); await provider.controller.createNotebook(notebookModel, backupId); } diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts index b06cb8d453a..f3f812d3dda 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts @@ -170,10 +170,6 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD return this._notebook; } - get handle() { - return this._notebook.handle; - } - get resolvedLanguages() { return this._notebook.resolvedLanguages; } diff --git a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts index 5400cb3a35a..e30e36efe6f 100644 --- a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts +++ b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts @@ -164,10 +164,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel private _operationManager: NotebookOperationManager; constructor( - public handle: number, - public viewType: string, - public supportBackup: boolean, - public uri: URI, + readonly viewType: string, + readonly supportBackup: boolean, + readonly uri: URI, @IUndoRedoService private _undoService: IUndoRedoService, @ITextModelService private _modelService: ITextModelService, @IModeService private readonly _modeService: IModeService, diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index b8753742ac4..fe94a91d7ce 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -270,7 +270,6 @@ export interface IMetadata { } export interface INotebookTextModel { - handle: number; viewType: string; metadata: NotebookDocumentMetadata readonly uri: URI; diff --git a/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts b/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts index 437aecd46ac..5e2037d1a14 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts @@ -25,7 +25,7 @@ suite('NotebookViewModel', () => { const modeService = instantiationService.get(IModeService); test('ctor', function () { - const notebook = new NotebookTextModel(0, 'notebook', false, URI.parse('test'), undoRedoService, textModelService, modeService); + const notebook = new NotebookTextModel('notebook', false, URI.parse('test'), undoRedoService, textModelService, modeService); const model = new NotebookEditorTestModel(notebook); const eventDispatcher = new NotebookEventDispatcher(); const viewModel = new NotebookViewModel('notebook', model.notebook, eventDispatcher, null, instantiationService, blukEditService, undoRedoService); diff --git a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts index 33146612f34..adb0abc97d0 100644 --- a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts @@ -393,7 +393,7 @@ export function withTestNotebook(instantiationService: TestInstantiationService, const viewType = 'notebook'; const editor = new TestNotebookEditor(); - const notebook = new NotebookTextModel(0, viewType, false, URI.parse('test'), undoRedoService, textModelService, modeService); + const notebook = new NotebookTextModel(viewType, false, URI.parse('test'), undoRedoService, textModelService, modeService); notebook.initialize(cells.map(cell => { return { source: cell[0],