mainThreadNotebook.ts 19.8 KB
Newer Older
R
rebornix 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
7
import { MainContext, MainThreadNotebookShape, NotebookExtensionDescription, IExtHostContext, ExtHostNotebookShape, ExtHostContext, INotebookDocumentsAndEditorsDelta, INotebookModelAddedData } from '../common/extHost.protocol';
R
rebornix 已提交
8
import { Disposable, IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
R
rebornix 已提交
9
import { URI, UriComponents } from 'vs/base/common/uri';
10
import { INotebookService, IMainNotebookController } from 'vs/workbench/contrib/notebook/common/notebookService';
R
rebornix 已提交
11
import { INotebookTextModel, INotebookMimeTypeSelector, NOTEBOOK_DISPLAY_ORDER, NotebookCellOutputsSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, INotebookKernelInfo, INotebookKernelInfoDto, INotebookTextModelBackup, IEditor } from 'vs/workbench/contrib/notebook/common/notebookCommon';
R
rebornix 已提交
12
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
13
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
14 15
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
16
import { CancellationToken } from 'vs/base/common/cancellation';
R
rebornix 已提交
17
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
R
rebornix 已提交
18 19
import { IRelativePattern } from 'vs/base/common/glob';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
R
rebornix 已提交
20

21 22
export class MainThreadNotebookDocument extends Disposable {
	private _textModel: NotebookTextModel;
R
rebornix 已提交
23

24 25
	get textModel() {
		return this._textModel;
R
rebornix 已提交
26
	}
R
rebornix 已提交
27 28

	constructor(
R
rebornix 已提交
29
		private readonly _proxy: ExtHostNotebookShape,
R
rebornix 已提交
30
		public handle: number,
R
rebornix 已提交
31
		public viewType: string,
32
		public uri: URI
R
rebornix 已提交
33
	) {
R
rebornix 已提交
34
		super();
35
		this._textModel = new NotebookTextModel(handle, viewType, uri);
R
rebornix 已提交
36 37 38
		this._register(this._textModel.onDidModelChange(e => {
			this._proxy.$acceptModelChanged(this.uri, e);
		}));
R
rebornix 已提交
39 40
		this._register(this._textModel.onDidSelectionChange(e => {
			const selectionsChange = e ? { selections: e } : null;
R
rebornix 已提交
41
			this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange, metadata: null });
R
rebornix 已提交
42
		}));
R
rebornix 已提交
43
	}
R
rebornix 已提交
44

R
rebornix 已提交
45 46 47
	applyEdit(modelVersionId: number, edits: ICellEditOperation[]): boolean {
		return this._textModel.applyEdit(modelVersionId, edits);
	}
R
rebornix 已提交
48

R
rebornix 已提交
49 50
	updateRenderers(renderers: number[]) {
		this._textModel.updateRenderers(renderers);
R
rebornix 已提交
51 52
	}

R
rebornix 已提交
53
	dispose() {
54
		this._textModel.dispose();
R
rebornix 已提交
55 56
		super.dispose();
	}
R
rebornix 已提交
57 58
}

R
rebornix 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
class DocumentAndEditorState {
	static ofMaps<K, V>(before: Map<K, V>, after: Map<K, V>): { removed: V[], added: V[] } {
		const removed: V[] = [];
		const added: V[] = [];
		before.forEach((value, index) => {
			if (!after.has(index)) {
				removed.push(value);
			}
		});
		after.forEach((value, index) => {
			if (!before.has(index)) {
				added.push(value);
			}
		});
		return { removed, added };
	}

