From 470afe2e8a1541a20d4769ac443b36ae5a2aed2c Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Thu, 20 Jan 2022 11:04:27 -0800 Subject: [PATCH] Enable VS Code extension event APIs for when editors become active or visible. (#18129) --- .../extHostNotebookDocumentsAndEditors.ts | 11 +++++++++-- .../workbench/api/common/extHost.api.impl.ts | 18 ++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/sql/workbench/api/common/extHostNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/common/extHostNotebookDocumentsAndEditors.ts index 67f9ae6613..58f786721c 100644 --- a/src/sql/workbench/api/common/extHostNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/common/extHostNotebookDocumentsAndEditors.ts @@ -22,6 +22,7 @@ import { import { ExtHostNotebookDocumentData } from 'sql/workbench/api/common/extHostNotebookDocumentData'; import { ExtHostNotebookEditor } from 'sql/workbench/api/common/extHostNotebookEditor'; import { VSCodeNotebookDocument } from 'sql/workbench/api/common/notebooks/vscodeNotebookDocument'; +import { VSCodeNotebookEditor } from 'sql/workbench/api/common/notebooks/vscodeNotebookEditor'; type Adapter = azdata.nb.NavigationProvider; @@ -49,8 +50,12 @@ export class ExtHostNotebookDocumentsAndEditors implements ExtHostNotebookDocume readonly onDidCloseNotebookDocument: Event = this._onDidCloseNotebook.event; readonly onDidChangeNotebookCell: Event = this._onDidChangeNotebookCell.event; - private _onDidOpenVSCodeNotebook = new Emitter(); - private _onDidCloseVSCodeNotebook = new Emitter(); + private readonly _onDidChangeVisibleVSCodeEditors = new Emitter(); + private readonly _onDidChangeActiveVSCodeEditor = new Emitter(); + private readonly _onDidOpenVSCodeNotebook = new Emitter(); + private readonly _onDidCloseVSCodeNotebook = new Emitter(); + readonly onDidChangeVisibleVSCodeEditors: Event = this._onDidChangeVisibleVSCodeEditors.event; + readonly onDidChangeActiveVSCodeEditor: Event = this._onDidChangeActiveVSCodeEditor.event; readonly onDidOpenVSCodeNotebookDocument: Event = this._onDidOpenVSCodeNotebook.event; readonly onDidCloseVSCodeNotebookDocument: Event = this._onDidCloseVSCodeNotebook.event; @@ -61,6 +66,8 @@ export class ExtHostNotebookDocumentsAndEditors implements ExtHostNotebookDocume this._proxy = this._mainContext.getProxy(SqlMainContext.MainThreadNotebookDocumentsAndEditors); } + this.onDidChangeVisibleNotebookEditors(editors => this._onDidChangeVisibleVSCodeEditors.fire(editors.map(editor => new VSCodeNotebookEditor(editor)))); + this.onDidChangeActiveNotebookEditor(editor => this._onDidChangeActiveVSCodeEditor.fire(new VSCodeNotebookEditor(editor))); this.onDidOpenNotebookDocument(notebook => this._onDidOpenVSCodeNotebook.fire(new VSCodeNotebookDocument(notebook))); this.onDidCloseNotebookDocument(notebook => this._onDidCloseVSCodeNotebook.fire(new VSCodeNotebookDocument(notebook))); } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 304dd4b84e..89ba1797ab 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -724,22 +724,16 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor, ex return new VSCodeNotebookEditor(extHostNotebookDocumentsAndEditors.getActiveEditor()); }, onDidChangeActiveNotebookEditor(listener, thisArgs?, disposables?) { - // {{SQL CARBON EDIT}} Disable VS Code notebooks - throw new Error(functionalityNotSupportedError); - // checkProposedApiEnabled(extension); - // return extHostNotebook.onDidChangeActiveNotebookEditor(listener, thisArgs, disposables); + // {{SQL CARBON EDIT}} Use our own notebooks + return extHostNotebookDocumentsAndEditors.onDidChangeActiveVSCodeEditor(listener, thisArgs, disposables); }, get visibleNotebookEditors() { - // {{SQL CARBON EDIT}} Disable VS Code notebooks - return undefined; - // checkProposedApiEnabled(extension); - // return extHostNotebook.visibleNotebookEditors; + // {{SQL CARBON EDIT}} Use our own notebooks + return extHostNotebookDocumentsAndEditors.getAllEditors().map(editor => new VSCodeNotebookEditor(editor)); }, get onDidChangeVisibleNotebookEditors() { - // {{SQL CARBON EDIT}} Disable VS Code notebooks - return undefined; - // checkProposedApiEnabled(extension); - // return extHostNotebook.onDidChangeVisibleNotebookEditors; + // {{SQL CARBON EDIT}} Use our own notebooks + return extHostNotebookDocumentsAndEditors.onDidChangeVisibleVSCodeEditors; }, onDidChangeNotebookEditorSelection(listener, thisArgs?, disposables?) { // {{SQL CARBON EDIT}} Disable VS Code notebooks