Skip to content

Commit

Permalink
cleanup notebook argument processor, remove INotebookTextModel#handle…
Browse files Browse the repository at this point in the history
… and use uri instead, #105735
  • Loading branch information
jrieken committed Sep 7, 2020
1 parent 53ffaba commit ed9c404
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 28 deletions.
13 changes: 5 additions & 8 deletions src/vs/workbench/api/common/extHostNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// };
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { controller: IMainNotebookController, extensionData: NotebookExtensionDescription }>();
notebookProviderInfoStore: NotebookProviderInfoStore;
notebookRenderersInfoStore: NotebookOutputRendererInfoStore = new NotebookOutputRendererInfoStore();
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ export interface IMetadata {
}

export interface INotebookTextModel {
handle: number;
viewType: string;
metadata: NotebookDocumentMetadata
readonly uri: URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit ed9c404

Please sign in to comment.