	static compute(before: DocumentAndEditorState | undefined, after: DocumentAndEditorState): INotebookDocumentsAndEditorsDelta {
		if (!before) {
			const apiEditors = [];
			for (let id in after.textEditors) {
				const editor = after.textEditors.get(id)!;
				apiEditors.push({ id, documentUri: editor.uri!, selections: editor!.textModel!.selections });
			}

			return {
				addedDocuments: [],
				addedEditors: apiEditors
			};
		}
		// const documentDelta = delta.ofSets(before.documents, after.documents);
		const editorDelta = DocumentAndEditorState.ofMaps(before.textEditors, after.textEditors);
		const addedAPIEditors = editorDelta.added.map(add => ({
			id: add.getId(),
			documentUri: add.uri!,
			selections: add.textModel!.selections
		}));

		const removedAPIEditors = editorDelta.removed.map(removed => removed.getId());

		// const oldActiveEditor = before.activeEditor !== after.activeEditor ? before.activeEditor : undefined;
		const newActiveEditor = before.activeEditor !== after.activeEditor ? after.activeEditor : undefined;

		// return new DocumentAndEditorStateDelta(
		// 	documentDelta.removed, documentDelta.added,
		// 	editorDelta.removed, editorDelta.added,
		// 	oldActiveEditor, newActiveEditor
		// );
		return {
			addedEditors: addedAPIEditors,
			removedEditors: removedAPIEditors,
			newActiveEditor: newActiveEditor
		};
	}

	constructor(
		readonly documents: Set<URI>,
		readonly textEditors: Map<string, IEditor>,
		readonly activeEditor: string | null | undefined,
	) {
		//
	}
}

R
rebornix 已提交
123 124 125
@extHostNamedCustomer(MainContext.MainThreadNotebook)
export class MainThreadNotebooks extends Disposable implements MainThreadNotebookShape {
	private readonly _notebookProviders = new Map<string, MainThreadNotebookController>();
R
rebornix 已提交
126
	private readonly _notebookKernels = new Map<string, MainThreadNotebookKernel>();
R
rebornix 已提交
127
	private readonly _proxy: ExtHostNotebookShape;
R
rebornix 已提交
128 129
	private _toDisposeOnEditorRemove = new Map<string, IDisposable>();
	private _currentState?: DocumentAndEditorState;
R
rebornix 已提交
130 131 132

	constructor(
		extHostContext: IExtHostContext,
R
rebornix 已提交
133
		@INotebookService private _notebookService: INotebookService,
134 135
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IEditorService private readonly editorService: IEditorService,
R
rebornix 已提交
136
		@IAccessibilityService private readonly accessibilityService: IAccessibilityService
137

R
rebornix 已提交
138 139 140
	) {
		super();
		this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostNotebook);
R
rebornix 已提交
141 142 143
		this.registerListeners();
	}

R
rebornix 已提交
144 145 146 147 148 149 150 151
	async $tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[], renderers: number[]): Promise<boolean> {
		let controller = this._notebookProviders.get(viewType);

		if (controller) {
			return controller.tryApplyEdits(resource, modelVersionId, edits, renderers);
		}

		return false;
R
rebornix 已提交
152 153
	}

R
rebornix 已提交
154
	registerListeners() {
R
rebornix 已提交
155 156 157 158
		this._notebookService.listNotebookEditors().forEach((e) => {
			this._addNotebookEditor(e);
		});

R
rebornix 已提交
159
		this._register(this._notebookService.onDidChangeActiveEditor(e => {
R
rebornix 已提交
160
			this._proxy.$acceptDocumentAndEditorsDelta({
R
rebornix 已提交
161
				newActiveEditor: e
R
rebornix 已提交
162
			});
R
rebornix 已提交
163
		}));
R
rebornix 已提交
164

R
rebornix 已提交
165 166 167 168 169 170 171 172
		this._register(this._notebookService.onNotebookEditorAdd(editor => {
			this._addNotebookEditor(editor);
		}));

		this._register(this._notebookService.onNotebookEditorRemove(editor => {
			this._removeNotebookEditor(editor);
		}));

R
rebornix 已提交
173 174 175 176 177 178 179
		const updateOrder = () => {
			let userOrder = this.configurationService.getValue<string[]>('notebook.displayOrder');
			this._proxy.$acceptDisplayOrder({
				defaultOrder: this.accessibilityService.isScreenReaderOptimized() ? ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER : NOTEBOOK_DISPLAY_ORDER,
				userOrder: userOrder
			});
		};
R
rebornix 已提交
180

R
rebornix 已提交
181
		updateOrder();
R
rebornix 已提交
182

R
rebornix 已提交
183 184 185
		this._register(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectedKeys.indexOf('notebook.displayOrder') >= 0) {
				updateOrder();
R
rebornix 已提交
186
			}
R
rebornix 已提交
187 188 189 190 191
		}));

		this._register(this.accessibilityService.onDidChangeScreenReaderOptimized(() => {
			updateOrder();
		}));
