mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 10:08:49 +01:00
Finalize NotebookEditor api proposal (#149767)
* Finalize NotebookEditor api proposal Fixes #149271 This finalizes most parts of the NotebookEditor api proposal. I haven't removed the proposal entirely as there are still a few parts being left behind: - The deprecated properties/functions - A few contribution points such as `notebook/cell/executePrimary` * remove extra quote
This commit is contained in:
@@ -759,31 +759,28 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
return extHostWebviewViews.registerWebviewViewProvider(extension, viewId, provider, options?.webviewOptions);
|
||||
},
|
||||
get activeNotebookEditor(): vscode.NotebookEditor | undefined {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
return extHostNotebook.activeNotebookEditor;
|
||||
},
|
||||
onDidChangeActiveNotebookEditor(listener, thisArgs?, disposables?) {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
return extHostNotebook.onDidChangeActiveNotebookEditor(listener, thisArgs, disposables);
|
||||
},
|
||||
get visibleNotebookEditors() {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
return extHostNotebook.visibleNotebookEditors;
|
||||
},
|
||||
get onDidChangeVisibleNotebookEditors() {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
return extHostNotebook.onDidChangeVisibleNotebookEditors;
|
||||
},
|
||||
onDidChangeNotebookEditorSelection(listener, thisArgs?, disposables?) {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
return extHostNotebookEditors.onDidChangeNotebookEditorSelection(listener, thisArgs, disposables);
|
||||
},
|
||||
onDidChangeNotebookEditorVisibleRanges(listener, thisArgs?, disposables?) {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
return extHostNotebookEditors.onDidChangeNotebookEditorVisibleRanges(listener, thisArgs, disposables);
|
||||
},
|
||||
showNotebookDocument(uriOrDocument, options?) {
|
||||
checkProposedApiEnabled(extension, 'notebookEditor');
|
||||
if (URI.isUri(uriOrDocument)) {
|
||||
extHostApiDeprecation.report('window.showNotebookDocument(uri)', extension,
|
||||
`Please use 'window.openNotebookDocument' and 'window.showTextDocument'`);
|
||||
}
|
||||
return extHostNotebook.showNotebookDocument(uriOrDocument, options);
|
||||
},
|
||||
registerExternalUriOpener(id: string, opener: vscode.ExternalUriOpener, metadata: vscode.ExternalUriOpenerMetadata) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
|
||||
import { ExtHostNotebookRenderersShape, IMainContext, MainContext, MainThreadNotebookRenderersShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
|
||||
import { ExtHostNotebookEditor } from 'vs/workbench/api/common/extHostNotebookEditor';
|
||||
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
|
||||
@@ -30,29 +29,16 @@ export class ExtHostNotebookRenderers implements ExtHostNotebookRenderersShape {
|
||||
throw new Error(`Extensions may only call createRendererMessaging() for renderers they contribute (got ${rendererId})`);
|
||||
}
|
||||
|
||||
// In the stable API, the editor is given as an empty object, and this map
|
||||
// is used to maintain references. This can be removed after editor finalization.
|
||||
const notebookEditorVisible = isProposedApiEnabled(manifest, 'notebookEditor');
|
||||
const notebookEditorAliases = new WeakMap<{}, vscode.NotebookEditor>();
|
||||
|
||||
const messaging: vscode.NotebookRendererMessaging = {
|
||||
onDidReceiveMessage: (listener, thisArg, disposables) => {
|
||||
const wrappedListener = notebookEditorVisible ? listener : (evt: { editor: vscode.NotebookEditor; message: any }) => {
|
||||
const obj = {};
|
||||
notebookEditorAliases.set(obj, evt.editor);
|
||||
listener({ editor: obj as vscode.NotebookEditor, message: evt.message });
|
||||
};
|
||||
|
||||
return this.getOrCreateEmitterFor(rendererId).event(wrappedListener, thisArg, disposables);
|
||||
return this.getOrCreateEmitterFor(rendererId).event(listener, thisArg, disposables);
|
||||
},
|
||||
postMessage: (message, editorOrAlias) => {
|
||||
if (ExtHostNotebookEditor.apiEditorsToExtHost.has(message)) { // back compat for swapped args
|
||||
[message, editorOrAlias] = [editorOrAlias, message];
|
||||
}
|
||||
|
||||
|
||||
const editor = notebookEditorVisible ? editorOrAlias : notebookEditorAliases.get(editorOrAlias!);
|
||||
const extHostEditor = editor && ExtHostNotebookEditor.apiEditorsToExtHost.get(editor);
|
||||
const extHostEditor = editorOrAlias && ExtHostNotebookEditor.apiEditorsToExtHost.get(editorOrAlias);
|
||||
return this.proxy.$postMessage(extHostEditor?.id, rendererId, message);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user