Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update notebook API #10632

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TELEMETRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5864,8 +5864,8 @@ No properties for event

[src/kernels/ipywidgets/baseIPyWidgetScriptManager.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/ipywidgets/baseIPyWidgetScriptManager.ts)
```typescript
delete config['@jupyter-widgets/controls'];
delete config['@jupyter-widgets/output'];
)}`
);
}
sendTelemetryEvent(Telemetry.DiscoverIPyWidgetNamesPerf, stopWatch.elapsedTime, {
type: isLocalConnection(this.kernel.kernelConnectionMetadata) ? 'local' : 'remote'
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,6 @@
"notebookWorkspaceEdit",
"notebookDebugOptions",
"notebookDeprecated",
"notebookEditor",
"notebookMessaging",
"notebookMime",
"notebookCellExecutionState",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class InteractiveWindowDebuggingManager
}

const checkIpykernelAndStart = async (allowSelectKernel = true): Promise<void> => {
const ipykernelResult = await this.checkForIpykernel6(editor.document);
const ipykernelResult = await this.checkForIpykernel6(editor.notebook);
switch (ipykernelResult) {
case IpykernelCheckResult.NotInstalled:
// User would have been notified about this, nothing more to do.
Expand Down
7 changes: 3 additions & 4 deletions src/interactive-window/interactiveWindowCommandListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,9 @@ export class InteractiveWindowCommandListener implements IDataScienceCommandList
getDisplayPath(file)
);
// Next open this notebook & execute it.
const editor = await this.notebook.showNotebookDocument(uri, {
preserveFocus: false,
viewColumn: ViewColumn.Beside
});
const editor = await this.notebook
.openNotebookDocument(uri)
.then((document) => this.notebook.showNotebookDocument(document));
const { controller } = await this.controllerPreferredService.computePreferred(editor.notebook);
if (controller) {
await this.commandManager.executeCommand('notebook.selectKernel', {
Expand Down
25 changes: 14 additions & 11 deletions src/notebooks/outputs/errorRendererComms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,21 @@ export class ErrorRendererCommunicationHandler implements IExtensionSyncActivati
// If there is one, go to the cell that matches
if (cell) {
const cellRange = new NotebookRange(cell.index, cell.index);
return this.notebooks.showNotebookDocument(cell.notebook.uri, { selections: [cellRange] }).then((_e) => {
return this.commandManager.executeCommand('notebook.cell.edit').then(() => {
const cellEditor = this.documentManager.visibleTextEditors.find(
(v) => v.document.uri.toString() === cellUri
);
if (cellEditor) {
// Force the selection to change
cellEditor.revealRange(selection);
cellEditor.selection = new Selection(selection.start, selection.start);
}
return this.notebooks
.openNotebookDocument(cell.notebook.uri)
.then((document) => this.notebooks.showNotebookDocument(document, { selections: [cellRange] }))
.then((_e) => {
return this.commandManager.executeCommand('notebook.cell.edit').then(() => {
const cellEditor = this.documentManager.visibleTextEditors.find(
(v) => v.document.uri.toString() === cellUri
);
if (cellEditor) {
// Force the selection to change
cellEditor.revealRange(selection);
cellEditor.selection = new Selection(selection.start, selection.start);
}
});
});
});
}
}
}
12 changes: 1 addition & 11 deletions src/platform/common/application/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from 'vscode';
import { IDisposableRegistry } from '../types';
import { testOnlyMethod } from '../utils/decorators';
import { isUri } from '../utils/misc';
import { IApplicationEnvironment, IVSCodeNotebook } from './types';

@injectable()
Expand Down Expand Up @@ -72,20 +71,11 @@ export class VSCodeNotebook implements IVSCodeNotebook {
}
}

public async showNotebookDocument(uri: Uri, options?: NotebookDocumentShowOptions): Promise<NotebookEditor>;
public async showNotebookDocument(
document: NotebookDocument,
options?: NotebookDocumentShowOptions
): Promise<NotebookEditor>;
public async showNotebookDocument(
uriOrDocument: Uri | NotebookDocument,
options?: NotebookDocumentShowOptions
): Promise<NotebookEditor> {
if (isUri(uriOrDocument)) {
return window.showNotebookDocument(uriOrDocument, options);
} else {
return window.showNotebookDocument(uriOrDocument, options);
}
return window.showNotebookDocument(document, options);
}

public registerNotebookSerializer(
Expand Down
1 change: 0 additions & 1 deletion src/platform/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,6 @@ export interface IVSCodeNotebook {
): NotebookController;
openNotebookDocument(uri: Uri): Thenable<NotebookDocument>;
openNotebookDocument(viewType: string, content?: NotebookData): Promise<NotebookDocument>;
showNotebookDocument(uri: Uri, options?: NotebookDocumentShowOptions): Thenable<NotebookEditor>;
showNotebookDocument(document: NotebookDocument, options?: NotebookDocumentShowOptions): Thenable<NotebookEditor>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/datascience/interactiveWindow.vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ suite(`Interactive window Execution`, async function () {
);

const vscodeNotebook = api.serviceContainer.get<IVSCodeNotebook>(IVSCodeNotebook);
await vscodeNotebook.openNotebookDocument(notebookFile);
let editor = await vscodeNotebook.showNotebookDocument(notebookFile, { preserveFocus: false });
const document = await vscodeNotebook.openNotebookDocument(notebookFile);
let editor = await vscodeNotebook.showNotebookDocument(document, { preserveFocus: false });

const cells = editor.notebook.getCells();
assert.strictEqual(cells?.length, 3);
Expand Down