R
rebornix 已提交
192 193 194 195

		const activeEditorPane = this.editorService.activeEditorPane as any | undefined;
		const notebookEditor = activeEditorPane?.isNotebookEditor ? activeEditorPane.getControl() : undefined;
		this._updateState(notebookEditor);
R
rebornix 已提交
196 197
	}

198 199 200 201 202 203
	async addNotebookDocument(data: INotebookModelAddedData) {
		this._proxy.$acceptDocumentAndEditorsDelta({
			addedDocuments: [data]
		});
	}

R
rebornix 已提交
204 205 206
	private _addNotebookEditor(e: IEditor) {
		this._toDisposeOnEditorRemove.set(e.getId(), combinedDisposable(
			e.onDidChangeModel(() => this._updateState()),
R
rebornix 已提交
207 208 209
			e.onDidFocusEditorWidget(() => {
				this._updateState(e);
			}),
R
rebornix 已提交
210 211
		));

R
rebornix 已提交
212 213 214
		const activeEditorPane = this.editorService.activeEditorPane as any | undefined;
		const notebookEditor = activeEditorPane?.isNotebookEditor ? activeEditorPane.getControl() : undefined;
		this._updateState(notebookEditor);
R
rebornix 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
	}

	private _removeNotebookEditor(e: IEditor) {
		const sub = this._toDisposeOnEditorRemove.get(e.getId());
		if (sub) {
			this._toDisposeOnEditorRemove.delete(e.getId());
			sub.dispose();
			this._updateState();
		}
	}

	private async _updateState(focusedNotebookEditor?: IEditor) {
		const documents = new Set<URI>();
		this._notebookService.listNotebookDocuments().forEach(document => {
			documents.add(document.uri);
		});

		const editors = new Map<string, IEditor>();
		let activeEditor: string | null = null;

		for (const editor of this._notebookService.listNotebookEditors()) {
			if (editor.hasModel()) {
				editors.set(editor.getId(), editor);
				if (editor.hasFocus()) {
					activeEditor = editor.getId();
				}
			}
		}

R
rebornix 已提交
244 245 246 247
		if (!activeEditor && focusedNotebookEditor) {
			activeEditor = focusedNotebookEditor.getId();
		}

R
rebornix 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
		// editors always have view model attached, which means there is already a document in exthost.
		const newState = new DocumentAndEditorState(documents, editors, activeEditor);
		const delta = DocumentAndEditorState.compute(this._currentState, newState);
		// const isEmptyChange = (!delta.addedDocuments || delta.addedDocuments.length === 0)
		// 	&& (!delta.removedDocuments || delta.removedDocuments.length === 0)
		// 	&& (!delta.addedEditors || delta.addedEditors.length === 0)
		// 	&& (!delta.removedEditors || delta.removedEditors.length === 0)
		// 	&& (delta.newActiveEditor === undefined)

		// if (!isEmptyChange) {
		this._currentState = newState;
		await this._proxy.$acceptDocumentAndEditorsDelta(delta);
		// }
	}

R
rebornix 已提交
263 264
	async $registerNotebookRenderer(extension: NotebookExtensionDescription, type: string, selectors: INotebookMimeTypeSelector, handle: number, preloads: UriComponents[]): Promise<void> {
		this._notebookService.registerNotebookRenderer(handle, extension, type, selectors, preloads.map(uri => URI.revive(uri)));
R
rebornix 已提交
265 266
	}

267 268
	async $unregisterNotebookRenderer(handle: number): Promise<void> {
		this._notebookService.unregisterNotebookRenderer(handle);
R
rebornix 已提交
269 270
	}

R
rebornix 已提交
271 272
	async $registerNotebookProvider(extension: NotebookExtensionDescription, viewType: string, kernel: INotebookKernelInfoDto | undefined): Promise<void> {
		let controller = new MainThreadNotebookController(this._proxy, this, viewType, kernel);
R
rebornix 已提交
273
		this._notebookProviders.set(viewType, controller);
R
rebornix 已提交
274
		this._notebookService.registerNotebookController(viewType, extension, controller);
R
rebornix 已提交
275
		return;
R
rebornix 已提交
276 277
	}

