diff --git a/package.json b/package.json index 9a35db0cfe2..ff6850eb96a 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "win": "F", "linux": "F", "key": "F", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.find" }, { @@ -110,7 +110,7 @@ "win": "K", "linux": "K", "key": "K", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "list.focusUp" }, { @@ -118,7 +118,7 @@ "win": "J", "linux": "J", "key": "J", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "list.focusDown" }, { @@ -126,7 +126,7 @@ "win": "A", "linux": "A", "key": "A", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.insertCodeCellAbove" }, { @@ -134,7 +134,7 @@ "win": "B", "linux": "B", "key": "B", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.insertCodeCellBelow" }, { @@ -142,7 +142,7 @@ "win": "D D", "linux": "D D", "key": "D D", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.delete" }, { @@ -150,7 +150,7 @@ "win": "Z", "linux": "Z", "key": "Z", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "jupyter.notebookeditor.keybind.undo" }, { @@ -158,7 +158,7 @@ "win": "S", "linux": "S", "key": "S", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "jupyter.notebookeditor.keybind.save" }, { @@ -166,7 +166,7 @@ "win": "C", "linux": "C", "key": "C", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.copy" }, { @@ -174,7 +174,7 @@ "win": "X", "linux": "X", "key": "X", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.cut" }, { @@ -182,7 +182,7 @@ "win": "V", "linux": "V", "key": "V", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.paste" }, { @@ -190,19 +190,19 @@ "win": "O", "linux": "O", "key": "O", - "when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "jupyter.notebookeditor.keybind.toggleOutput" }, { "mac": "ctrl+shift+-", "win": "ctrl+shift+-", "linux": "ctrl+shift+-", - "when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.split" }, { "key": "ctrl+enter", - "when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", + "when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts", "command": "notebook.cell.execute" }, { @@ -297,21 +297,21 @@ "light": "resources/light/export_to_python.svg", "dark": "resources/dark/export_to_python.svg" }, - "enablement": "notebookViewType == jupyter-notebook && isWorkspaceTrusted" + "enablement": "notebookType == jupyter-notebook && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.runallcellsabove", "title": "%DataScience.runAbove%", "category": "Notebook", "icon": "$(run-above)", - "enablement": "notebookViewType == jupyter-notebook && isWorkspaceTrusted" + "enablement": "notebookType == jupyter-notebook && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.runcellandallbelow", "title": "%DataScience.runBelow%", "category": "Notebook", "icon": "$(run-below)", - "enablement": "notebookViewType == jupyter-notebook && isWorkspaceTrusted" + "enablement": "notebookType == jupyter-notebook && isWorkspaceTrusted" }, { "command": "jupyter.export", @@ -616,13 +616,13 @@ "command": "jupyter.notebookeditor.keybind.undo", "title": "%jupyter.command.jupyter.notebookeditor.keybind.undo.title%", "category": "Notebook", - "enablement": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts" + "enablement": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts" }, { "command": "jupyter.notebookeditor.keybind.save", "title": "%jupyter.command.jupyter.notebookeditor.keybind.save.title%", "category": "Notebook", - "enablement": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts" + "enablement": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts" }, { "command": "jupyter.removeallcells", @@ -650,7 +650,7 @@ "light": "resources/light/interrupt.svg", "dark": "resources/dark/interrupt.svg" }, - "enablement": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted && jupyter.notebookeditor.canInterruptNotebookKernel" + "enablement": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted && jupyter.notebookeditor.canInterruptNotebookKernel" }, { "command": "jupyter.notebookeditor.restartkernel", @@ -764,7 +764,7 @@ "shortTitle": "%jupyter.command.jupyter.openVariableView.shorttitle%", "icon": "$(variable-group)", "category": "Jupyter", - "enablement": "notebookViewType == jupyter-notebook && !jupyter.variableViewVisible && isWorkspaceTrusted" + "enablement": "notebookType == jupyter-notebook && !jupyter.variableViewVisible && isWorkspaceTrusted" }, { "command": "jupyter.refreshDataViewer", @@ -831,31 +831,31 @@ "command": "jupyter.notebookeditor.restartkernel", "title": "%jupyter.command.jupyter.restartkernel.title%", "group": "navigation@1", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted && jupyter.notebookeditor.canrestartNotebookkernel" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted && jupyter.notebookeditor.canrestartNotebookkernel" }, { "command": "jupyter.notebookeditor.interruptkernel", "title": "%jupyter.command.jupyter.interruptkernel.title%", "group": "overflow@1", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted && jupyter.notebookeditor.canInterruptNotebookKernel" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted && jupyter.notebookeditor.canInterruptNotebookKernel" }, { "command": "jupyter.openVariableView", "title": "%jupyter.command.jupyter.openVariableView.title%", "group": "navigation@2", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.export", "title": "%DataScience.notebookExportAs%", "group": "navigation@3", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.selectNativeJupyterUriFromToolBar", "title": "%jupyter.command.jupyter.selectjupyteruri.title%", "group": "overflow@1000", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" } ], "notebook/cell/title": [ @@ -863,35 +863,35 @@ "command": "jupyter.notebookeditor.runallcellsabove", "title": "%DataScience.runAbove%", "group": "inline/cell@0", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.runcellandallbelow", "title": "%DataScience.runBelow%", "group": "inline/cell@0", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" } ], "notebook/toolbar": [ { "command": "jupyter.notebookeditor.restartkernel", "group": "navigation/execute@1", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.interruptkernel", "group": "navigation/execute@2", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.openVariableView", "group": "navigation@1", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.export", "group": "navigation@2", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" } ], "explorer/context": [ @@ -920,17 +920,17 @@ { "command": "jupyter.notebookeditor.keybind.toggleOutput", "title": "%DataScience.toggleCellOutput%", - "when": "notebookViewType == jupyter-notebook" + "when": "notebookType == jupyter-notebook" }, { "command": "jupyter.notebookeditor.runallcellsabove", "title": "%DataScience.runAbove%", - "when": "notebookEditorFocused && notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookEditorFocused && notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.runcellandallbelow", "title": "%DataScience.runBelow%", - "when": "notebookEditorFocused && notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookEditorFocused && notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.exportAsPythonScript", @@ -1187,7 +1187,7 @@ "command": "jupyter.notebookeditor.interruptkernel", "title": "%jupyter.command.jupyter.interruptkernel.title%", "category": "Notebook", - "when": "notebookViewType == 'jupyter-notebook' && isWorkspaceTrusted" + "when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted" }, { "command": "jupyter.notebookeditor.restartkernel", @@ -1205,13 +1205,13 @@ "command": "jupyter.notebookeditor.expandallcells", "title": "%jupyter.command.jupyter.expandallcells.title%", "category": "Notebook", - "when": "notebookEditorFocused && notebookViewType == 'jupyter-notebook'" + "when": "notebookEditorFocused && notebookType == 'jupyter-notebook'" }, { "command": "jupyter.notebookeditor.collapseallcells", "title": "%jupyter.command.jupyter.collapseallcells.title%", "category": "Notebook", - "when": "notebookEditorFocused && notebookViewType == 'jupyter-notebook'" + "when": "notebookEditorFocused && notebookType == 'jupyter-notebook'" }, { "command": "jupyter.notebookeditor.keybind.undo", @@ -1359,7 +1359,7 @@ "command": "jupyter.openVariableView", "title": "%jupyter.command.jupyter.openVariableView.title%", "category": "Jupyter", - "when": "notebookViewType == jupyter-notebook && isWorkspaceTrusted" + "when": "notebookType == jupyter-notebook && isWorkspaceTrusted" }, { "command": "jupyter.selectNativeJupyterUriFromToolBar", diff --git a/src/client/common/application/notebook.ts b/src/client/common/application/notebook.ts index 6cc67f536c6..9f7e5778531 100644 --- a/src/client/common/application/notebook.ts +++ b/src/client/common/application/notebook.ts @@ -15,7 +15,8 @@ import { NotebookEditorSelectionChangeEvent, NotebookExecuteHandler, NotebookRendererScript, - window + window, + workspace } from 'vscode'; import { UseVSCodeNotebookEditorApi } from '../constants'; import { IDisposableRegistry } from '../types'; @@ -31,7 +32,7 @@ export class VSCodeNotebook implements IVSCodeNotebook { public readonly onDidSaveNotebookDocument: Event; public readonly onDidChangeNotebookDocument: Event; public get notebookDocuments(): ReadonlyArray { - return this.canUseNotebookApi ? notebooks.notebookDocuments : []; + return this.canUseNotebookApi ? workspace.notebookDocuments : []; } public get notebookEditors() { return this.canUseNotebookApi ? window.visibleNotebookEditors : []; @@ -60,8 +61,8 @@ export class VSCodeNotebook implements IVSCodeNotebook { this.canUseNotebookApi = true; this.onDidChangeNotebookEditorSelection = window.onDidChangeNotebookEditorSelection; this.onDidChangeActiveNotebookEditor = window.onDidChangeActiveNotebookEditor; - this.onDidOpenNotebookDocument = notebooks.onDidOpenNotebookDocument; - this.onDidCloseNotebookDocument = notebooks.onDidCloseNotebookDocument; + this.onDidOpenNotebookDocument = workspace.onDidOpenNotebookDocument; + this.onDidCloseNotebookDocument = workspace.onDidCloseNotebookDocument; this.onDidChangeVisibleNotebookEditors = window.onDidChangeVisibleNotebookEditors; this.onDidSaveNotebookDocument = notebooks.onDidSaveNotebookDocument; this.onDidChangeNotebookDocument = this._onDidChangeNotebookDocument.event; @@ -86,7 +87,7 @@ export class VSCodeNotebook implements IVSCodeNotebook { transientDocumentMetadata?: { [x: string]: boolean | undefined } | undefined; } ): Disposable { - return notebooks.registerNotebookContentProvider(notebookType, provider, options); + return workspace.registerNotebookContentProvider(notebookType, provider, options); } public createNotebookController( id: string, diff --git a/src/client/datascience/jupyter/kernels/cellExecution.ts b/src/client/datascience/jupyter/kernels/cellExecution.ts index 494402ce634..f02c437e430 100644 --- a/src/client/datascience/jupyter/kernels/cellExecution.ts +++ b/src/client/datascience/jupyter/kernels/cellExecution.ts @@ -185,7 +185,8 @@ export class CellExecution { `Cell Exec contents ${this.cell.document.getText().substring(0, 50)}...` ); if (!this.canExecuteCell()) { - this.execution?.end({}); + // End state is bool | undefined not optional. Undefined == not success or failure + this.execution?.end(undefined); this.execution = undefined; return; } @@ -199,7 +200,7 @@ export class CellExecution { this.startTime = new Date().getTime(); CellExecution.activeNotebookCellExecution.set(this.cell.notebook, this.execution); - this.execution?.start({ startTime: this.startTime }); + this.execution?.start(this.startTime); await Promise.all([this.initPromise, this.execution?.clearOutput()]); this.stopWatch.reset(); @@ -289,13 +290,15 @@ export class CellExecution { } private endCellTask(success: 'success' | 'failed' | 'cancelled') { if (this.isEmptyCodeCell) { - this.execution?.end({}); + // Undefined for not success or failures + this.execution?.end(undefined); } else if (success === 'success' || success === 'failed') { this.endTime = new Date().getTime(); - this.execution?.end({ endTime: this.endTime, success: success === 'success' }); + this.execution?.end(success === 'success', this.endTime); } else { // Cell was cancelled. - this.execution?.end({}); + // Undefined for not success or failures + this.execution?.end(undefined); } if (CellExecution.activeNotebookCellExecution.get(this.cell.notebook) === this.execution) { CellExecution.activeNotebookCellExecution.set(this.cell.notebook, undefined); @@ -323,7 +326,7 @@ export class CellExecution { // Create a temporary task. this.previousResultsToRestore = { ...(this.cell.executionSummary || {}) }; this.temporaryExecution = this.controller.createNotebookCellExecution(this.cell); - this.temporaryExecution?.start({}); + this.temporaryExecution?.start(); if (this.previousResultsToRestore?.executionOrder && this.execution) { this.execution.executionOrder = this.previousResultsToRestore.executionOrder; } @@ -337,12 +340,13 @@ export class CellExecution { if (this.previousResultsToRestore.executionOrder) { this.temporaryExecution.executionOrder = this.previousResultsToRestore.executionOrder; } - this.temporaryExecution.end({ - endTime: this.previousResultsToRestore.endTime, - success: this.previousResultsToRestore.success - }); + this.temporaryExecution.end( + this.previousResultsToRestore.success, + this.previousResultsToRestore.timing?.endTime + ); } else { - this.temporaryExecution?.end({}); + // Undefined for not success or failure + this.temporaryExecution?.end(undefined); } this.previousResultsToRestore = undefined; this.temporaryExecution = undefined; @@ -719,7 +723,7 @@ export class CellExecution { name: msg.content.name, text: formatStreamText(concatMultilineString(`${existingOutputText}${newContent}`)) }); - promise = task?.replaceOutputItems(output.items, existingOutputToAppendTo.id); + promise = task?.replaceOutputItems(output.items, existingOutputToAppendTo); } else if (clearOutput) { // Replace the current outputs with a single new output. const output = cellOutputToVSCCellOutput({ @@ -857,7 +861,7 @@ export class CellExecution { // This message could have come from a background thread. // In such circumstances, create a temporary task & use that to update the output (only cell execution tasks can update cell output). const task = this.execution || this.createTemporaryTask(); - const promise = task?.replaceOutputItems(newOutput.items, outputToBeUpdated.id); + const promise = task?.replaceOutputItems(newOutput.items, outputToBeUpdated); this.endTemporaryTask(); // await on the promise at the end, we want to minimize UI flickers. // The way we update output of other cells is to use an existing task or a temporary task. diff --git a/src/client/datascience/jupyter/kernels/kernelExecution.ts b/src/client/datascience/jupyter/kernels/kernelExecution.ts index 26f1f70e3c0..1ac206ad2ea 100644 --- a/src/client/datascience/jupyter/kernels/kernelExecution.ts +++ b/src/client/datascience/jupyter/kernels/kernelExecution.ts @@ -3,7 +3,7 @@ 'use strict'; -import { notebooks, NotebookCell, NotebookCellKind, NotebookController, NotebookDocument } from 'vscode'; +import { NotebookCell, NotebookCellKind, NotebookController, NotebookDocument, workspace } from 'vscode'; import { ServerStatus } from '../../../../datascience-ui/interactive-common/mainState'; import { IApplicationShell } from '../../../common/application/types'; import { traceInfo, traceWarning } from '../../../common/logger'; @@ -133,7 +133,7 @@ export class KernelExecution implements IDisposable { ); // If the document is closed (user or on CI), then just stop handling the UI updates & cancel cell execution queue. - notebooks.onDidCloseNotebookDocument( + workspace.onDidCloseNotebookDocument( async (e: NotebookDocument) => { if (e === document) { if (!newCellExecutionQueue.failed || !newCellExecutionQueue.isEmpty) { diff --git a/src/client/datascience/notebook/contentProvider.ts b/src/client/datascience/notebook/contentProvider.ts index 2606d3cca85..c39a4b521d7 100644 --- a/src/client/datascience/notebook/contentProvider.ts +++ b/src/client/datascience/notebook/contentProvider.ts @@ -44,16 +44,15 @@ export class NotebookContentProvider implements VSCNotebookContentProvider { if (!this.compatibilitySupport.canOpenWithVSCodeNotebookEditor(uri)) { // If not supported, return a notebook with error displayed. // We cannot, not display a notebook. + const cellData = new NotebookCellData( + NotebookCellKind.Markup, + `# ${DataScience.usingPreviewNotebookWithOtherNotebookWarning()}`, + MARKDOWN_LANGUAGE + ); + cellData.outputs = []; + cellData.metadata = {}; return { - cells: [ - new NotebookCellData( - NotebookCellKind.Markup, - `# ${DataScience.usingPreviewNotebookWithOtherNotebookWarning()}`, - MARKDOWN_LANGUAGE, - [], - {} - ) - ], + cells: [cellData], metadata: {} }; } diff --git a/src/client/datascience/notebook/helpers/executionHelpers.ts b/src/client/datascience/notebook/helpers/executionHelpers.ts index 081b63aa622..c7dc7cc710c 100644 --- a/src/client/datascience/notebook/helpers/executionHelpers.ts +++ b/src/client/datascience/notebook/helpers/executionHelpers.ts @@ -48,8 +48,9 @@ export async function updateCellCode(cell: NotebookCell, text: string) { export async function addNewCellAfter(cell: NotebookCell, text: string) { await chainWithPendingUpdates(cell.notebook, (edit) => { traceCellMessage(cell, 'Create new cell after current'); - edit.replaceNotebookCells(cell.notebook.uri, new NotebookRange(cell.index + 1, cell.index + 1), [ - new NotebookCellData(NotebookCellKind.Code, text, cell.document.languageId, [], cell.metadata || {}) - ]); + const cellData = new NotebookCellData(NotebookCellKind.Code, text, cell.document.languageId); + cellData.outputs = []; + cellData.metadata = {}; + edit.replaceNotebookCells(cell.notebook.uri, new NotebookRange(cell.index + 1, cell.index + 1), [cellData]); }); } diff --git a/src/client/datascience/notebook/helpers/helpers.ts b/src/client/datascience/notebook/helpers/helpers.ts index 62abecbd166..d9ee63b4a47 100644 --- a/src/client/datascience/notebook/helpers/helpers.ts +++ b/src/client/datascience/notebook/helpers/helpers.ts @@ -304,9 +304,10 @@ function createCodeCellFromNotebookCell(cell: NotebookCell): nbformat.ICodeCell } function createNotebookCellDataFromRawCell(cell: nbformat.IRawCell): NotebookCellData { - return new NotebookCellData(NotebookCellKind.Code, concatMultilineString(cell.source), 'raw', [], { - custom: getNotebookCellMetadata(cell) - }); + const cellData = new NotebookCellData(NotebookCellKind.Code, concatMultilineString(cell.source), 'raw'); + cellData.outputs = []; + cellData.metadata = { custom: getNotebookCellMetadata(cell) }; + return cellData; } function createMarkdownCellFromNotebookCell(cell: NotebookCell): nbformat.IMarkdownCell { const cellMetadata = cell.metadata.custom as CellMetadata | undefined; @@ -321,9 +322,14 @@ function createMarkdownCellFromNotebookCell(cell: NotebookCell): nbformat.IMarkd return markdownCell; } function createNotebookCellDataFromMarkdownCell(cell: nbformat.IMarkdownCell): NotebookCellData { - return new NotebookCellData(NotebookCellKind.Markup, concatMultilineString(cell.source), MARKDOWN_LANGUAGE, [], { - custom: getNotebookCellMetadata(cell) - }); + const cellData = new NotebookCellData( + NotebookCellKind.Markup, + concatMultilineString(cell.source), + MARKDOWN_LANGUAGE + ); + cellData.outputs = []; + cellData.metadata = { custom: getNotebookCellMetadata(cell) }; + return cellData; } function createNotebookCellDataFromCodeCell(cell: nbformat.ICodeCell, cellLanguage: string): NotebookCellData { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -336,14 +342,13 @@ function createNotebookCellDataFromCodeCell(cell: nbformat.ICodeCell, cellLangua const executionSummary: NotebookCellExecutionSummary = hasExecutionCount ? { executionOrder: cell.execution_count as number } : {}; - return new NotebookCellData( - NotebookCellKind.Code, - source, - cellLanguage, - outputs, - { custom: getNotebookCellMetadata(cell) }, - executionSummary - ); + + const cellData = new NotebookCellData(NotebookCellKind.Code, source, cellLanguage); + + cellData.outputs = outputs; + cellData.metadata = { custom: getNotebookCellMetadata(cell) }; + cellData.executionSummary = executionSummary; + return cellData; } const orderOfMimeTypes = [ 'application/vnd.*', diff --git a/src/client/datascience/notebook/noKernelsNotebookController.ts b/src/client/datascience/notebook/noKernelsNotebookController.ts index 540fa91fc55..2bb0b6559c7 100644 --- a/src/client/datascience/notebook/noKernelsNotebookController.ts +++ b/src/client/datascience/notebook/noKernelsNotebookController.ts @@ -79,7 +79,7 @@ export class NoKernelsNotebookController implements Disposable { traceback: errorMessage.split('\n') }); task.appendOutput(errorOutput).then(noop, noop); - task.end(); + task.end(undefined); this.errorHandler.handleError(new KernelSpecNotFoundError(getNotebookMetadata(notebook))).catch(noop); } } diff --git a/src/client/datascience/notebook/vscodeNotebookController.ts b/src/client/datascience/notebook/vscodeNotebookController.ts index 79a34e093e1..f8453f1042e 100644 --- a/src/client/datascience/notebook/vscodeNotebookController.ts +++ b/src/client/datascience/notebook/vscodeNotebookController.ts @@ -106,7 +106,7 @@ export class VSCodeNotebookController implements Disposable { this.controller.interruptHandler = this.handleInterrupt.bind(this); this.controller.description = getDescriptionOfKernelConnection(kernelConnection); this.controller.detail = getDetailOfKernelConnection(kernelConnection, this.pathUtils); - this.controller.hasExecutionOrder = true; + this.controller.supportsExecutionOrder = true; this.controller.supportedLanguages = this.languageService.getSupportedLanguages(kernelConnection); // Hook up to see when this NotebookController is selected by the UI this.controller.onDidChangeNotebookAssociation(this.onDidChangeNotebookAssociation, this, this.disposables); diff --git a/src/client/datascience/utils.ts b/src/client/datascience/utils.ts index 67819ac2176..e23a78bfb71 100644 --- a/src/client/datascience/utils.ts +++ b/src/client/datascience/utils.ts @@ -65,7 +65,7 @@ export function translateCellToNative( executionSummary: { executionOrder: cell.data.execution_count as number, success: true, - endTime: 0 + timing: { startTime: 0, endTime: 0 } }, outputs: [], kind: NotebookCellKind.Code, diff --git a/src/test/datascience/notebook/contentProviderMain.vscode.test.ts b/src/test/datascience/notebook/contentProviderMain.vscode.test.ts index 79842085c50..b5315a7fbfd 100644 --- a/src/test/datascience/notebook/contentProviderMain.vscode.test.ts +++ b/src/test/datascience/notebook/contentProviderMain.vscode.test.ts @@ -69,27 +69,25 @@ suite('DataScience - VSCode Notebook ContentProvider', () => { assert.isOk(notebook); - assert.deepEqual(notebook.cells, [ - new NotebookCellData( - NotebookCellKind.Code, - 'print(1)', - PYTHON_LANGUAGE, - [], - { - custom: { - metadata: {} - } - }, - { - executionOrder: 10 - } - ), - new NotebookCellData(NotebookCellKind.Markup, '# HEAD', MARKDOWN_LANGUAGE, [], { - custom: { - metadata: {} - } - }) - ]); + const codeCellData = new NotebookCellData(NotebookCellKind.Code, 'print(1)', PYTHON_LANGUAGE); + + codeCellData.outputs = []; + codeCellData.metadata = { + custom: { + metadata: {} + } + }; + codeCellData.executionSummary = { executionOrder: 10 }; + + const markdownCellData = new NotebookCellData(NotebookCellKind.Markup, '# HEAD', MARKDOWN_LANGUAGE); + markdownCellData.outputs = []; + markdownCellData.metadata = { + custom: { + metadata: {} + } + }; + + assert.deepEqual(notebook.cells, [codeCellData, markdownCellData]); }); test('Return notebook with csharp language', async () => { @@ -121,27 +119,29 @@ suite('DataScience - VSCode Notebook ContentProvider', () => { assert.isOk(notebook); - assert.deepEqual(notebook.cells, [ - new NotebookCellData( - NotebookCellKind.Code, - 'Console.WriteLine("1")', - 'csharp', - [], - { - custom: { - metadata: {} - } - }, - { - executionOrder: 10 - } - ), - new NotebookCellData(NotebookCellKind.Markup, '# HEAD', MARKDOWN_LANGUAGE, [], { - custom: { - metadata: {} - } - }) - ]); + const codeCellData = new NotebookCellData(NotebookCellKind.Code, 'Console.WriteLine("1")', 'csharp'); + + codeCellData.outputs = []; + codeCellData.metadata = { + custom: { + metadata: {} + } + }; + + codeCellData.executionSummary = { + executionOrder: 10 + }; + + const markdownCellData = new NotebookCellData(NotebookCellKind.Markup, '# HEAD', MARKDOWN_LANGUAGE); + + markdownCellData.outputs = []; + markdownCellData.metadata = { + custom: { + metadata: {} + } + }; + + assert.deepEqual(notebook.cells, [codeCellData, markdownCellData]); }); test('Verify mime types and order', () => { // https://github.com/microsoft/vscode-python/issues/11880 diff --git a/src/test/datascience/notebook/helper.ts b/src/test/datascience/notebook/helper.ts index 34d6ec426c3..aa8239cced0 100644 --- a/src/test/datascience/notebook/helper.ts +++ b/src/test/datascience/notebook/helper.ts @@ -87,11 +87,12 @@ export async function insertMarkdownCell(source: string, options?: { index?: num throw new Error('No active editor'); } const startNumber = options?.index ?? activeEditor.document.cellCount; - await chainWithPendingUpdates(activeEditor.document, (edit) => - edit.replaceNotebookCells(activeEditor.document.uri, new NotebookRange(startNumber, startNumber), [ - new NotebookCellData(NotebookCellKind.Markup, source, MARKDOWN_LANGUAGE, [], {}) - ]) - ); + await chainWithPendingUpdates(activeEditor.document, (edit) => { + const cellData = new NotebookCellData(NotebookCellKind.Markup, source, MARKDOWN_LANGUAGE); + cellData.outputs = []; + cellData.metadata = {}; + edit.replaceNotebookCells(activeEditor.document.uri, new NotebookRange(startNumber, startNumber), [cellData]); + }); return activeEditor.document.cellAt(startNumber)!; } export async function insertCodeCell(source: string, options?: { language?: string; index?: number }) { @@ -102,9 +103,10 @@ export async function insertCodeCell(source: string, options?: { language?: stri } const startNumber = options?.index ?? activeEditor.document.cellCount; const edit = new WorkspaceEdit(); - edit.replaceNotebookCells(activeEditor.document.uri, new NotebookRange(startNumber, startNumber), [ - new NotebookCellData(NotebookCellKind.Code, source, options?.language || PYTHON_LANGUAGE, [], {}) - ]); + const cellData = new NotebookCellData(NotebookCellKind.Code, source, options?.language || PYTHON_LANGUAGE); + cellData.outputs = []; + cellData.metadata = {}; + edit.replaceNotebookCells(activeEditor.document.uri, new NotebookRange(startNumber, startNumber), [cellData]); await workspace.applyEdit(edit); return activeEditor.document.cellAt(startNumber)!; diff --git a/src/test/datascience/notebook/helpers.vscode.test.ts b/src/test/datascience/notebook/helpers.vscode.test.ts index aacdc4af772..35f1b767180 100644 --- a/src/test/datascience/notebook/helpers.vscode.test.ts +++ b/src/test/datascience/notebook/helpers.vscode.test.ts @@ -33,23 +33,23 @@ suite('DataScience - VSCode Notebook - helpers', () => { const notebook = notebookModelToVSCNotebookData({}, Uri.file(''), cells as any, PYTHON_LANGUAGE, {}); assert.isOk(notebook); - assert.deepEqual(notebook.cells, [ - new NotebookCellData( - NotebookCellKind.Code, - 'print(1)', - PYTHON_LANGUAGE, - [], - { - custom: { metadata: {} } - }, - { - executionOrder: 10 - } - ), - new NotebookCellData(NotebookCellKind.Markup, '# HEAD', MARKDOWN_LANGUAGE, [], { - custom: { metadata: {} } - }) - ]); + + const codeCellData = new NotebookCellData(NotebookCellKind.Code, 'print(1)', PYTHON_LANGUAGE); + codeCellData.outputs = []; + codeCellData.metadata = { + custom: { metadata: {} } + }; + codeCellData.executionSummary = { + executionOrder: 10 + }; + const markdownCellData = new NotebookCellData(NotebookCellKind.Markup, '# HEAD', MARKDOWN_LANGUAGE); + + markdownCellData.outputs = []; + markdownCellData.metadata = { + custom: { metadata: {} } + }; + + assert.deepEqual(notebook.cells, [codeCellData, markdownCellData]); }); suite('Outputs', () => { function validateCellOutputTranslation( diff --git a/src/test/vscode-mock.ts b/src/test/vscode-mock.ts index 3bf85bb9d77..862c125345a 100644 --- a/src/test/vscode-mock.ts +++ b/src/test/vscode-mock.ts @@ -70,7 +70,7 @@ export function initialize() { const commands = new MockCommands(); (mockedVSCode as any).commands = commands; mockedVSCodeNamespaces.commands = commands as any; - mockedVSCodeNamespaces.notebooks?.setup((nb) => nb.notebookDocuments).returns(() => []); + mockedVSCodeNamespaces.workspace?.setup((ws) => ws.notebookDocuments).returns(() => []); mockedVSCodeNamespaces.window?.setup((w) => w.visibleNotebookEditors).returns(() => []); // Use mock clipboard fo testing purposes. const clipboard = new MockClipboard(); diff --git a/vscode.d.ts b/vscode.d.ts index f9a4ddc9a18..74f694427a2 100644 --- a/vscode.d.ts +++ b/vscode.d.ts @@ -9857,7 +9857,7 @@ declare module 'vscode' { readonly onDidTriggerButton: Event; /** - * Items to pick from. + * Items to pick from. This can be read and updated by the extension. */ items: readonly T[]; @@ -10639,6 +10639,65 @@ declare module 'vscode' { */ export const onDidSaveTextDocument: Event; + /** + * All notebook documents currently known to the editor. + */ + export const notebookDocuments: readonly NotebookDocument[]; + + /** + * Open a notebook. Will return early if this notebook is already {@link notebook.notebookDocuments loaded}. Otherwise + * the notebook is loaded and the {@link notebook.onDidOpenNotebookDocument `onDidOpenNotebookDocument`}-event fires. + * + * *Note* that the lifecycle of the returned notebook is owned by the editor and not by the extension. That means an + * {@link notebook.onDidCloseNotebookDocument `onDidCloseNotebookDocument`}-event can occur at any time after. + * + * *Note* that opening a notebook does not show a notebook editor. This function only returns a notebook document which + * can be showns in a notebook editor but it can also be used for other things. + * + * @param uri The resource to open. + * @returns A promise that resolves to a {@link NotebookDocument notebook} + */ + export function openNotebookDocument(uri: Uri): Thenable; + + /** + * Open an untitled notebook. The editor will prompt the user for a file + * path when the document is to be saved. + * + * @see {@link openNotebookDocument} + * @param notebookType The notebook type that should be used. + * @param content The initial contents of the notebook. + * @returns A promise that resolves to a {@link NotebookDocument notebook}. + */ + export function openNotebookDocument(notebookType: string, content?: NotebookData): Thenable; + + /** + * Register a {@link NotebookSerializer notebook serializer}. + * + * A notebook serializer must be contributed through the `notebooks` extension point. When opening a notebook file, the editor will send + * the `onNotebook:` activation event, and extensions must register their serializer in return. + * + * @param notebookType A notebook. + * @param serializer A notebook serialzier. + * @param options Optional context options that define what parts of a notebook should be persisted + * @return A {@link Disposable} that unregisters this serializer when being disposed. + */ + export function registerNotebookSerializer(notebookType: string, serializer: NotebookSerializer, options?: NotebookDocumentContentOptions): Disposable; + + /** + * An event that is emitted when a {@link NotebookDocument notebook} is opened. + */ + export const onDidOpenNotebookDocument: Event; + + /** + * An event that is emitted when a {@link NotebookDocument notebook} is disposed. + * + * *Note 1:* There is no guarantee that this event fires when an editor tab is closed. + * + * *Note 2:* A notebook can be open but not shown in an editor which means this event can fire + * for a notebook that has not been shown in an editor. + */ + export const onDidCloseNotebookDocument: Event; + /** * An event that is emitted when files are being created. * @@ -11371,10 +11430,6 @@ declare module 'vscode' { */ readonly uri: Uri; - /** @deprecated */ - // todo@API remove - readonly viewType: string; - /** * The type of notebook. */ @@ -11454,16 +11509,9 @@ declare module 'vscode' { readonly success?: boolean; /** - * The unix timestamp at which execution started. + * The times at which execution started and ended, as unix timestamps */ - // @rob - //todo@API think about invalid state (no end, but start and vice versa) - readonly startTime?: number; - - /** - * The unix timestamp at which execution ended. - */ - readonly endTime?: number; + readonly timing?: { startTime: number, endTime: number }; } /** @@ -11564,7 +11612,7 @@ declare module 'vscode' { static error(value: Error): NotebookCellOutputItem; /** - * The mime type which determines how the {@link NotebookCellOutputItem.value `value`}-property + * The mime type which determines how the {@link NotebookCellOutputItem.data `data`}-property * is interpreted. * * Notebooks have built-in support for certain mime-types, extensions can add support for new @@ -11591,15 +11639,8 @@ declare module 'vscode' { * {@link NotebookCellOutputItem output items} where contained items represent the same result but * use different MIME types. */ - //todo@API - add sugar function to add more outputs export class NotebookCellOutput { - /** - * Identifier for this output. Using the identifier allows a subsequent execution to modify - * existing output. Defaults to a fresh UUID. - */ - id: string; - /** * The output items of this output. Each item must represent the same result. _Note_ that repeated * MIME types per output is invalid and that the editor will just pick one of them. @@ -11620,24 +11661,13 @@ declare module 'vscode' { */ metadata?: { [key: string]: any }; - /** - * Create new notebook output. - * - * @param outputs Notebook output items. - * @param metadata Optional metadata. - */ - constructor(outputs: NotebookCellOutputItem[], metadata?: { [key: string]: any }); - /** * Create new notebook output. * * @param items Notebook output items. - * @param id Identifier of this output. * @param metadata Optional metadata. */ - //todo@API id-args is not used by jupyter but we it added with display_id in mind... - // @jupyter check if needed - constructor(items: NotebookCellOutputItem[], id: string, metadata?: { [key: string]: any }); + constructor(items: NotebookCellOutputItem[], metadata?: { [key: string]: any }); } /** @@ -11683,12 +11713,8 @@ declare module 'vscode' { * @param kind The kind. * @param value The source value. * @param languageId The language identifier of the source value. - * @param outputs Optional outputs. - * @param metadata Optional metadata. - * @param executionSummary Optional execution summary. */ - // todo@API should ctors only have the args for required properties? - constructor(kind: NotebookCellKind, value: string, languageId: string, outputs?: NotebookCellOutput[], metadata?: { [key: string]: any }, executionSummary?: NotebookCellExecutionSummary); + constructor(kind: NotebookCellKind, value: string, languageId: string); } /** @@ -11824,10 +11850,6 @@ declare module 'vscode' { */ readonly id: string; - // todo@api remove - /** @deprecated */ - readonly viewType: string; - /** * The notebook type this controller is for. */ @@ -11871,10 +11893,6 @@ declare module 'vscode' { */ supportsExecutionOrder?: boolean; - // todo@API remove - /** @deprecated */ - hasExecutionOrder?: boolean; - /** * Create a cell execution task. * @@ -11933,32 +11951,6 @@ declare module 'vscode' { dispose(): void; } - // todo@api jsdoc - // todo@api Inline unless we can come up with more (future) properties - export interface NotebookCellExecuteStartContext { - /** - * The time that execution began, in milliseconds in the Unix epoch. Used to drive the clock - * that shows for how long a cell has been running. If not given, the clock won't be shown. - */ - startTime?: number; - } - - // todo@api jsdoc - // todo@api Inline unless we can come up with more (future) properties - export interface NotebookCellExecuteEndContext { - /** - * If true, a green check is shown on the cell status bar. - * If false, a red X is shown. - * If undefined, no check or X icon is shown. - */ - success?: boolean; - - /** - * The time that execution finished, in milliseconds in the Unix epoch. - */ - endTime?: number; - } - /** * A NotebookCellExecution is how {@link NotebookController notebook controller} modify a notebook cell as * it is executing. @@ -11988,13 +11980,23 @@ declare module 'vscode' { */ executionOrder: number | undefined; - // todo@API inline context object? - // @rob inline as arguments - start(context?: NotebookCellExecuteStartContext): void; + /** + * Signal that the execution has begun. + * + * @param startTime The time that execution began, in milliseconds in the Unix epoch. Used to drive the clock + * that shows for how long a cell has been running. If not given, the clock won't be shown. + */ + start(startTime?: number): void; - // todo@API inline context object? - // @rob inline as arguments - end(result?: NotebookCellExecuteEndContext): void; + /** + * Signal that execution has ended. + * + * @param success If true, a green check is shown on the cell status bar. + * If false, a red X is shown. + * If undefined, no check or X icon is shown. + * @param endTime The time that execution finished, in milliseconds in the Unix epoch. + */ + end(success: boolean | undefined, endTime?: number): void; /** * Clears the output of the cell that is executing or of another cell that is affected by this execution. @@ -12029,19 +12031,19 @@ declare module 'vscode' { * Replace all output items of existing cell output. * * @param items Output items that replace the items of existing output. - * @param output Output object or the identifier of one. + * @param output Output object that already exists. * @return A thenable that resolves when the operation finished. */ - replaceOutputItems(items: NotebookCellOutputItem | NotebookCellOutputItem[], output: NotebookCellOutput | string): Thenable; + replaceOutputItems(items: NotebookCellOutputItem | NotebookCellOutputItem[], output: NotebookCellOutput): Thenable; /** * Append output items to existing cell output. * * @param items Output items that are append to existing output. - * @param output Output object or the identifier of one. + * @param output Output object that already exists. * @return A thenable that resolves when the operation finished. */ - appendOutputItems(items: NotebookCellOutputItem | NotebookCellOutputItem[], output: NotebookCellOutput | string): Thenable; + appendOutputItems(items: NotebookCellOutputItem | NotebookCellOutputItem[], output: NotebookCellOutput): Thenable; } /** @@ -12101,11 +12103,10 @@ declare module 'vscode' { /** * Creates a new NotebookCellStatusBarItem. + * @param text The text to show for the item. + * @param alignment Whether the item is aligned to the left or right. */ - // @rob - // todo@API jsdoc for args - // todo@API should ctors only have the args for required properties? - constructor(text: string, alignment: NotebookCellStatusBarAlignment, command?: string | Command, tooltip?: string, priority?: number, accessibilityInformation?: AccessibilityInformation); + constructor(text: string, alignment: NotebookCellStatusBarAlignment); } /** @@ -12121,11 +12122,9 @@ declare module 'vscode' { * The provider will be called when the cell scrolls into view, when its content, outputs, language, or metadata change, and when it changes execution state. * @param cell The cell for which to return items. * @param token A token triggered if this request should be cancelled. + * @return One or more {@link NotebookCellStatusBarItem cell statusbar items} */ - // @rob - //todo@API jsdoc for return-type - //todo@API should this return T | T[] - provideCellStatusBarItems(cell: NotebookCell, token: CancellationToken): ProviderResult; + provideCellStatusBarItems(cell: NotebookCell, token: CancellationToken): ProviderResult; } /** @@ -12137,74 +12136,8 @@ declare module 'vscode' { * 2. {@link NotebookController} own the execution of notebooks, e.g they create output from code cells. * 3. NotebookRenderer present notebook output in the editor. They run in a separate context. */ - // todo@api what should be in this namespace? should notebookDocuments and friends be in the workspace namespace? export namespace notebooks { - /** - * All notebook documents currently known to the editor. - */ - // todo@api move to workspace - export const notebookDocuments: readonly NotebookDocument[]; - - /** - * Open a notebook. Will return early if this notebook is already {@link notebook.notebookDocuments loaded}. Otherwise - * the notebook is loaded and the {@link notebook.onDidOpenNotebookDocument `onDidOpenNotebookDocument`}-event fires. - * - * *Note* that the lifecycle of the returned notebook is owned by the editor and not by the extension. That means an - * {@link notebook.onDidCloseNotebookDocument `onDidCloseNotebookDocument`}-event can occur at any time after. - * - * *Note* that opening a notebook does not show a notebook editor. This function only returns a notebook document which - * can be showns in a notebook editor but it can also be used for other things. - * - * @param uri The resource to open. - * @returns A promise that resolves to a {@link NotebookDocument notebook} - */ - // todo@api move to workspace - export function openNotebookDocument(uri: Uri): Thenable; - - /** - * Open an untitled notebook. The editor will prompt the user for a file - * path when the document is to be saved. - * - * @see {@link openNotebookDocument} - * @param notebookType The notebook type that should be used. - * @param content The initial contents of the notebook. - * @returns A promise that resolves to a {@link NotebookDocument notebook}. - */ - // todo@api move to workspace - export function openNotebookDocument(notebookType: string, content?: NotebookData): Thenable; - - /** - * An event that is emitted when a {@link NotebookDocument notebook} is opened. - */ - // todo@api move to workspace - export const onDidOpenNotebookDocument: Event; - - /** - * An event that is emitted when a {@link NotebookDocument notebook} is disposed. - * - * *Note 1:* There is no guarantee that this event fires when an editor tab is closed. - * - * *Note 2:* A notebook can be open but not shown in an editor which means this event can fire - * for a notebook that has not been shown in an editor. - */ - // todo@api move to workspace - export const onDidCloseNotebookDocument: Event; - - /** - * Register a {@link NotebookSerializer notebook serializer}. - * - * A notebook serializer must to be contributed through the `notebooks` extension point. When opening a notebook file, the editor will send - * the `onNotebook:` activation event, and extensions must register their serializer in return. - * - * @param notebookType A notebook. - * @param serializer A notebook serialzier. - * @param options Optional context options that define what parts of a notebook should be persisted - * @return A {@link Disposable} that unregisters this serializer when being disposed. - */ - // todo@api move to workspace - export function registerNotebookSerializer(notebookType: string, serializer: NotebookSerializer, options?: NotebookDocumentContentOptions): Disposable; - /** * Creates a new notebook controller. * diff --git a/vscode.proposed.d.ts b/vscode.proposed.d.ts index 667119f880d..2ce6cc641a1 100644 --- a/vscode.proposed.d.ts +++ b/vscode.proposed.d.ts @@ -904,14 +904,14 @@ declare module 'vscode' { /** * The icon path or {@link ThemeIcon} for the terminal. */ - readonly iconPath?: Uri | { light: Uri; dark: Uri } | { id: string, color?: { id: string } }; + readonly iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon; } export interface ExtensionTerminalOptions { /** * A themeIcon, Uri, or light and dark Uris to use as the terminal tab icon */ - readonly iconPath?: Uri | { light: Uri; dark: Uri } | { id: string, color?: { id: string } }; + readonly iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon; } //#endregion @@ -1059,12 +1059,11 @@ declare module 'vscode' { //#endregion - //#region https://github.com/microsoft/vscode/issues/106744, Notebook, deprecated + //#region https://github.com/microsoft/vscode/issues/106744, Notebook, deprecated & misc - /** - * @deprecated use notebooks instead - */ - export const notebook: typeof notebooks; + export interface NotebookCellOutput { + id: string; + } //#endregion @@ -1391,7 +1390,7 @@ declare module 'vscode' { backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, token: CancellationToken): Thenable; } - export namespace notebooks { + export namespace workspace { // TODO@api use NotebookDocumentFilter instead of just notebookType:string? // TODO@API options duplicates the more powerful variant on NotebookContentProvider @@ -1408,7 +1407,7 @@ declare module 'vscode' { exclusive?: boolean; } - export namespace notebooks { + export namespace workspace { // SPECIAL overload with NotebookRegistrationData export function registerNotebookContentProvider(notebookType: string, provider: NotebookContentProvider, options?: NotebookDocumentContentOptions, registrationData?: NotebookRegistrationData): Disposable; // SPECIAL overload with NotebookRegistrationData @@ -2759,11 +2758,20 @@ declare module 'vscode' { //#region https://github.com/microsoft/vscode/issues/124024 @hediet @alexdima export namespace languages { + /** + * Registers an inline completion provider. + */ export function registerInlineCompletionItemProvider(selector: DocumentSelector, provider: InlineCompletionItemProvider): Disposable; } export interface InlineCompletionItemProvider { - provideInlineCompletionItems(document: TextDocument, position: Position, context: InlineCompletionContext, token: CancellationToken): ProviderResult>; + /** + * Provides inline completion items for the given position and document. + * If inline completions are enabled, this method will be called whenever the user stopped typing. + * It will also be called when the user explicitly triggers inline completions or asks for the next or previous inline completion. + * Use `context.triggerKind` to distinguish between these scenarios. + */ + provideInlineCompletionItems(document: TextDocument, position: Position, context: InlineCompletionContext, token: CancellationToken): ProviderResult | T[]>; } export interface InlineCompletionContext { @@ -2807,6 +2815,10 @@ declare module 'vscode' { /** * The range to replace. * Must begin and end on the same line. + * + * Prefer replacements over insertions to avoid cache invalidation. + * Instead of reporting a completion that extends a word, + * the whole word should be replaced with the extended word. */ range?: Range; @@ -2830,6 +2842,9 @@ declare module 'vscode' { * Be aware that this API will not ever be finalized. */ export interface InlineCompletionController { + /** + * Is fired when an inline completion item is shown to the user. + */ // eslint-disable-next-line vscode-dts-event-naming readonly onDidShowCompletionItem: Event>; }