Remove old notebook editor api proposal (#164504)

All consumers should now be on the finalized api

Fixes #151661
This commit is contained in:
Matt Bierner
2022-10-24 14:40:53 -07:00
committed by GitHub
parent 52f46cc600
commit 4eef476a4f
5 changed files with 16 additions and 42 deletions

View File

@@ -69,7 +69,8 @@ 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());
});
@@ -77,12 +78,14 @@ import * as utils from '../utils';
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);
@@ -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);
@@ -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();

View File

@@ -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');

View File

@@ -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;
},

View File

@@ -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 };
}

View File

@@ -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
}