R
rebornix 已提交
278
	async $unregisterNotebookProvider(viewType: string): Promise<void> {
R
rebornix 已提交
279 280
		this._notebookProviders.delete(viewType);
		this._notebookService.unregisterNotebookProvider(viewType);
R
rebornix 已提交
281 282 283
		return;
	}

R
rebornix 已提交
284 285
	async $registerNotebookKernel(extension: NotebookExtensionDescription, id: string, label: string, selectors: (string | IRelativePattern)[], preloads: UriComponents[]): Promise<void> {
		const kernel = new MainThreadNotebookKernel(this._proxy, id, label, selectors, extension.id, URI.revive(extension.location), preloads.map(preload => URI.revive(preload)));
R
rebornix 已提交
286 287 288 289 290 291 292 293 294 295 296
		this._notebookKernels.set(id, kernel);
		this._notebookService.registerNotebookKernel(kernel);
		return;
	}

	async $unregisterNotebookKernel(id: string): Promise<void> {
		this._notebookKernels.delete(id);
		this._notebookService.unregisterNotebookKernel(id);
		return;
	}

R
rebornix 已提交
297
	async $updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise<void> {
R
rebornix 已提交
298 299 300
		let controller = this._notebookProviders.get(viewType);

		if (controller) {
R
rebornix 已提交
301
			controller.updateLanguages(resource, languages);
R
rebornix 已提交
302 303
		}
	}
R
rebornix 已提交
304

R
rebornix 已提交
305
	async $updateNotebookMetadata(viewType: string, resource: UriComponents, metadata: NotebookDocumentMetadata): Promise<void> {
R
rebornix 已提交
306 307 308 309 310 311 312
		let controller = this._notebookProviders.get(viewType);

		if (controller) {
			controller.updateNotebookMetadata(resource, metadata);
		}
	}

313 314 315 316 317 318 319 320
	async $updateNotebookCellMetadata(viewType: string, resource: UriComponents, handle: number, metadata: NotebookCellMetadata): Promise<void> {
		let controller = this._notebookProviders.get(viewType);

		if (controller) {
			controller.updateNotebookCellMetadata(resource, handle, metadata);
		}
	}

321
	async $spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[], renderers: number[]): Promise<void> {
322
		let controller = this._notebookProviders.get(viewType);
323
		controller?.spliceNotebookCellOutputs(resource, cellHandle, splices, renderers);
324 325
	}

R
rebornix 已提交
326 327
	async executeNotebook(viewType: string, uri: URI, useAttachedKernel: boolean, token: CancellationToken): Promise<void> {
		return this._proxy.$executeNotebook(viewType, uri, undefined, useAttachedKernel, token);
R
rebornix 已提交
328
	}
329 330 331 332 333

	async $postMessage(handle: number, value: any): Promise<boolean> {

		const activeEditorPane = this.editorService.activeEditorPane as any | undefined;
		if (activeEditorPane?.isNotebookEditor) {
R
rebornix 已提交
334
			const notebookEditor = (activeEditorPane.getControl() as INotebookEditor);
335 336 337 338 339 340 341 342 343

			if (notebookEditor.viewModel?.handle === handle) {
				notebookEditor.postMessage(value);
				return true;
			}
		}

		return false;
	}
R
rebornix 已提交
344 345 346
}

export class MainThreadNotebookController implements IMainNotebookController {
R
rebornix 已提交
347
	private _mapping: Map<string, MainThreadNotebookDocument> = new Map();
R
rebornix 已提交
348
	static documentHandle: number = 0;
R
rebornix 已提交
349 350

