Skip to content

Commit

Permalink
Remove old notebook editor api proposal
Browse files Browse the repository at this point in the history
All consumers should now be on the finalized api

Fixes microsoft#151661
  • Loading branch information
mjbvz committed Oct 24, 2022
1 parent ce340cb commit c414ead
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,23 @@ import * as utils from '../utils';
test('Opening a notebook should fire activeNotebook event changed only once', async function () {
const openedEditor = onDidOpenNotebookEditor();
const resource = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const editor = await vscode.window.showNotebookDocument(resource);
const document = await vscode.workspace.openNotebookDocument(resource);
const editor = await vscode.window.showNotebookDocument(document);
assert.ok(await openedEditor);
assert.strictEqual(editor.notebook.uri.toString(), resource.toString());
});

test('Active/Visible Editor', async function () {
const firstEditorOpen = onDidOpenNotebookEditor();
const resource = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const firstEditor = await vscode.window.showNotebookDocument(resource);
const document = await vscode.workspace.openNotebookDocument(resource);

const firstEditor = await vscode.window.showNotebookDocument(document);
await firstEditorOpen;
assert.strictEqual(vscode.window.activeNotebookEditor, firstEditor);
assert.strictEqual(vscode.window.visibleNotebookEditors.includes(firstEditor), true);

const secondEditor = await vscode.window.showNotebookDocument(resource, { viewColumn: vscode.ViewColumn.Beside });
const secondEditor = await vscode.window.showNotebookDocument(document, { viewColumn: vscode.ViewColumn.Beside });
// There is no guarantee that when `showNotebookDocument` resolves, the active notebook editor is already updated correctly.
// assert.strictEqual(secondEditor === vscode.window.activeNotebookEditor, true);
assert.notStrictEqual(firstEditor, secondEditor);
Expand All @@ -95,7 +98,8 @@ import * as utils from '../utils';
test('Notebook Editor Event - onDidChangeVisibleNotebookEditors on open/close', async function () {
const openedEditor = utils.asPromise(vscode.window.onDidChangeVisibleNotebookEditors);
const resource = await utils.createRandomFile(undefined, undefined, '.nbdtest');
await vscode.window.showNotebookDocument(resource);
const document = await vscode.workspace.openNotebookDocument(resource);
await vscode.window.showNotebookDocument(document);
assert.ok(await openedEditor);

const firstEditorClose = utils.asPromise(vscode.window.onDidChangeVisibleNotebookEditors);
Expand All @@ -105,15 +109,17 @@ import * as utils from '../utils';

test('Notebook Editor Event - onDidChangeVisibleNotebookEditors on two editor groups', async function () {
const resource = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const document = await vscode.workspace.openNotebookDocument(resource);

let count = 0;
testDisposables.push(vscode.window.onDidChangeVisibleNotebookEditors(() => {
count = vscode.window.visibleNotebookEditors.length;
}));

await vscode.window.showNotebookDocument(resource, { viewColumn: vscode.ViewColumn.Active });
await vscode.window.showNotebookDocument(document, { viewColumn: vscode.ViewColumn.Active });
assert.strictEqual(count, 1);

await vscode.window.showNotebookDocument(resource, { viewColumn: vscode.ViewColumn.Beside });
await vscode.window.showNotebookDocument(document, { viewColumn: vscode.ViewColumn.Beside });
assert.strictEqual(count, 2);

await utils.closeAllEditors();
Expand Down
8 changes: 2 additions & 6 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
onDidChangeNotebookEditorVisibleRanges(listener, thisArgs?, disposables?) {
return extHostNotebookEditors.onDidChangeNotebookEditorVisibleRanges(listener, thisArgs, disposables);
},
showNotebookDocument(uriOrDocument, options?) {
if (URI.isUri(uriOrDocument)) {
extHostApiDeprecation.report('window.showNotebookDocument(uri)', extension,
`Please use 'workspace.openNotebookDocument' and 'window.showNotebookDocument'`);
}
return extHostNotebook.showNotebookDocument(uriOrDocument, options);
showNotebookDocument(document, options?) {
return extHostNotebook.showNotebookDocument(document, options);
},
registerExternalUriOpener(id: string, opener: vscode.ExternalUriOpener, metadata: vscode.ExternalUriOpenerMetadata) {
checkProposedApiEnabled(extension, 'externalUriOpener');
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/api/common/extHostNotebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export class ExtHostNotebookEditor {
if (!this._editor) {
const that = this;
this._editor = {
get document() {
return that.notebookData.apiNotebook;
},
get notebook() {
return that.notebookData.apiNotebook;
},
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostNotebookKernels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
} else if (v && 'notebookEditor' in v) {
const notebookEditorId = this._extHostNotebook.getIdByEditor(v.notebookEditor);
if (notebookEditorId === undefined) {
throw new Error(`Cannot invoke 'notebook.selectKernel' for unrecognized notebook editor ${v.notebookEditor.document.uri.toString()}`);
throw new Error(`Cannot invoke 'notebook.selectKernel' for unrecognized notebook editor ${v.notebookEditor.notebook.uri.toString()}`);
}
return { notebookEditorId };
}
Expand Down
27 changes: 1 addition & 26 deletions src/vscode-dts/vscode.proposed.notebookEditor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,5 @@ declare module 'vscode' {
// https://github.com/microsoft/vscode/issues/149271

// ❗️ Important: The main NotebookEditor api has been finalized.
// This file only contains deprecated properties/functions from the proposal.

export interface NotebookEditor {
/**
* The document associated with this notebook editor.
*
* @deprecated Use {@linkcode NotebookEditor.notebook} instead.
*/
readonly document: NotebookDocument;
}

export namespace window {
/**
* A short-hand for `openNotebookDocument(uri).then(document => showNotebookDocument(document, options))`.
*
* @deprecated Will not be finalized.
*
* @see {@link workspace.openNotebookDocument}
*
* @param uri The resource to open.
* @param options {@link NotebookDocumentShowOptions Editor options} to configure the behavior of showing the {@link NotebookEditor notebook editor}.
*
* @return A promise that resolves to an {@link NotebookEditor notebook editor}.
*/
export function showNotebookDocument(uri: Uri, options?: NotebookDocumentShowOptions): Thenable<NotebookEditor>;
}
// This file only tracks the `notebook/cell/executePrimary` contribution, which will be removed
}

0 comments on commit c414ead

Please sign in to comment.