	constructor(
R
rebornix 已提交
351 352
		private readonly _proxy: ExtHostNotebookShape,
		private _mainThreadNotebook: MainThreadNotebooks,
R
rebornix 已提交
353
		private _viewType: string,
R
rebornix 已提交
354
		readonly kernel: INotebookKernelInfoDto | undefined
R
rebornix 已提交
355 356 357
	) {
	}

358
	async createNotebook(viewType: string, uri: URI, backup: INotebookTextModelBackup | undefined, forceReload: boolean, editorId?: string): Promise<NotebookTextModel | undefined> {
R
rebornix 已提交
359 360 361
		let mainthreadNotebook = this._mapping.get(URI.from(uri).toString());

		if (mainthreadNotebook) {
R
revert.  
rebornix 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374
			if (forceReload) {
				const data = await this._proxy.$resolveNotebookData(viewType, uri);
				if (!data) {
					return;
				}

				mainthreadNotebook.textModel.languages = data.languages;
				mainthreadNotebook.textModel.metadata = data.metadata;
				mainthreadNotebook.textModel.applyEdit(mainthreadNotebook.textModel.versionId, [
					{ editType: CellEditType.Delete, count: mainthreadNotebook.textModel.cells.length, index: 0 },
					{ editType: CellEditType.Insert, index: 0, cells: data.cells }
				]);
			}
R
rebornix 已提交
375 376 377
			return mainthreadNotebook.textModel;
		}

378
		let document = new MainThreadNotebookDocument(this._proxy, MainThreadNotebookController.documentHandle++, viewType, uri);
R
rebornix 已提交
379 380 381 382 383 384 385 386 387 388 389
		this._mapping.set(document.uri.toString(), document);

		if (backup) {
			// trigger events
			document.textModel.metadata = backup.metadata;
			document.textModel.languages = backup.languages;

			document.textModel.applyEdit(document.textModel.versionId, [
				{
					editType: CellEditType.Insert,
					index: 0,
390
					cells: backup.cells || []
R
rebornix 已提交
391 392 393
				}
			]);

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
			this._mainThreadNotebook.addNotebookDocument({
				viewType: document.viewType,
				handle: document.handle,
				uri: document.uri,
				metadata: document.textModel.metadata,
				versionId: document.textModel.versionId,
				cells: document.textModel.cells.map(cell => ({
					handle: cell.handle,
					uri: cell.uri,
					source: cell.textBuffer.getLinesContent(),
					language: cell.language,
					cellKind: cell.cellKind,
					outputs: cell.outputs,
					metadata: cell.metadata
				})),
				attachedEditor: editorId ? {
					id: editorId,
					selections: document.textModel.selections
				} : undefined
R
rebornix 已提交
413
			});
R
rebornix 已提交
414 415 416 417 418 419 420 421 422 423 424 425

			return document.textModel;
		}

		// open notebook document
		const data = await this._proxy.$resolveNotebookData(viewType, uri);
		if (!data) {
			return;
		}

		document.textModel.languages = data.languages;
		document.textModel.metadata = data.metadata;
426 427 428 429 430 431 432

		if (data.cells.length) {
			document.textModel.initialize(data!.cells);
		} else {
			const mainCell = document.textModel.createCellTextModel([''], document.textModel.languages.length ? document.textModel.languages[0] : '', CellKind.Code, [], undefined);
			document.textModel.insertTemplateCell(mainCell);
		}
R
rebornix 已提交
433

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
		await this._mainThreadNotebook.addNotebookDocument({
			viewType: document.viewType,
			handle: document.handle,
			uri: document.uri,
			metadata: document.textModel.metadata,
			versionId: document.textModel.versionId,
			cells: document.textModel.cells.map(cell => ({
				handle: cell.handle,
				uri: cell.uri,
				source: cell.textBuffer.getLinesContent(),
				language: cell.language,
				cellKind: cell.cellKind,
				outputs: cell.outputs,
				metadata: cell.metadata
			})),
			attachedEditor: editorId ? {
				id: editorId,
				selections: document.textModel.selections
			} : undefined
R
rebornix 已提交
453 454
		});

R
rebornix 已提交
455 456
		this._proxy.$acceptEditorPropertiesChanged(uri, { selections: null, metadata: document.textModel.metadata });

R
rebornix 已提交
457 458 459
		return document.textModel;
	}

R
rebornix 已提交
460
	async tryApplyEdits(resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[], renderers: number[]): Promise<boolean> {
461
		let mainthreadNotebook = this._mapping.get(URI.from(resource).toString());
R
rebornix 已提交
462 463 464 465 466 467 468

		if (mainthreadNotebook) {
			mainthreadNotebook.updateRenderers(renderers);
			return mainthreadNotebook.applyEdit(modelVersionId, edits);
		}

		return false;
469 470
	}

471
	spliceNotebookCellOutputs(resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[], renderers: number[]): void {
472
		let mainthreadNotebook = this._mapping.get(URI.from(resource).toString());
473 474
		mainthreadNotebook?.textModel.updateRenderers(renderers);
		mainthreadNotebook?.textModel.$spliceNotebookCellOutputs(cellHandle, splices);
475 476
	}

R
rebornix 已提交
477 478
	async executeNotebook(viewType: string, uri: URI, useAttachedKernel: boolean, token: CancellationToken): Promise<void> {
		return this._mainThreadNotebook.executeNotebook(viewType, uri, useAttachedKernel, token);
R
rebornix 已提交
479 480
	}

481 482
	onDidReceiveMessage(editorId: string, message: any): void {
		this._proxy.$onDidReceiveMessage(editorId, message);
483 484
	}

R
rebornix 已提交
485 486 487 488 489 490 491 492 493 494 495 496 497
	async removeNotebookDocument(notebook: INotebookTextModel): Promise<void> {
		let document = this._mapping.get(URI.from(notebook.uri).toString());

		if (!document) {
			return;
		}

		await this._proxy.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
		document.dispose();
		this._mapping.delete(URI.from(notebook.uri).toString());
	}

	// Methods for ExtHost
R
rebornix 已提交
498 499 500

	updateLanguages(resource: UriComponents, languages: string[]) {
		let document = this._mapping.get(URI.from(resource).toString());
501
		document?.textModel.updateLanguages(languages);
R
rebornix 已提交
502 503
	}

R
rebornix 已提交
504
	updateNotebookMetadata(resource: UriComponents, metadata: NotebookDocumentMetadata) {
R
rebornix 已提交
505 506 507 508
		let document = this._mapping.get(URI.from(resource).toString());
		document?.textModel.updateNotebookMetadata(metadata);
	}

509 510 511 512 513
	updateNotebookCellMetadata(resource: UriComponents, handle: number, metadata: NotebookCellMetadata) {
		let document = this._mapping.get(URI.from(resource).toString());
		document?.textModel.updateNotebookCellMetadata(handle, metadata);
	}

514 515
	updateNotebookRenderers(resource: UriComponents, renderers: number[]): void {
		let document = this._mapping.get(URI.from(resource).toString());
516
		document?.textModel.updateRenderers(renderers);
517 518
	}

R
rebornix 已提交
519 520
	async executeNotebookCell(uri: URI, handle: number, useAttachedKernel: boolean, token: CancellationToken): Promise<void> {
		return this._proxy.$executeNotebook(this._viewType, uri, handle, useAttachedKernel, token);
521 522
	}

R
rebornix 已提交
523 524
	async save(uri: URI, token: CancellationToken): Promise<boolean> {
		return this._proxy.$saveNotebook(this._viewType, uri, token);
525
	}
R
saveAs  
rebornix 已提交
526 527 528 529 530

	async saveAs(uri: URI, target: URI, token: CancellationToken): Promise<boolean> {
		return this._proxy.$saveNotebookAs(this._viewType, uri, target, token);

	}
R
rebornix 已提交
531
}
R
rebornix 已提交
532 533 534 535 536

export class MainThreadNotebookKernel implements INotebookKernelInfo {
	constructor(
		private readonly _proxy: ExtHostNotebookShape,
		readonly id: string,
R
rebornix 已提交
537
		readonly label: string,
R
rebornix 已提交
538 539 540 541 542 543 544 545 546 547 548
		readonly selectors: (string | IRelativePattern)[],
		readonly extension: ExtensionIdentifier,
		readonly extensionLocation: URI,
		readonly preloads: URI[]
	) {
	}

	async executeNotebook(viewType: string, uri: URI, handle: number | undefined, token: CancellationToken): Promise<void> {
		return this._proxy.$executeNotebook2(this.id, viewType, uri, handle, token);
	}
}