From cf7da9f9c9d43f621d65c91e46c4a0847ff11cef Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Wed, 8 Jun 2022 09:27:03 -0700 Subject: [PATCH] Move kernel execution into the 'kernels' folder (#10354) * Move cellExecution logic into 'kernels' tree * Update telemetry --- TELEMETRY.md | 18 +-- src/intellisense/cellLanguageService.ts | 3 +- src/intellisense/diagnosticsProvider.ts | 4 +- .../emptyNotebookCellLanguageService.ts | 5 +- src/intellisense/intellisenseProvider.node.ts | 2 +- .../pythonKernelCompletionProvider.ts | 2 +- .../commands/exportCommands.ts | 2 +- .../editor-integration/cellFactory.ts | 2 +- .../editor-integration/codeLensFactory.ts | 3 +- .../editor-integration/decorator.ts | 2 +- .../editor-integration/hoverProvider.ts | 3 +- .../generatedCodeStoreManager.ts | 2 +- src/interactive-window/interactiveWindow.ts | 6 +- .../interactiveWindowCommandListener.ts | 11 +- .../interactiveWindowProvider.ts | 3 +- .../outputs/tracebackFormatter.ts | 2 +- src/kernels/activation.node.ts | 2 +- .../execution/cellDisplayIdTracker.ts | 2 +- .../execution/cellExecution.ts | 2 +- .../execution/cellExecutionCreator.ts | 0 .../execution/cellExecutionMessageHandler.ts | 3 +- .../cellExecutionMessageHandlerService.ts | 0 .../execution/cellExecutionQueue.ts | 2 +- .../execution/executionHelpers.ts | 0 .../execution}/helpers.ts | 130 ++++++------------ .../execution/kernelExecution.ts | 4 +- .../execution/notebookUpdater.ts | 0 src/kernels/helpers.ts | 3 +- .../jupyterCellOutputMimeTypeTracker.node.ts | 3 +- .../jupyter/launcher/serverPreload.node.ts | 2 +- src/kernels/kernel.base.ts | 6 +- src/kernels/kernel.node.ts | 4 +- src/kernels/kernel.web.ts | 4 +- src/kernels/kernelCommandListener.ts | 2 +- src/kernels/kernelCrashMonitor.ts | 2 +- src/kernels/kernelProvider.node.ts | 4 +- src/kernels/kernelProvider.web.ts | 4 +- src/kernels/serviceRegistry.node.ts | 2 + src/kernels/serviceRegistry.web.ts | 3 + src/notebooks/constants.ts | 3 - .../noPythonKernelsNotebookController.ts | 2 +- .../controllers/notebookControllerManager.ts | 6 +- src/notebooks/controllers/remoteSwitcher.ts | 2 +- .../controllers/vscodeNotebookController.ts | 55 +++++++- src/notebooks/notebookCommandListener.ts | 4 +- src/notebooks/notebookEditorProvider.ts | 3 +- src/notebooks/notebookUsageTracker.ts | 2 +- src/notebooks/outputs/tracebackFormatter.ts | 2 +- src/notebooks/serviceRegistry.node.ts | 2 - src/notebooks/serviceRegistry.web.ts | 2 - src/notebooks/types.ts | 7 +- src/platform/api/kernelApi.ts | 3 +- src/platform/common/activeEditorContext.ts | 4 +- src/platform/common/constants.ts | 3 +- .../common/dataScienceSurveyBanner.node.ts | 2 +- .../common/extensionRecommendation.node.ts | 2 +- src/platform/common/utils.ts | 54 +++++++- src/platform/errors/errorUtils.ts | 34 +---- .../display/visibilityFilter.node.ts | 2 +- src/telemetry/importTracker.node.ts | 2 +- .../extensionRecommendation.unit.test.ts | 2 +- .../interactiveWindow.vscode.common.test.ts | 2 +- .../installationPrompts.vscode.test.ts | 5 +- .../notebook/executionService.vscode.test.ts | 2 +- src/test/datascience/notebook/helper.ts | 11 +- .../intellisense/completion.vscode.test.ts | 2 +- .../notebook/interruptRestart.vscode.test.ts | 2 +- .../notebook/kernelCrashes.vscode.test.ts | 2 +- .../notebook/kernelRefresh.vscode.test.ts | 2 +- .../notebook/kernelSelection.vscode.test.ts | 2 +- .../outputDisplayOrder.vscode.test.ts | 2 +- .../updateNotebookMetadata.unit.test.ts | 2 +- .../plotViewer/plotViewer.vscode.test.ts | 2 +- src/test/initialize.ts | 2 +- .../generatedCodeStorageManager.unit.test.ts | 2 +- .../kernels/kernelProvider.node.unit.test.ts | 4 +- .../variablesView/notebookWatcher.ts | 4 +- 77 files changed, 252 insertions(+), 248 deletions(-) rename src/{notebooks => kernels}/execution/cellDisplayIdTracker.ts (97%) rename src/{notebooks => kernels}/execution/cellExecution.ts (99%) rename src/{notebooks => kernels}/execution/cellExecutionCreator.ts (100%) rename src/{notebooks => kernels}/execution/cellExecutionMessageHandler.ts (99%) rename src/{notebooks => kernels}/execution/cellExecutionMessageHandlerService.ts (100%) rename src/{notebooks => kernels}/execution/cellExecutionQueue.ts (99%) rename src/{notebooks => kernels}/execution/executionHelpers.ts (100%) rename src/{notebooks => kernels/execution}/helpers.ts (90%) rename src/{notebooks => kernels}/execution/kernelExecution.ts (99%) rename src/{notebooks => kernels}/execution/notebookUpdater.ts (100%) diff --git a/TELEMETRY.md b/TELEMETRY.md index a2759242298..60bec8d8244 100644 --- a/TELEMETRY.md +++ b/TELEMETRY.md @@ -1545,7 +1545,7 @@ No properties for event ## Locations Used -[src/notebooks/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/kernelExecution.ts) +[src/kernels/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/kernelExecution.ts) ```typescript this.documentExecutions.set(document, newCellExecutionQueue); return newCellExecutionQueue; @@ -2689,7 +2689,7 @@ function resetData(resource: Resource, eventName: string, properties: any) { ``` -[src/notebooks/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/kernelExecution.ts) +[src/kernels/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/kernelExecution.ts) ```typescript // Otherwise a real error occurred. sendKernelTelemetryEvent( @@ -2701,7 +2701,7 @@ function resetData(resource: Resource, eventName: string, properties: any) { ``` -[src/notebooks/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/kernelExecution.ts) +[src/kernels/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/kernelExecution.ts) ```typescript })(); @@ -5238,7 +5238,7 @@ No properties for event ## Locations Used -[src/notebooks/execution/cellExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/cellExecution.ts) +[src/kernels/execution/cellExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/cellExecution.ts) ```typescript const props = { notebook: true }; if (!CellExecution.sentExecuteCellTelemetry) { @@ -5281,7 +5281,7 @@ No properties for event ## Locations Used -[src/notebooks/execution/cellExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/cellExecution.ts) +[src/kernels/execution/cellExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/cellExecution.ts) ```typescript CellExecution.sentExecuteCellTelemetry = true; sendTelemetryEvent(Telemetry.ExecuteCellPerceivedCold, this.stopWatchForTelemetry.elapsedTime, props); @@ -5799,7 +5799,7 @@ No properties for event ## Locations Used -[src/notebooks/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/kernelExecution.ts) +[src/kernels/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/kernelExecution.ts) ```typescript return newCellExecutionQueue; } @@ -7995,7 +7995,7 @@ No properties for event ## Locations Used -[src/notebooks/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/kernelExecution.ts) +[src/kernels/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/kernelExecution.ts) ```typescript } @@ -8023,7 +8023,7 @@ No properties for event ## Locations Used -[src/notebooks/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/execution/kernelExecution.ts) +[src/kernels/execution/kernelExecution.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/kernelExecution.ts) ```typescript }); } @@ -8671,7 +8671,7 @@ No description provided ## Locations Used -[src/notebooks/helpers.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/helpers.ts) +[src/kernels/execution/helpers.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/kernels/execution/helpers.ts) ```typescript // Unless we already know its an unknown output type. const outputType: nbformat.OutputType = diff --git a/src/intellisense/cellLanguageService.ts b/src/intellisense/cellLanguageService.ts index 2cf39f2f763..5367d5f5abd 100644 --- a/src/intellisense/cellLanguageService.ts +++ b/src/intellisense/cellLanguageService.ts @@ -24,8 +24,7 @@ import { getLanguageInNotebookMetadata } from '../kernels/helpers'; import { KernelConnectionMetadata } from '../kernels/types'; -import { isJupyterNotebook, getNotebookMetadata } from '../notebooks/helpers'; -import { translateKernelLanguageToMonaco } from '../platform/common/utils'; +import { getNotebookMetadata, isJupyterNotebook, translateKernelLanguageToMonaco } from '../platform/common/utils'; export const LastSavedNotebookCellLanguage = 'DATASCIENCE.LAST_SAVED_CELL_LANGUAGE'; /** diff --git a/src/intellisense/diagnosticsProvider.ts b/src/intellisense/diagnosticsProvider.ts index b6daee4f233..7ee28b891fb 100644 --- a/src/intellisense/diagnosticsProvider.ts +++ b/src/intellisense/diagnosticsProvider.ts @@ -31,8 +31,8 @@ import { PYTHON_LANGUAGE } from '../platform/common/constants'; import { disposeAllDisposables } from '../platform/common/helpers'; import { IDisposable, IDisposableRegistry } from '../platform/common/types'; import { DataScience } from '../platform/common/utils/localize'; -import { JupyterNotebookView } from '../notebooks/constants'; -import { getAssociatedJupyterNotebook } from '../notebooks/helpers'; +import { JupyterNotebookView } from '../platform/common/constants'; +import { getAssociatedJupyterNotebook } from '../platform/common/utils'; type CellUri = string; type CellVersion = number; diff --git a/src/intellisense/emptyNotebookCellLanguageService.ts b/src/intellisense/emptyNotebookCellLanguageService.ts index 7986223284b..9d6049bc0e0 100644 --- a/src/intellisense/emptyNotebookCellLanguageService.ts +++ b/src/intellisense/emptyNotebookCellLanguageService.ts @@ -9,10 +9,9 @@ import { PYTHON_LANGUAGE } from '../platform/common/constants'; import { traceError } from '../platform/logging'; import { IDisposableRegistry } from '../platform/common/types'; import { noop } from '../platform/common/utils/misc'; -import { chainWithPendingUpdates } from '../notebooks/execution/notebookUpdater'; -import { isJupyterNotebook } from '../notebooks/helpers'; +import { chainWithPendingUpdates } from '../kernels/execution/notebookUpdater'; import { INotebookControllerManager } from '../notebooks/types'; -import { translateKernelLanguageToMonaco } from '../platform/common/utils'; +import { isJupyterNotebook, translateKernelLanguageToMonaco } from '../platform/common/utils'; import { IVSCodeNotebookController } from '../notebooks/controllers/types'; /** * If user creates a blank notebook, then they'll mostl likely end up with a blank cell with language, lets assume `Python`. diff --git a/src/intellisense/intellisenseProvider.node.ts b/src/intellisense/intellisenseProvider.node.ts index d4d50c06a1a..17e8af245f4 100644 --- a/src/intellisense/intellisenseProvider.node.ts +++ b/src/intellisense/intellisenseProvider.node.ts @@ -18,13 +18,13 @@ import { IDisposableRegistry, IConfigurationService, IsPreRelease } from '../pla import { IInterpreterService } from '../platform/interpreter/contracts'; import { PythonEnvironment } from '../platform/pythonEnvironments/info'; import { getInterpreterId } from '../platform/pythonEnvironments/info/interpreter'; -import { isJupyterNotebook } from '../notebooks/helpers'; import { INotebookControllerManager, INotebookCompletionProvider, INotebookEditorProvider } from '../notebooks/types'; import { LanguageServer } from './languageServer.node'; import { IVSCodeNotebookController } from '../notebooks/controllers/types'; import { getComparisonKey } from '../platform/vscode-path/resources'; import { CompletionRequest } from 'vscode-languageclient'; import { NotebookPythonPathService } from './notebookPythonPathService'; +import { isJupyterNotebook } from '../platform/common/utils'; const EmptyWorkspaceKey = ''; diff --git a/src/intellisense/pythonKernelCompletionProvider.ts b/src/intellisense/pythonKernelCompletionProvider.ts index 500cf935707..ceff9ea9b74 100644 --- a/src/intellisense/pythonKernelCompletionProvider.ts +++ b/src/intellisense/pythonKernelCompletionProvider.ts @@ -21,11 +21,11 @@ import { waitForPromise } from '../platform/common/utils/async'; import { isNotebookCell } from '../platform/common/utils/misc'; import { StopWatch } from '../platform/common/utils/stopWatch'; import { IJupyterSession, IKernelProvider } from '../kernels/types'; -import { getAssociatedJupyterNotebook } from '../notebooks/helpers'; import { INotebookCompletionProvider, INotebookEditorProvider } from '../notebooks/types'; import { mapJupyterKind } from './conversion'; import { isTestExecution, Settings } from '../platform/common/constants'; import { INotebookCompletion } from './types'; +import { getAssociatedJupyterNotebook } from '../platform/common/utils'; let IntellisenseTimeout = Settings.IntellisenseTimeout; export function setIntellisenseTimeout(timeoutMs: number) { diff --git a/src/interactive-window/commands/exportCommands.ts b/src/interactive-window/commands/exportCommands.ts index c07d659e5bf..06f082bab93 100644 --- a/src/interactive-window/commands/exportCommands.ts +++ b/src/interactive-window/commands/exportCommands.ts @@ -14,12 +14,12 @@ import { DataScience } from '../../platform/common/utils/localize'; import { isUri } from '../../platform/common/utils/misc'; import { PythonEnvironment } from '../../platform/pythonEnvironments/info'; import { sendTelemetryEvent } from '../../telemetry'; -import { getNotebookMetadata, isPythonNotebook } from '../../notebooks/helpers'; import { INotebookControllerManager } from '../../notebooks/types'; import { Commands, Telemetry } from '../../platform/common/constants'; import { IFileConverter, ExportFormat } from '../../platform/export/types'; import { IExportCommands, IInteractiveWindowProvider } from '../types'; import { IFileSystem } from '../../platform/common/platform/types'; +import { isPythonNotebook, getNotebookMetadata } from '../../platform/common/utils'; interface IExportQuickPickItem extends QuickPickItem { handler(): void; diff --git a/src/interactive-window/editor-integration/cellFactory.ts b/src/interactive-window/editor-integration/cellFactory.ts index 460ca5c201a..fe57a738db3 100644 --- a/src/interactive-window/editor-integration/cellFactory.ts +++ b/src/interactive-window/editor-integration/cellFactory.ts @@ -8,10 +8,10 @@ import { NotebookCell, NotebookCellKind, NotebookDocument, Range, TextDocument, import { appendLineFeed, generateMarkdownFromCodeLines, parseForComments } from '../../webviews/webview-side/common'; import { CellMatcher } from './cellMatcher'; -import { createJupyterCellFromVSCNotebookCell } from '../../notebooks/helpers'; import { ICell, ICellRange, IJupyterSettings, Resource } from '../../platform/common/types'; import { noop } from '../../platform/common/utils/misc'; import { getInteractiveCellMetadata } from '../helpers'; +import { createJupyterCellFromVSCNotebookCell } from '../../kernels/execution/helpers'; export function createCodeCell(): nbformat.ICodeCell; // eslint-disable-next-line @typescript-eslint/unified-signatures diff --git a/src/interactive-window/editor-integration/codeLensFactory.ts b/src/interactive-window/editor-integration/codeLensFactory.ts index 3d663fd07f3..a72685bce08 100644 --- a/src/interactive-window/editor-integration/codeLensFactory.ts +++ b/src/interactive-window/editor-integration/codeLensFactory.ts @@ -21,8 +21,7 @@ import { ICellRange, IConfigurationService, IDisposableRegistry, Resource } from import * as localize from '../../platform/common/utils/localize'; import { getInteractiveCellMetadata } from '../helpers'; import { IKernelProvider } from '../../kernels/types'; -import { InteractiveWindowView } from '../../notebooks/constants'; -import { CodeLensCommands, Commands } from '../../platform/common/constants'; +import { CodeLensCommands, Commands, InteractiveWindowView } from '../../platform/common/constants'; import { generateCellRangesFromDocument } from './cellFactory'; import { ICodeLensFactory, IGeneratedCode, IGeneratedCodeStorageFactory } from './types'; import { getAssociatedNotebookDocument } from '../../kernels/helpers'; diff --git a/src/interactive-window/editor-integration/decorator.ts b/src/interactive-window/editor-integration/decorator.ts index 837a6e6d3ce..34aafdc826e 100644 --- a/src/interactive-window/editor-integration/decorator.ts +++ b/src/interactive-window/editor-integration/decorator.ts @@ -9,7 +9,7 @@ import { IPythonExtensionChecker } from '../../platform/api/types'; import { IDocumentManager } from '../../platform/common/application/types'; import { PYTHON_LANGUAGE } from '../../platform/common/constants'; import { IConfigurationService, IDisposable, IDisposableRegistry } from '../../platform/common/types'; -import { getAssociatedJupyterNotebook } from '../../notebooks/helpers'; +import { getAssociatedJupyterNotebook } from '../../platform/common/utils'; import { generateCellRangesFromDocument } from './cellFactory'; @injectable() diff --git a/src/interactive-window/editor-integration/hoverProvider.ts b/src/interactive-window/editor-integration/hoverProvider.ts index 507c1268752..8173163e1a0 100644 --- a/src/interactive-window/editor-integration/hoverProvider.ts +++ b/src/interactive-window/editor-integration/hoverProvider.ts @@ -7,7 +7,7 @@ import * as vscode from 'vscode'; import { IExtensionSyncActivationService } from '../../platform/activation/types'; import { IVSCodeNotebook } from '../../platform/common/application/types'; import { Cancellation } from '../../platform/common/cancellation'; -import { Identifiers, PYTHON, Telemetry } from '../../platform/common/constants'; +import { Identifiers, InteractiveWindowView, PYTHON, Telemetry } from '../../platform/common/constants'; import { traceError } from '../../platform/logging'; import { IDisposableRegistry } from '../../platform/common/types'; @@ -15,7 +15,6 @@ import { sleep } from '../../platform/common/utils/async'; import { StopWatch } from '../../platform/common/utils/stopWatch'; import { sendTelemetryEvent } from '../../telemetry'; import { IKernel, IKernelProvider } from '../../kernels/types'; -import { InteractiveWindowView } from '../../notebooks/constants'; import { IJupyterVariables } from '../../kernels/variables/types'; import { IInteractiveWindowProvider } from '../types'; import { getInteractiveCellMetadata } from '../helpers'; diff --git a/src/interactive-window/generatedCodeStoreManager.ts b/src/interactive-window/generatedCodeStoreManager.ts index 10af4a8dd5f..8224fb34621 100644 --- a/src/interactive-window/generatedCodeStoreManager.ts +++ b/src/interactive-window/generatedCodeStoreManager.ts @@ -5,9 +5,9 @@ import { inject, injectable } from 'inversify'; import { NotebookDocument } from 'vscode'; import { getAssociatedNotebookDocument } from '../kernels/helpers'; import { IKernel, IKernelProvider } from '../kernels/types'; -import { InteractiveWindowView } from '../notebooks/constants'; import { INotebookControllerManager } from '../notebooks/types'; import { IExtensionSyncActivationService } from '../platform/activation/types'; +import { InteractiveWindowView } from '../platform/common/constants'; import { disposeAllDisposables } from '../platform/common/helpers'; import { IDisposable, IDisposableRegistry } from '../platform/common/types'; import { ICodeGeneratorFactory, IGeneratedCodeStorageFactory } from './editor-integration/types'; diff --git a/src/interactive-window/interactiveWindow.ts b/src/interactive-window/interactiveWindow.ts index c8a30e53bcc..a489e636ec7 100644 --- a/src/interactive-window/interactiveWindow.ts +++ b/src/interactive-window/interactiveWindow.ts @@ -52,9 +52,6 @@ import { DataScience } from '../platform/common/utils/localize'; import { createDeferred, Deferred } from '../platform/common/utils/async'; import { IServiceContainer } from '../platform/ioc/types'; import { SysInfoReason } from '../platform/messageTypes'; -import { chainWithPendingUpdates } from '../notebooks/execution/notebookUpdater'; -import { updateNotebookMetadata } from '../notebooks/helpers'; -import { CellExecutionCreator } from '../notebooks/execution/cellExecutionCreator'; import { createOutputWithErrorMessageForDisplay } from '../platform/errors/errorUtils'; import { INotebookExporter } from '../kernels/jupyter/types'; import { IDataScienceErrorHandler } from '../platform/errors/types'; @@ -74,6 +71,9 @@ import { InteractiveCellMetadata } from './editor-integration/types'; import { IInteractiveWindowDebuggingManager } from '../kernels/debugger/types'; +import { CellExecutionCreator } from '../kernels/execution/cellExecutionCreator'; +import { updateNotebookMetadata } from '../kernels/execution/helpers'; +import { chainWithPendingUpdates } from '../kernels/execution/notebookUpdater'; export class InteractiveWindow implements IInteractiveWindowLoadable { public get onDidChangeViewState(): Event { diff --git a/src/interactive-window/interactiveWindowCommandListener.ts b/src/interactive-window/interactiveWindowCommandListener.ts index e7edfb89c4b..b309a98e130 100644 --- a/src/interactive-window/interactiveWindowCommandListener.ts +++ b/src/interactive-window/interactiveWindowCommandListener.ts @@ -23,7 +23,13 @@ import { IDocumentManager, IVSCodeNotebook } from '../platform/common/application/types'; -import { Commands, JVSC_EXTENSION_ID, PYTHON_LANGUAGE, Telemetry } from '../platform/common/constants'; +import { + Commands, + JupyterNotebookView, + JVSC_EXTENSION_ID, + PYTHON_LANGUAGE, + Telemetry +} from '../platform/common/constants'; import { traceError, traceInfo } from '../platform/logging'; import { IFileSystem } from '../platform/common/platform/types'; import { IConfigurationService, IDataScienceCommandListener, IDisposableRegistry } from '../platform/common/types'; @@ -33,15 +39,14 @@ import { CommandSource } from '../platform/testing/common/constants'; import { JupyterInstallError } from '../platform/errors/jupyterInstallError'; import { INotebookControllerManager, INotebookEditorProvider } from '../notebooks/types'; import { KernelConnectionMetadata } from '../kernels/types'; -import { chainWithPendingUpdates } from '../notebooks/execution/notebookUpdater'; import { INotebookExporter, IJupyterExecution } from '../kernels/jupyter/types'; import { IDataScienceErrorHandler } from '../platform/errors/types'; import { IFileConverter, IExportDialog, ExportFormat } from '../platform/export/types'; import { IStatusProvider } from '../platform/progress/types'; import { generateCellsFromDocument } from './editor-integration/cellFactory'; import { IInteractiveWindowProvider } from './types'; -import { JupyterNotebookView } from '../notebooks/constants'; import { getDisplayPath, getFilePath } from '../platform/common/platform/fs-paths'; +import { chainWithPendingUpdates } from '../kernels/execution/notebookUpdater'; @injectable() export class InteractiveWindowCommandListener implements IDataScienceCommandListener { diff --git a/src/interactive-window/interactiveWindowProvider.ts b/src/interactive-window/interactiveWindowProvider.ts index f0afb996e9c..eca286a785d 100644 --- a/src/interactive-window/interactiveWindowProvider.ts +++ b/src/interactive-window/interactiveWindowProvider.ts @@ -42,7 +42,7 @@ import { IServiceContainer } from '../platform/ioc/types'; import { KernelConnectionMetadata } from '../kernels/types'; import { IEmbedNotebookEditorProvider, INotebookControllerManager, INotebookEditorProvider } from '../notebooks/types'; import { InteractiveWindow } from './interactiveWindow'; -import { JVSC_EXTENSION_ID, NotebookCellScheme } from '../platform/common/constants'; +import { InteractiveWindowView, JVSC_EXTENSION_ID, NotebookCellScheme } from '../platform/common/constants'; import { IInteractiveWindow, IInteractiveWindowDebugger, @@ -56,7 +56,6 @@ import { INotebookExporter } from '../kernels/jupyter/types'; import { IDataScienceErrorHandler } from '../platform/errors/types'; import { IExportDialog } from '../platform/export/types'; import { IVSCodeNotebookController } from '../notebooks/controllers/types'; -import { InteractiveWindowView } from '../notebooks/constants'; import { ICodeGeneratorFactory, IGeneratedCodeStorageFactory } from './editor-integration/types'; import { IInteractiveWindowDebuggingManager } from '../kernels/debugger/types'; import { getResourceType } from '../platform/common/utils'; diff --git a/src/interactive-window/outputs/tracebackFormatter.ts b/src/interactive-window/outputs/tracebackFormatter.ts index 09c432d081b..f0c24b5c48c 100644 --- a/src/interactive-window/outputs/tracebackFormatter.ts +++ b/src/interactive-window/outputs/tracebackFormatter.ts @@ -4,13 +4,13 @@ import { inject, injectable } from 'inversify'; import { NotebookCell, Uri } from 'vscode'; import { ITracebackFormatter } from '../../kernels/types'; -import { InteractiveWindowView } from '../../notebooks/constants'; import { IGeneratedCode, IFileGeneratedCodes, IGeneratedCodeStorageFactory } from '../editor-integration/types'; import { untildify } from '../../platform/common/utils/platform'; import { traceInfoIfCI } from '../../platform/logging'; import { getDisplayPath, getFilePath } from '../../platform/common/platform/fs-paths'; import { IPlatformService } from '../../platform/common/platform/types'; import { stripAnsi } from '../../platform/common/utils/regexp'; +import { InteractiveWindowView } from '../../platform/common/constants'; // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires const _escapeRegExp = require('lodash/escapeRegExp') as typeof import('lodash/escapeRegExp'); // NOSONAR diff --git a/src/kernels/activation.node.ts b/src/kernels/activation.node.ts index 43d05db2d1f..4464b551e47 100644 --- a/src/kernels/activation.node.ts +++ b/src/kernels/activation.node.ts @@ -5,13 +5,13 @@ import { inject, injectable } from 'inversify'; import { NotebookDocument } from 'vscode'; -import { isJupyterNotebook } from '../notebooks/helpers'; import { IExtensionSingleActivationService } from '../platform/activation/types'; import { IPythonExtensionChecker } from '../platform/api/types'; import { IVSCodeNotebook } from '../platform/common/application/types'; import { Telemetry, JupyterDaemonModule } from '../platform/common/constants'; import { IPythonExecutionFactory, IPythonDaemonExecutionService } from '../platform/common/process/types.node'; import { IDisposableRegistry } from '../platform/common/types'; +import { isJupyterNotebook } from '../platform/common/utils'; import { debounceAsync, swallowExceptions } from '../platform/common/utils/decorators'; import { sendTelemetryEvent } from '../telemetry'; import { JupyterInterpreterService } from './jupyter/interpreter/jupyterInterpreterService.node'; diff --git a/src/notebooks/execution/cellDisplayIdTracker.ts b/src/kernels/execution/cellDisplayIdTracker.ts similarity index 97% rename from src/notebooks/execution/cellDisplayIdTracker.ts rename to src/kernels/execution/cellDisplayIdTracker.ts index f044591814f..f529113964a 100644 --- a/src/notebooks/execution/cellDisplayIdTracker.ts +++ b/src/kernels/execution/cellDisplayIdTracker.ts @@ -3,7 +3,7 @@ import { injectable } from 'inversify'; import { NotebookCell, NotebookCellOutput, NotebookDocument, workspace } from 'vscode'; -import { isJupyterNotebook } from '../helpers'; +import { isJupyterNotebook } from '../../platform/common/utils'; @injectable() export class CellOutputDisplayIdTracker { diff --git a/src/notebooks/execution/cellExecution.ts b/src/kernels/execution/cellExecution.ts similarity index 99% rename from src/notebooks/execution/cellExecution.ts rename to src/kernels/execution/cellExecution.ts index da758fbbd35..087fc74da39 100644 --- a/src/notebooks/execution/cellExecution.ts +++ b/src/kernels/execution/cellExecution.ts @@ -24,7 +24,6 @@ import { traceError, traceInfoIfCI, traceWarning } from '../../platform/logging' import { IDisposable } from '../../platform/common/types'; import { createDeferred } from '../../platform/common/utils/async'; import { StopWatch } from '../../platform/common/utils/stopWatch'; -import { NotebookCellStateTracker, traceCellMessage } from '../helpers'; import { sendTelemetryEvent } from '../../telemetry'; import { Telemetry } from '../../webviews/webview-side/common/constants'; import { noop } from '../../platform/common/utils/misc'; @@ -33,6 +32,7 @@ import { isCancellationError } from '../../platform/common/cancellation'; import { activeNotebookCellExecution, CellExecutionMessageHandler } from './cellExecutionMessageHandler'; import { CellExecutionMessageHandlerService } from './cellExecutionMessageHandlerService'; import { IJupyterSession, KernelConnectionMetadata, NotebookCellRunState } from '../../kernels/types'; +import { NotebookCellStateTracker, traceCellMessage } from './helpers'; export class CellExecutionFactory { constructor( diff --git a/src/notebooks/execution/cellExecutionCreator.ts b/src/kernels/execution/cellExecutionCreator.ts similarity index 100% rename from src/notebooks/execution/cellExecutionCreator.ts rename to src/kernels/execution/cellExecutionCreator.ts diff --git a/src/notebooks/execution/cellExecutionMessageHandler.ts b/src/kernels/execution/cellExecutionMessageHandler.ts similarity index 99% rename from src/notebooks/execution/cellExecutionMessageHandler.ts rename to src/kernels/execution/cellExecutionMessageHandler.ts index cd21f352ac9..c0d8ea8c44b 100644 --- a/src/notebooks/execution/cellExecutionMessageHandler.ts +++ b/src/kernels/execution/cellExecutionMessageHandler.ts @@ -32,13 +32,14 @@ import { disposeAllDisposables } from '../../platform/common/helpers'; import { traceError, traceWarning } from '../../platform/logging'; import { RefBool } from '../../platform/common/refBool'; import { IDisposable, IExtensionContext } from '../../platform/common/types'; -import { traceCellMessage, cellOutputToVSCCellOutput, translateCellDisplayOutput, isJupyterNotebook } from '../helpers'; +import { traceCellMessage, cellOutputToVSCCellOutput, translateCellDisplayOutput } from './helpers'; import { formatStreamText, concatMultilineString } from '../../webviews/webview-side/common'; import { swallowExceptions } from '../../platform/common/utils/decorators'; import { noop } from '../../platform/common/utils/misc'; import { ITracebackFormatter } from '../../kernels/types'; import { handleTensorBoardDisplayDataOutput } from './executionHelpers'; import { WIDGET_MIMETYPE } from '../../kernels/ipywidgets-message-coordination/constants'; +import { isJupyterNotebook } from '../../platform/common/utils'; // Helper interface for the set_next_input execute reply payload interface ISetNextInputPayload { diff --git a/src/notebooks/execution/cellExecutionMessageHandlerService.ts b/src/kernels/execution/cellExecutionMessageHandlerService.ts similarity index 100% rename from src/notebooks/execution/cellExecutionMessageHandlerService.ts rename to src/kernels/execution/cellExecutionMessageHandlerService.ts diff --git a/src/notebooks/execution/cellExecutionQueue.ts b/src/kernels/execution/cellExecutionQueue.ts similarity index 99% rename from src/notebooks/execution/cellExecutionQueue.ts rename to src/kernels/execution/cellExecutionQueue.ts index 80b000212f6..1088789f410 100644 --- a/src/notebooks/execution/cellExecutionQueue.ts +++ b/src/kernels/execution/cellExecutionQueue.ts @@ -4,7 +4,7 @@ import { Disposable, EventEmitter, NotebookCell } from 'vscode'; import { traceInfo, traceError } from '../../platform/logging'; import { noop } from '../../platform/common/utils/misc'; -import { traceCellMessage } from '../helpers'; +import { traceCellMessage } from './helpers'; import { CellExecution, CellExecutionFactory } from './cellExecution'; import { IJupyterSession, KernelConnectionMetadata, NotebookCellRunState } from '../../kernels/types'; diff --git a/src/notebooks/execution/executionHelpers.ts b/src/kernels/execution/executionHelpers.ts similarity index 100% rename from src/notebooks/execution/executionHelpers.ts rename to src/kernels/execution/executionHelpers.ts diff --git a/src/notebooks/helpers.ts b/src/kernels/execution/helpers.ts similarity index 90% rename from src/notebooks/helpers.ts rename to src/kernels/execution/helpers.ts index 5e01382cfda..70cc3aa96b6 100644 --- a/src/notebooks/helpers.ts +++ b/src/kernels/execution/helpers.ts @@ -9,106 +9,38 @@ import { NotebookCellOutputItem, NotebookCell, NotebookCellData, - NotebookData, - NotebookDocument, NotebookCellKind, NotebookCellExecutionState, - WorkspaceEdit, - workspace, - TextDocument, - NotebookEdit + NotebookController } from 'vscode'; // eslint-disable-next-line @typescript-eslint/no-require-imports import { KernelMessage } from '@jupyterlab/services'; // eslint-disable-next-line @typescript-eslint/no-require-imports import cloneDeep = require('lodash/cloneDeep'); import fastDeepEqual = require('fast-deep-equal'); -import * as path from '../platform/vscode-path/path'; -import * as uriPath from '../platform/vscode-path/resources'; -import { IDocumentManager } from '../platform/common/application/types'; -import { PYTHON_LANGUAGE } from '../platform/common/constants'; -import { traceInfoIfCI, traceError, traceWarning } from '../platform/logging'; -import { getInterpreterHash } from '../platform/pythonEnvironments/info/interpreter'; -import { sendTelemetryEvent } from '../telemetry'; -import { splitMultilineString, concatMultilineString } from '../webviews/webview-side/common'; -import { Telemetry } from '../webviews/webview-side/common/constants'; +import * as path from '../../platform/vscode-path/path'; +import * as uriPath from '../../platform/vscode-path/resources'; +import { PYTHON_LANGUAGE } from '../../platform/common/constants'; +import { traceInfoIfCI, traceError, traceWarning } from '../../platform/logging'; +import { getInterpreterHash } from '../../platform/pythonEnvironments/info/interpreter'; +import { sendTelemetryEvent } from '../../telemetry'; +import { splitMultilineString, concatMultilineString } from '../../webviews/webview-side/common'; +import { Telemetry } from '../../webviews/webview-side/common/constants'; +import { getOSType, OSType } from '../../platform/common/utils/platform'; +import { createOutputWithErrorMessageForDisplay } from '../../platform/errors/errorUtils'; +import { CellExecutionCreator } from './cellExecutionCreator'; +import { KernelConnectionMetadata } from '../types'; import { isPythonKernelConnection, getInterpreterFromKernelConnectionMetadata, kernelConnectionMetadataHasKernelModel, getKernelRegistrationInfo -} from '../kernels/helpers'; -import { IJupyterKernelSpec, KernelConnectionMetadata } from '../kernels/types'; -import { JupyterNotebookView, InteractiveWindowView } from './constants'; -import { CellOutputMimeTypes } from './types'; -import { getOSType, OSType } from '../platform/common/utils/platform'; +} from '../helpers'; -/** - * Whether this is a Notebook we created/manage/use. - * Remember, there could be other notebooks such as GitHub Issues nb by VS Code. - */ -export function isJupyterNotebook(document: NotebookDocument): boolean; -// eslint-disable-next-line @typescript-eslint/unified-signatures -export function isJupyterNotebook(viewType: string): boolean; -export function isJupyterNotebook(option: NotebookDocument | string) { - if (typeof option === 'string') { - return option === JupyterNotebookView || option === InteractiveWindowView; - } else { - return option.notebookType === JupyterNotebookView || option.notebookType === InteractiveWindowView; - } -} - -export function getNotebookMetadata(document: NotebookDocument | NotebookData): nbformat.INotebookMetadata | undefined { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const notebookContent: undefined | Partial = document.metadata?.custom as any; - // Create a clone. - return JSON.parse(JSON.stringify(notebookContent?.metadata || {})); -} - -export async function updateNotebookDocumentMetadata( - document: NotebookDocument, - editManager: IDocumentManager, - kernelConnection?: KernelConnectionMetadata, - kernelInfo?: Partial -) { - let metadata = getNotebookMetadata(document) || { orig_nbformat: 3 }; - const { changed } = updateNotebookMetadata(metadata, kernelConnection, kernelInfo); - if (changed) { - const edit = new WorkspaceEdit(); - // Create a clone. - const docMetadata = JSON.parse( - JSON.stringify( - (document.metadata as { - custom?: Exclude, 'cells'>; - }) || { custom: {} } - ) - ); - - docMetadata.custom = docMetadata.custom || {}; - docMetadata.custom.metadata = metadata; - edit.set(document.uri, [ - NotebookEdit.updateNotebookMetadata({ - ...(document.metadata || {}), - custom: docMetadata.custom - }) - ]); - await editManager.applyEdit(edit); - } -} - -export function isPythonNotebook(metadata?: nbformat.INotebookMetadata) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const kernelSpec = metadata?.kernelspec as any as Partial | undefined; - if (metadata?.language_info?.name && metadata.language_info.name !== PYTHON_LANGUAGE) { - return false; - } - - if (kernelSpec?.name?.includes(PYTHON_LANGUAGE)) { - return true; - } - - // Valid notebooks will have a language information in the metadata. - return kernelSpec?.language === PYTHON_LANGUAGE || metadata?.language_info?.name === PYTHON_LANGUAGE; +export enum CellOutputMimeTypes { + error = 'application/vnd.code.notebook.error', + stderr = 'application/vnd.code.notebook.stderr', + stdout = 'application/vnd.code.notebook.stdout' } export function createJupyterCellFromVSCNotebookCell( @@ -941,8 +873,26 @@ export function updateNotebookMetadata( return { changed, kernelId }; } -export function getAssociatedJupyterNotebook(document: TextDocument): NotebookDocument | undefined { - return workspace.notebookDocuments.find( - (notebook) => isJupyterNotebook(notebook) && notebook.getCells().some((cell) => cell.document === document) - ); +export async function endCellAndDisplayErrorsInCell( + cell: NotebookCell, + controller: NotebookController, + errorMessage: string, + isCancelled: boolean +) { + const execution = CellExecutionCreator.getOrCreate(cell, controller); + const output = createOutputWithErrorMessageForDisplay(errorMessage); + if (!output) { + if (execution.started) { + execution.end(isCancelled ? undefined : false, cell.executionSummary?.timing?.endTime); + } + return; + } + // Start execution if not already (Cell execution wrapper will ensure it won't start twice) + const started = execution.started; + if (!started) { + execution.start(cell.executionSummary?.timing?.endTime); + execution.executionOrder = cell.executionSummary?.executionOrder; + } + await execution.appendOutput(output); + execution.end(isCancelled ? undefined : false, cell.executionSummary?.timing?.endTime); } diff --git a/src/notebooks/execution/kernelExecution.ts b/src/kernels/execution/kernelExecution.ts similarity index 99% rename from src/notebooks/execution/kernelExecution.ts rename to src/kernels/execution/kernelExecution.ts index 170f6b05417..6da590fccf1 100644 --- a/src/notebooks/execution/kernelExecution.ts +++ b/src/kernels/execution/kernelExecution.ts @@ -24,10 +24,10 @@ import { KernelConnectionMetadata, NotebookCellRunState } from '../../kernels/types'; -import { traceCellMessage } from '../helpers'; +import { traceCellMessage } from './helpers'; import { getDisplayPath } from '../../platform/common/platform/fs-paths'; import { CellExecutionMessageHandlerService } from './cellExecutionMessageHandlerService'; -import { getAssociatedNotebookDocument } from '../../kernels/helpers'; +import { getAssociatedNotebookDocument } from '../helpers'; /** * Separate class that deals just with kernel execution. diff --git a/src/notebooks/execution/notebookUpdater.ts b/src/kernels/execution/notebookUpdater.ts similarity index 100% rename from src/notebooks/execution/notebookUpdater.ts rename to src/kernels/execution/notebookUpdater.ts diff --git a/src/kernels/helpers.ts b/src/kernels/helpers.ts index 18b7c7a5c06..255b7f80a87 100644 --- a/src/kernels/helpers.ts +++ b/src/kernels/helpers.ts @@ -33,9 +33,8 @@ import { fsPathToUri } from '../platform/vscode-path/utils'; import { deserializePythonEnvironment, serializePythonEnvironment } from '../platform/api/pythonApi'; import { JupyterKernelSpec } from './jupyter/jupyterKernelSpec'; import { Resource } from '../platform/common/types'; -import { getResourceType } from '../platform/common/utils'; +import { getResourceType, isPythonNotebook } from '../platform/common/utils'; import { sendTelemetryEvent } from '../telemetry'; -import { isPythonNotebook } from '../notebooks/helpers'; // https://jupyter-client.readthedocs.io/en/stable/kernels.html export const connectionFilePlaceholder = '{connection_file}'; diff --git a/src/kernels/jupyter/jupyterCellOutputMimeTypeTracker.node.ts b/src/kernels/jupyter/jupyterCellOutputMimeTypeTracker.node.ts index b7c3de4f326..792eeb02d8e 100644 --- a/src/kernels/jupyter/jupyterCellOutputMimeTypeTracker.node.ts +++ b/src/kernels/jupyter/jupyterCellOutputMimeTypeTracker.node.ts @@ -10,10 +10,11 @@ import { IExtensionSingleActivationService } from '../../platform/activation/typ import { IVSCodeNotebook } from '../../platform/common/application/types'; import { disposeAllDisposables } from '../../platform/common/helpers'; import { IDisposableRegistry } from '../../platform/common/types'; +import { isJupyterNotebook } from '../../platform/common/utils'; import { captureTelemetry, sendTelemetryEvent } from '../../telemetry'; import { getTelemetrySafeHashedString } from '../../telemetry/helpers'; import { Telemetry } from '../../webviews/webview-side/common/constants'; -import { isJupyterNotebook, createJupyterCellFromVSCNotebookCell } from '../../notebooks/helpers'; +import { createJupyterCellFromVSCNotebookCell } from '../execution/helpers'; // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires const flatten = require('lodash/flatten') as typeof import('lodash/flatten'); diff --git a/src/kernels/jupyter/launcher/serverPreload.node.ts b/src/kernels/jupyter/launcher/serverPreload.node.ts index 133528123ba..cfe5ba3cf01 100644 --- a/src/kernels/jupyter/launcher/serverPreload.node.ts +++ b/src/kernels/jupyter/launcher/serverPreload.node.ts @@ -13,12 +13,12 @@ import { IMemento, WORKSPACE_MEMENTO } from '../../../platform/common/types'; -import { isJupyterNotebook } from '../../../notebooks/helpers'; import { getKernelConnectionLanguage } from '../../helpers'; import { IKernel, IKernelProvider, INotebookProvider } from '../../types'; import { IInteractiveWindowProvider, IInteractiveWindow } from '../../../interactive-window/types'; import { DisplayOptions } from '../../displayOptions'; import { IRawNotebookProvider } from '../../raw/types'; +import { isJupyterNotebook } from '../../../platform/common/utils'; const LastPythonNotebookCreatedKey = 'last-python-notebook-created'; const LastNotebookCreatedKey = 'last-notebook-created'; diff --git a/src/kernels/kernel.base.ts b/src/kernels/kernel.base.ts index 151667ea5e0..a5a4d13adc0 100644 --- a/src/kernels/kernel.base.ts +++ b/src/kernels/kernel.base.ts @@ -58,10 +58,10 @@ import { Cancellation, isCancellationError } from '../platform/common/cancellati import { KernelProgressReporter } from '../platform/progress/kernelProgressReporter'; import { DisplayOptions } from './displayOptions'; import { SilentExecutionErrorOptions } from './helpers'; -import { traceCellMessage } from '../notebooks/helpers'; -import { KernelExecution } from '../notebooks/execution/kernelExecution'; -import { CellOutputDisplayIdTracker } from '../notebooks/execution/cellDisplayIdTracker'; import { IStatusProvider } from '../platform/progress/types'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; +import { traceCellMessage } from './execution/helpers'; +import { KernelExecution } from './execution/kernelExecution'; export abstract class BaseKernel implements IKernel { private readonly disposables: IDisposable[] = []; diff --git a/src/kernels/kernel.node.ts b/src/kernels/kernel.node.ts index 2c9cc0bf737..3a07151daef 100644 --- a/src/kernels/kernel.node.ts +++ b/src/kernels/kernel.node.ts @@ -8,10 +8,8 @@ import { traceInfo, traceError } from '../platform/logging'; import { IFileSystemNode } from '../platform/common/platform/types.node'; import { IPythonExecutionFactory } from '../platform/common/process/types.node'; import { Resource, IConfigurationService, IExtensionContext } from '../platform/common/types'; -import { InteractiveWindowView } from '../notebooks/constants'; import { calculateWorkingDirectory } from '../platform/common/utils.node'; import { CodeSnippets } from '../webviews/webview-side/common/constants'; -import { CellOutputDisplayIdTracker } from '../notebooks/execution/cellDisplayIdTracker'; import { getAssociatedNotebookDocument, isLocalHostConnection, isPythonKernelConnection } from './helpers'; import { expandWorkingDir } from './jupyter/jupyterUtils'; import { @@ -25,6 +23,8 @@ import { AddRunCellHook } from '../platform/common/scriptConstants'; import { IStatusProvider } from '../platform/progress/types'; import { sendTelemetryForPythonKernelExecutable } from './helpers.node'; import { BaseKernel } from './kernel.base'; +import { InteractiveWindowView } from '../platform/common/constants'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; export class Kernel extends BaseKernel { constructor( diff --git a/src/kernels/kernel.web.ts b/src/kernels/kernel.web.ts index bfadbab7cb4..d1a46965bb2 100644 --- a/src/kernels/kernel.web.ts +++ b/src/kernels/kernel.web.ts @@ -7,9 +7,9 @@ import { IApplicationShell, IWorkspaceService } from '../platform/common/applica import { Resource, IConfigurationService, IExtensionContext } from '../platform/common/types'; import { INotebookProvider, ITracebackFormatter, KernelActionSource, KernelConnectionMetadata } from './types'; import { BaseKernel } from './kernel.base'; -import { CellOutputDisplayIdTracker } from '../notebooks/execution/cellDisplayIdTracker'; import { IStatusProvider } from '../platform/progress/types'; -import { InteractiveWindowView } from '../notebooks/constants'; +import { InteractiveWindowView } from '../platform/common/constants'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; import { getAssociatedNotebookDocument } from './helpers'; const addRunCellHook = require('../../pythonFiles/vscode_datascience_helpers/kernel/addRunCellHook.py'); diff --git a/src/kernels/kernelCommandListener.ts b/src/kernels/kernelCommandListener.ts index ea5df0ceffd..179432694e2 100644 --- a/src/kernels/kernelCommandListener.ts +++ b/src/kernels/kernelCommandListener.ts @@ -4,7 +4,6 @@ import { inject, injectable, optional } from 'inversify'; import { ConfigurationTarget, Uri, window, workspace } from 'vscode'; import { IApplicationShell, ICommandManager } from '../platform/common/application/types'; -import { endCellAndDisplayErrorsInCell } from '../platform/errors/errorUtils'; import { traceInfo, traceInfoIfCI } from '../platform/logging'; import { IDisposableRegistry, IConfigurationService, IDataScienceCommandListener } from '../platform/common/types'; import { DataScience } from '../platform/common/utils/localize'; @@ -19,6 +18,7 @@ import { IDataScienceErrorHandler } from '../platform/errors/types'; import { DisplayOptions } from './displayOptions'; import { KernelConnector } from './kernelConnector'; import { getDisplayPath } from '../platform/common/platform/fs-paths'; +import { endCellAndDisplayErrorsInCell } from './execution/helpers'; import { getAssociatedNotebookDocument } from './helpers'; @injectable() diff --git a/src/kernels/kernelCrashMonitor.ts b/src/kernels/kernelCrashMonitor.ts index 2e41a2d5dac..dca6b15e767 100644 --- a/src/kernels/kernelCrashMonitor.ts +++ b/src/kernels/kernelCrashMonitor.ts @@ -9,8 +9,8 @@ import { IApplicationShell } from '../platform/common/application/types'; import { Telemetry } from '../platform/common/constants'; import { IDisposableRegistry } from '../platform/common/types'; import { DataScience } from '../platform/common/utils/localize'; -import { endCellAndDisplayErrorsInCell } from '../platform/errors/errorUtils'; import { sendKernelTelemetryEvent } from '../telemetry/telemetry'; +import { endCellAndDisplayErrorsInCell } from './execution/helpers'; import { getDisplayNameOrNameOfKernelConnection } from './helpers'; import { IKernel, IKernelProvider } from './types'; diff --git a/src/kernels/kernelProvider.node.ts b/src/kernels/kernelProvider.node.ts index 537d2f040ea..6af25603ab5 100644 --- a/src/kernels/kernelProvider.node.ts +++ b/src/kernels/kernelProvider.node.ts @@ -13,12 +13,12 @@ import { IConfigurationService, IExtensionContext } from '../platform/common/types'; -import { InteractiveWindowView } from '../notebooks/constants'; -import { CellOutputDisplayIdTracker } from '../notebooks/execution/cellDisplayIdTracker'; import { Kernel } from './kernel.node'; import { IKernel, INotebookProvider, ITracebackFormatter, KernelOptions } from './types'; import { IStatusProvider } from '../platform/progress/types'; import { BaseKernelProvider } from './kernelProvider.base'; +import { InteractiveWindowView } from '../platform/common/constants'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; @injectable() export class KernelProvider extends BaseKernelProvider { diff --git a/src/kernels/kernelProvider.web.ts b/src/kernels/kernelProvider.web.ts index 96de894995d..aabad22cf49 100644 --- a/src/kernels/kernelProvider.web.ts +++ b/src/kernels/kernelProvider.web.ts @@ -11,12 +11,12 @@ import { IConfigurationService, IExtensionContext } from '../platform/common/types'; -import { InteractiveWindowView } from '../notebooks/constants'; import { Kernel } from './kernel.web'; import { IKernel, INotebookProvider, ITracebackFormatter, KernelOptions } from './types'; import { BaseKernelProvider } from './kernelProvider.base'; -import { CellOutputDisplayIdTracker } from '../notebooks/execution/cellDisplayIdTracker'; import { IStatusProvider } from '../platform/progress/types'; +import { InteractiveWindowView } from '../platform/common/constants'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; @injectable() export class KernelProvider extends BaseKernelProvider { diff --git a/src/kernels/serviceRegistry.node.ts b/src/kernels/serviceRegistry.node.ts index 1db93901638..b3b0fba1224 100644 --- a/src/kernels/serviceRegistry.node.ts +++ b/src/kernels/serviceRegistry.node.ts @@ -51,6 +51,7 @@ import { registerTypes as registerJupyterTypes } from './jupyter/serviceRegistry import { KernelProvider } from './kernelProvider.node'; import { KernelFinder } from './kernelFinder.node'; import { ServerConnectionType } from './jupyter/launcher/serverConnectionType'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; export function registerTypes(serviceManager: IServiceManager, isDevMode: boolean) { serviceManager.addSingleton( @@ -147,4 +148,5 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea ); const rawService = serviceManager.get(IRawNotebookSupportedService); setSharedProperty('rawKernelSupported', rawService.isSupported ? 'true' : 'false'); + serviceManager.addSingleton(CellOutputDisplayIdTracker, CellOutputDisplayIdTracker); } diff --git a/src/kernels/serviceRegistry.web.ts b/src/kernels/serviceRegistry.web.ts index 988f93c8b44..26d154c1a7b 100644 --- a/src/kernels/serviceRegistry.web.ts +++ b/src/kernels/serviceRegistry.web.ts @@ -33,6 +33,7 @@ import { IJupyterVariables, IKernelVariableRequester } from './variables/types'; import { KernelVariables } from './variables/kernelVariables'; import { JupyterVariables } from './variables/jupyterVariables'; import { PythonVariablesRequester } from './variables/pythonVariableRequester'; +import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; @injectable() class RawNotebookSupportedService implements IRawNotebookSupportedService { @@ -97,4 +98,6 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea // Subdirectories registerWidgetTypes(serviceManager, isDevMode); registerJupyterTypes(serviceManager, isDevMode); + + serviceManager.addSingleton(CellOutputDisplayIdTracker, CellOutputDisplayIdTracker); } diff --git a/src/notebooks/constants.ts b/src/notebooks/constants.ts index 8658a623456..d194bed477a 100644 --- a/src/notebooks/constants.ts +++ b/src/notebooks/constants.ts @@ -1,5 +1,2 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - -export const JupyterNotebookView = 'jupyter-notebook'; -export const InteractiveWindowView = 'interactive'; diff --git a/src/notebooks/controllers/noPythonKernelsNotebookController.ts b/src/notebooks/controllers/noPythonKernelsNotebookController.ts index 56b54963d9a..d65bc2ed382 100644 --- a/src/notebooks/controllers/noPythonKernelsNotebookController.ts +++ b/src/notebooks/controllers/noPythonKernelsNotebookController.ts @@ -6,6 +6,7 @@ import { IPythonExtensionChecker } from '../../platform/api/types'; import { IVSCodeNotebook, ICommandManager, IApplicationShell } from '../../platform/common/application/types'; import { disposeAllDisposables } from '../../platform/common/helpers'; import { IDisposable, IDisposableRegistry } from '../../platform/common/types'; +import { getNotebookMetadata, isPythonNotebook } from '../../platform/common/utils'; import { DataScience, Common } from '../../platform/common/utils/localize'; import { noop } from '../../platform/common/utils/misc'; import { sendTelemetryEvent } from '../../telemetry'; @@ -14,7 +15,6 @@ import { Telemetry, PythonExtension } from '../../webviews/webview-side/common/constants'; -import { getNotebookMetadata, isPythonNotebook } from '../helpers'; export class NoPythonKernelsNotebookController implements Disposable { private readonly disposables: IDisposable[] = []; diff --git a/src/notebooks/controllers/notebookControllerManager.ts b/src/notebooks/controllers/notebookControllerManager.ts index 35b1051bf6e..1d29f206151 100644 --- a/src/notebooks/controllers/notebookControllerManager.ts +++ b/src/notebooks/controllers/notebookControllerManager.ts @@ -13,7 +13,7 @@ import { IDocumentManager, IApplicationShell } from '../../platform/common/application/types'; -import { PYTHON_LANGUAGE } from '../../platform/common/constants'; +import { InteractiveWindowView, JupyterNotebookView, PYTHON_LANGUAGE } from '../../platform/common/constants'; import { traceInfoIfCI, traceError, @@ -50,8 +50,6 @@ import { IKernelFinder, isLocalConnection } from '../../kernels/types'; -import { JupyterNotebookView, InteractiveWindowView } from '../constants'; -import { isPythonNotebook, getNotebookMetadata } from '../helpers'; import { INotebookControllerManager } from '../types'; import { KernelFilterService } from './kernelFilter/kernelFilterService'; import { NoPythonKernelsNotebookController } from './noPythonKernelsNotebookController'; @@ -66,7 +64,7 @@ import { getLanguageInNotebookMetadata, isPythonKernelConnection } from '../../kernels/helpers'; -import { getResourceType } from '../../platform/common/utils'; +import { getNotebookMetadata, getResourceType, isPythonNotebook } from '../../platform/common/utils'; import { getTelemetrySafeLanguage } from '../../telemetry/helpers'; import { INotebookMetadata } from '@jupyterlab/nbformat'; import { ServerConnectionType } from '../../kernels/jupyter/launcher/serverConnectionType'; diff --git a/src/notebooks/controllers/remoteSwitcher.ts b/src/notebooks/controllers/remoteSwitcher.ts index eef1ad33506..570dd8ecf9d 100644 --- a/src/notebooks/controllers/remoteSwitcher.ts +++ b/src/notebooks/controllers/remoteSwitcher.ts @@ -15,10 +15,10 @@ import { IDisposable, IDisposableRegistry } from '../../platform/common/types'; import { DataScience } from '../../platform/common/utils/localize'; import { Commands } from '../../webviews/webview-side/common/constants'; import { JupyterServerSelector } from '../../kernels/jupyter/serverSelector'; -import { isJupyterNotebook } from '../helpers'; import { INotebookControllerManager } from '../types'; import { IJupyterServerUriStorage } from '../../kernels/jupyter/types'; import { Settings } from '../../platform/common/constants'; +import { isJupyterNotebook } from '../../platform/common/utils'; @injectable() export class RemoteSwitcher implements IExtensionSingleActivationService { diff --git a/src/notebooks/controllers/vscodeNotebookController.ts b/src/notebooks/controllers/vscodeNotebookController.ts index 9871c19eec0..882ba9216aa 100644 --- a/src/notebooks/controllers/vscodeNotebookController.ts +++ b/src/notebooks/controllers/vscodeNotebookController.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +import type * as nbformat from '@jupyterlab/nbformat'; import { Disposable, EventEmitter, @@ -12,9 +13,11 @@ import { NotebookController, NotebookControllerAffinity, NotebookDocument, + NotebookEdit, NotebookEditor, NotebookRendererScript, - Uri + Uri, + WorkspaceEdit } from 'vscode'; import { IPythonExtensionChecker } from '../../platform/api/types'; import { @@ -24,7 +27,7 @@ import { IDocumentManager, IApplicationShell } from '../../platform/common/application/types'; -import { PYTHON_LANGUAGE } from '../../platform/common/constants'; +import { InteractiveWindowView, PYTHON_LANGUAGE } from '../../platform/common/constants'; import { disposeAllDisposables } from '../../platform/common/helpers'; import { traceInfoIfCI, @@ -53,7 +56,6 @@ import { import { IServiceContainer } from '../../platform/ioc/types'; import { EnvironmentType } from '../../platform/pythonEnvironments/info'; import { Telemetry, Commands } from '../../webviews/webview-side/common/constants'; -import { endCellAndDisplayErrorsInCell } from '../../platform/errors/errorUtils'; import { IDataScienceErrorHandler, WrappedError } from '../../platform/errors/types'; import { IPyWidgetMessages } from '../../platform/messageTypes'; import { NotebookCellLanguageService } from '../../intellisense/cellLanguageService'; @@ -74,17 +76,25 @@ import { LocalKernelSpecConnectionMetadata, PythonKernelConnectionMetadata } from '../../kernels/types'; -import { InteractiveWindowView } from '../constants'; -import { CellExecutionCreator } from '../execution/cellExecutionCreator'; -import { isJupyterNotebook, traceCellMessage, updateNotebookDocumentMetadata } from '../helpers'; import { KernelDeadError } from '../../platform/errors/kernelDeadError'; import { DisplayOptions } from '../../kernels/displayOptions'; -import { sendNotebookOrKernelLanguageTelemetry } from '../../platform/common/utils'; +import { + getNotebookMetadata, + isJupyterNotebook, + sendNotebookOrKernelLanguageTelemetry +} from '../../platform/common/utils'; import { ConsoleForegroundColors, TraceOptions } from '../../platform/logging/types'; import { KernelConnector } from '../../kernels/kernelConnector'; import { IVSCodeNotebookController } from './types'; import { ILocalResourceUriConverter } from '../../kernels/ipywidgets-message-coordination/types'; import { isCancellationError } from '../../platform/common/cancellation'; +import { CellExecutionCreator } from '../../kernels/execution/cellExecutionCreator'; +import { + traceCellMessage, + endCellAndDisplayErrorsInCell, + updateNotebookMetadata +} from '../../kernels/execution/helpers'; +import { KernelMessage } from '@jupyterlab/services'; export class VSCodeNotebookController implements Disposable, IVSCodeNotebookController { private readonly _onNotebookControllerSelected: EventEmitter<{ @@ -635,6 +645,37 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont } } +async function updateNotebookDocumentMetadata( + document: NotebookDocument, + editManager: IDocumentManager, + kernelConnection?: KernelConnectionMetadata, + kernelInfo?: Partial +) { + let metadata = getNotebookMetadata(document) || { orig_nbformat: 3 }; + const { changed } = updateNotebookMetadata(metadata, kernelConnection, kernelInfo); + if (changed) { + const edit = new WorkspaceEdit(); + // Create a clone. + const docMetadata = JSON.parse( + JSON.stringify( + (document.metadata as { + custom?: Exclude, 'cells'>; + }) || { custom: {} } + ) + ); + + docMetadata.custom = docMetadata.custom || {}; + docMetadata.custom.metadata = metadata; + edit.set(document.uri, [ + NotebookEdit.updateNotebookMetadata({ + ...(document.metadata || {}), + custom: docMetadata.custom + }) + ]); + await editManager.applyEdit(edit); + } +} + function getKernelConnectionCategory(kernelConnection: KernelConnectionMetadata) { switch (kernelConnection.kind) { case 'connectToLiveRemoteKernel': diff --git a/src/notebooks/notebookCommandListener.ts b/src/notebooks/notebookCommandListener.ts index 757250a5a23..baee4a2654d 100644 --- a/src/notebooks/notebookCommandListener.ts +++ b/src/notebooks/notebookCommandListener.ts @@ -9,10 +9,10 @@ import { NotebookCellData, NotebookCellKind, NotebookEdit, NotebookRange } from import { IVSCodeNotebook, ICommandManager } from '../platform/common/application/types'; import { IDataScienceCommandListener, IDisposableRegistry } from '../platform/common/types'; import { Commands } from '../webviews/webview-side/common/constants'; -import { chainWithPendingUpdates } from './execution/notebookUpdater'; -import { getNotebookMetadata } from './helpers'; import { noop } from '../platform/common/utils/misc'; import { NotebookCellLanguageService } from '../intellisense/cellLanguageService'; +import { chainWithPendingUpdates } from '../kernels/execution/notebookUpdater'; +import { getNotebookMetadata } from '../platform/common/utils'; @injectable() export class NotebookCommandListener implements IDataScienceCommandListener { diff --git a/src/notebooks/notebookEditorProvider.ts b/src/notebooks/notebookEditorProvider.ts index b7ac620f2a1..1c949cbc00b 100644 --- a/src/notebooks/notebookEditorProvider.ts +++ b/src/notebooks/notebookEditorProvider.ts @@ -6,14 +6,13 @@ import { inject, injectable } from 'inversify'; import { Uri, NotebookData, NotebookCellData, NotebookCellKind } from 'vscode'; import { IVSCodeNotebook } from '../platform/common/application/types'; -import { PYTHON_LANGUAGE } from '../platform/common/constants'; +import { JupyterNotebookView, PYTHON_LANGUAGE } from '../platform/common/constants'; import '../platform/common/extensions'; import { Resource } from '../platform/common/types'; import { getResourceType } from '../platform/common/utils'; import { getComparisonKey } from '../platform/vscode-path/resources'; import { captureTelemetry } from '../telemetry'; import { Telemetry, defaultNotebookFormat } from '../webviews/webview-side/common/constants'; -import { JupyterNotebookView } from './constants'; import { IEmbedNotebookEditorProvider, INotebookEditorProvider } from './types'; import { getOSType, OSType } from '../platform/common/utils/platform'; diff --git a/src/notebooks/notebookUsageTracker.ts b/src/notebooks/notebookUsageTracker.ts index c4e3a851533..c17a2c30dda 100644 --- a/src/notebooks/notebookUsageTracker.ts +++ b/src/notebooks/notebookUsageTracker.ts @@ -6,10 +6,10 @@ import { notebooks, NotebookCellExecutionStateChangeEvent, NotebookDocument, Not import { IExtensionSingleActivationService } from '../platform/activation/types'; import { IVSCodeNotebook } from '../platform/common/application/types'; import { IDisposableRegistry } from '../platform/common/types'; +import { isJupyterNotebook } from '../platform/common/utils'; import { ResourceSet } from '../platform/vscode-path/map'; import { sendTelemetryEvent } from '../telemetry'; import { Telemetry } from '../webviews/webview-side/common/constants'; -import { isJupyterNotebook } from './helpers'; /** * This class tracks opened notebooks & # of executed notebooks. diff --git a/src/notebooks/outputs/tracebackFormatter.ts b/src/notebooks/outputs/tracebackFormatter.ts index 60c122f875f..54797225f21 100644 --- a/src/notebooks/outputs/tracebackFormatter.ts +++ b/src/notebooks/outputs/tracebackFormatter.ts @@ -4,10 +4,10 @@ import { injectable } from 'inversify'; import { NotebookCell } from 'vscode'; import { ITracebackFormatter } from '../../kernels/types'; +import { JupyterNotebookView } from '../../platform/common/constants'; import { getFilePath } from '../../platform/common/platform/fs-paths'; import { DataScience } from '../../platform/common/utils/localize'; import { traceInfoIfCI } from '../../platform/logging'; -import { JupyterNotebookView } from '../constants'; const LineNumberMatchRegex = /(;32m[ ->]*?)(\d+)(.*)/g; @injectable() diff --git a/src/notebooks/serviceRegistry.node.ts b/src/notebooks/serviceRegistry.node.ts index 78c085608ae..e016f42d02a 100644 --- a/src/notebooks/serviceRegistry.node.ts +++ b/src/notebooks/serviceRegistry.node.ts @@ -11,7 +11,6 @@ import { KernelFilterUI } from './controllers/kernelFilter/kernelFilterUI'; import { LiveKernelSwitcher } from './controllers/liveKernelSwitcher'; import { NotebookControllerManager } from './controllers/notebookControllerManager'; import { RemoteSwitcher } from './controllers/remoteSwitcher'; -import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; import { NotebookCommandListener } from './notebookCommandListener'; import { NotebookEditorProvider } from './notebookEditorProvider'; import { ErrorRendererCommunicationHandler } from './outputs/errorRendererComms.node'; @@ -30,7 +29,6 @@ import { NotebookIPyWidgetCoordinator } from './controllers/notebookIPyWidgetCoo export function registerTypes(serviceManager: IServiceManager) { serviceManager.addSingleton(IExtensionSingleActivationService, RemoteSwitcher); - serviceManager.addSingleton(CellOutputDisplayIdTracker, CellOutputDisplayIdTracker); serviceManager.addSingleton( IExtensionSingleActivationService, GitHubIssueCodeLensProvider diff --git a/src/notebooks/serviceRegistry.web.ts b/src/notebooks/serviceRegistry.web.ts index ceaac0738b2..0013447297a 100644 --- a/src/notebooks/serviceRegistry.web.ts +++ b/src/notebooks/serviceRegistry.web.ts @@ -10,7 +10,6 @@ import { KernelFilterUI } from './controllers/kernelFilter/kernelFilterUI'; import { LiveKernelSwitcher } from './controllers/liveKernelSwitcher'; import { NotebookControllerManager } from './controllers/notebookControllerManager'; import { RemoteSwitcher } from './controllers/remoteSwitcher'; -import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker'; import { INotebookControllerManager, INotebookEditorProvider } from './types'; import { NotebookUsageTracker } from './notebookUsageTracker'; import { NotebookEditorProvider } from './notebookEditorProvider'; @@ -21,7 +20,6 @@ import { NotebookIPyWidgetCoordinator } from './controllers/notebookIPyWidgetCoo export function registerTypes(serviceManager: IServiceManager) { serviceManager.addSingleton(IExtensionSingleActivationService, RemoteSwitcher); - serviceManager.addSingleton(CellOutputDisplayIdTracker, CellOutputDisplayIdTracker); serviceManager.addSingleton(INotebookControllerManager, NotebookControllerManager); serviceManager.addSingleton(IExtensionSyncActivationService, KernelFilterUI); serviceManager.addBinding(INotebookControllerManager, IExtensionSyncActivationService); diff --git a/src/notebooks/types.ts b/src/notebooks/types.ts index a9164e04f29..2b5708ed677 100644 --- a/src/notebooks/types.ts +++ b/src/notebooks/types.ts @@ -14,7 +14,7 @@ import { import { Resource } from '../platform/common/types'; import { KernelConnectionMetadata, LiveRemoteKernelConnectionMetadata } from '../kernels/types'; import { IVSCodeNotebookController } from './controllers/types'; -import { InteractiveWindowView, JupyterNotebookView } from './constants'; +import { JupyterNotebookView, InteractiveWindowView } from '../platform/common/constants'; export const INotebookKernelResolver = Symbol('INotebookKernelResolver'); @@ -50,11 +50,6 @@ export interface INotebookControllerManager { serverId?: string ): Promise<{ preferredConnection?: KernelConnectionMetadata; controller?: IVSCodeNotebookController }>; } -export enum CellOutputMimeTypes { - error = 'application/vnd.code.notebook.error', - stderr = 'application/vnd.code.notebook.stderr', - stdout = 'application/vnd.code.notebook.stdout' -} export const INotebookCompletionProvider = Symbol('INotebookCompletionProvider'); diff --git a/src/platform/api/kernelApi.ts b/src/platform/api/kernelApi.ts index e8fb8d8aa43..0d1142221b6 100644 --- a/src/platform/api/kernelApi.ts +++ b/src/platform/api/kernelApi.ts @@ -25,11 +25,10 @@ import { KernelConnectionMetadata, WebSocketData } from './extension'; -import { Telemetry } from '../common/constants'; +import { JupyterNotebookView, Telemetry } from '../common/constants'; import { KernelConnector } from '../../kernels/kernelConnector'; import { DisplayOptions } from '../../kernels/displayOptions'; import { IServiceContainer } from '../ioc/types'; -import { JupyterNotebookView } from '../../notebooks/constants'; import { IExportedKernelServiceFactory } from './types'; @injectable() diff --git a/src/platform/common/activeEditorContext.ts b/src/platform/common/activeEditorContext.ts index 94df392dc66..25301d73a62 100644 --- a/src/platform/common/activeEditorContext.ts +++ b/src/platform/common/activeEditorContext.ts @@ -5,16 +5,16 @@ import { inject, injectable, optional } from 'inversify'; import { NotebookEditor, TextEditor } from 'vscode'; import { IKernel, IKernelProvider } from '../../kernels/types'; -import { getNotebookMetadata, isJupyterNotebook, isPythonNotebook } from '../../notebooks/helpers'; import { IExtensionSingleActivationService } from '../activation/types'; import { ICommandManager, IDocumentManager, IVSCodeNotebook } from './application/types'; import { EditorContexts, PYTHON_LANGUAGE } from './constants'; import { ContextKey } from './contextKey'; import { IDisposable, IDisposableRegistry } from './types'; import { isNotebookCell, noop } from './utils/misc'; -import { InteractiveWindowView, JupyterNotebookView } from '../../notebooks/constants'; +import { InteractiveWindowView, JupyterNotebookView } from '../../platform/common/constants'; import { INotebookControllerManager } from '../../notebooks/types'; import { IInteractiveWindowProvider, IInteractiveWindow } from '../../interactive-window/types'; +import { getNotebookMetadata, isJupyterNotebook, isPythonNotebook } from './utils'; import { getAssociatedNotebookDocument } from '../../kernels/helpers'; @injectable() diff --git a/src/platform/common/constants.ts b/src/platform/common/constants.ts index 9774926991c..7fe579789ae 100644 --- a/src/platform/common/constants.ts +++ b/src/platform/common/constants.ts @@ -1,4 +1,3 @@ -import { JupyterNotebookView } from '../../notebooks/constants'; export const PYTHON_LANGUAGE = 'python'; export const MARKDOWN_LANGUAGE = 'markdown'; export const JUPYTER_LANGUAGE = 'jupyter'; @@ -14,6 +13,8 @@ export const GITHUB_ISSUE_MARKDOWN_FILE = [{ language: MARKDOWN_LANGUAGE, scheme export const InteractiveInputScheme = 'vscode-interactive-input'; export const InteractiveScheme = 'vscode-interactive'; +export const JupyterNotebookView = 'jupyter-notebook'; +export const InteractiveWindowView = 'interactive'; export const NOTEBOOK_SELECTOR = [ { language: PYTHON_LANGUAGE, notebookType: JupyterNotebookView }, diff --git a/src/platform/common/dataScienceSurveyBanner.node.ts b/src/platform/common/dataScienceSurveyBanner.node.ts index d08c85d7144..cbc9381bdaa 100644 --- a/src/platform/common/dataScienceSurveyBanner.node.ts +++ b/src/platform/common/dataScienceSurveyBanner.node.ts @@ -5,7 +5,6 @@ import { inject, injectable } from 'inversify'; import { NotebookCellExecutionState, NotebookCellExecutionStateChangeEvent, UIKind } from 'vscode'; -import { isJupyterNotebook } from '../../notebooks/helpers'; import { IExtensionSingleActivationService } from '../activation/types'; import { IApplicationEnvironment, IApplicationShell, IVSCodeNotebook } from './application/types'; import './extensions'; @@ -21,6 +20,7 @@ import { } from './types'; import * as localize from './utils/localize'; import { MillisecondsInADay } from '../constants.node'; +import { isJupyterNotebook } from './utils'; export enum InsidersNotebookSurveyStateKeys { ShowBanner = 'ShowInsidersNotebookSurveyBanner', diff --git a/src/platform/common/extensionRecommendation.node.ts b/src/platform/common/extensionRecommendation.node.ts index 0a5ed47f245..4326eb133d2 100644 --- a/src/platform/common/extensionRecommendation.node.ts +++ b/src/platform/common/extensionRecommendation.node.ts @@ -16,9 +16,9 @@ import { getLanguageInNotebookMetadata, isPythonKernelConnection } from '../../kernels/helpers'; -import { getNotebookMetadata, isJupyterNotebook } from '../../notebooks/helpers'; import { INotebookControllerManager } from '../../notebooks/types'; import { IVSCodeNotebookController } from '../../notebooks/controllers/types'; +import { getNotebookMetadata, isJupyterNotebook } from './utils'; const mementoKeyToNeverPromptExtensionAgain = 'JVSC_NEVER_PROMPT_EXTENSIONS_LIST'; const knownExtensionsToRecommend = new Map([ diff --git a/src/platform/common/utils.ts b/src/platform/common/utils.ts index 4f5fe90bf6a..230c8c10719 100644 --- a/src/platform/common/utils.ts +++ b/src/platform/common/utils.ts @@ -5,16 +5,23 @@ import type * as nbformat from '@jupyterlab/nbformat'; import * as uriPath from '../../platform/vscode-path/resources'; import { SemVer, parse } from 'semver'; -import { Uri } from 'vscode'; +import { NotebookData, NotebookDocument, TextDocument, Uri, workspace } from 'vscode'; import { sendTelemetryEvent } from '../../telemetry'; import { getTelemetrySafeLanguage } from '../../telemetry/helpers'; import { splitMultilineString } from '../../webviews/webview-side/common'; -import { jupyterLanguageToMonacoLanguageMapping, Telemetry } from './constants'; +import { + InteractiveWindowView, + jupyterLanguageToMonacoLanguageMapping, + JupyterNotebookView, + PYTHON_LANGUAGE, + Telemetry +} from './constants'; import { traceError, traceInfo } from '../logging'; import { ICell } from './types'; import { DataScience } from './utils/localize'; +import { IJupyterKernelSpec } from '../api/extension'; // Can't figure out a better way to do this. Enumerate // the allowed keys of different output formats. @@ -167,3 +174,46 @@ export function sendNotebookOrKernelLanguageTelemetry( language = getTelemetrySafeLanguage(language); sendTelemetryEvent(telemetryEvent, undefined, { language }); } + +/** + * Whether this is a Notebook we created/manage/use. + * Remember, there could be other notebooks such as GitHub Issues nb by VS Code. + */ +export function isJupyterNotebook(document: NotebookDocument): boolean; +// eslint-disable-next-line @typescript-eslint/unified-signatures +export function isJupyterNotebook(viewType: string): boolean; +export function isJupyterNotebook(option: NotebookDocument | string) { + if (typeof option === 'string') { + return option === JupyterNotebookView || option === InteractiveWindowView; + } else { + return option.notebookType === JupyterNotebookView || option.notebookType === InteractiveWindowView; + } +} + +export function getNotebookMetadata(document: NotebookDocument | NotebookData): nbformat.INotebookMetadata | undefined { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const notebookContent: undefined | Partial = document.metadata?.custom as any; + // Create a clone. + return JSON.parse(JSON.stringify(notebookContent?.metadata || {})); +} + +export function getAssociatedJupyterNotebook(document: TextDocument): NotebookDocument | undefined { + return workspace.notebookDocuments.find( + (notebook) => isJupyterNotebook(notebook) && notebook.getCells().some((cell) => cell.document === document) + ); +} + +export function isPythonNotebook(metadata?: nbformat.INotebookMetadata) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const kernelSpec = metadata?.kernelspec as any as Partial | undefined; + if (metadata?.language_info?.name && metadata.language_info.name !== PYTHON_LANGUAGE) { + return false; + } + + if (kernelSpec?.name?.includes(PYTHON_LANGUAGE)) { + return true; + } + + // Valid notebooks will have a language information in the metadata. + return kernelSpec?.language === PYTHON_LANGUAGE || metadata?.language_info?.name === PYTHON_LANGUAGE; +} diff --git a/src/platform/errors/errorUtils.ts b/src/platform/errors/errorUtils.ts index cff4d87815c..cd87bfd7496 100644 --- a/src/platform/errors/errorUtils.ts +++ b/src/platform/errors/errorUtils.ts @@ -1,15 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import { - NotebookCell, - NotebookCellOutput, - NotebookCellOutputItem, - NotebookController, - Uri, - WorkspaceFolder -} from 'vscode'; -import { CellExecutionCreator } from '../../notebooks/execution/cellExecutionCreator'; +import { NotebookCellOutput, NotebookCellOutputItem, Uri, WorkspaceFolder } from 'vscode'; import { getDisplayPath } from '../common/platform/fs-paths'; import { DataScience } from '../common/utils/localize'; import { JupyterConnectError } from './jupyterConnectError'; @@ -575,30 +567,6 @@ function isBuiltInModuleOverwritten( }; } -export async function endCellAndDisplayErrorsInCell( - cell: NotebookCell, - controller: NotebookController, - errorMessage: string, - isCancelled: boolean -) { - const execution = CellExecutionCreator.getOrCreate(cell, controller); - const output = createOutputWithErrorMessageForDisplay(errorMessage); - if (!output) { - if (execution.started) { - execution.end(isCancelled ? undefined : false, cell.executionSummary?.timing?.endTime); - } - return; - } - // Start execution if not already (Cell execution wrapper will ensure it won't start twice) - const started = execution.started; - if (!started) { - execution.start(cell.executionSummary?.timing?.endTime); - execution.executionOrder = cell.executionSummary?.executionOrder; - } - await execution.appendOutput(output); - execution.end(isCancelled ? undefined : false, cell.executionSummary?.timing?.endTime); -} - export function createOutputWithErrorMessageForDisplay(errorMessage: string) { if (!errorMessage) { return; diff --git a/src/platform/interpreter/display/visibilityFilter.node.ts b/src/platform/interpreter/display/visibilityFilter.node.ts index fbf82be6ce6..adfb33f91b7 100644 --- a/src/platform/interpreter/display/visibilityFilter.node.ts +++ b/src/platform/interpreter/display/visibilityFilter.node.ts @@ -3,11 +3,11 @@ import { inject, injectable } from 'inversify'; import { Event, EventEmitter } from 'vscode'; -import { isJupyterNotebook } from '../../../notebooks/helpers'; import { IExtensionSingleActivationService } from '../../activation/types'; import { IInterpreterStatusbarVisibilityFilter, IPythonApiProvider, IPythonExtensionChecker } from '../../api/types'; import { IVSCodeNotebook } from '../../common/application/types'; import { IDisposableRegistry } from '../../common/types'; +import { isJupyterNotebook } from '../../common/utils'; @injectable() export class InterpreterStatusBarVisibility diff --git a/src/telemetry/importTracker.node.ts b/src/telemetry/importTracker.node.ts index b93f9a2eece..a941322961e 100644 --- a/src/telemetry/importTracker.node.ts +++ b/src/telemetry/importTracker.node.ts @@ -8,7 +8,6 @@ import * as path from '../platform/vscode-path/path'; import { NotebookCellExecutionStateChangeEvent, NotebookCellKind, NotebookDocument, TextDocument } from 'vscode'; import { captureTelemetry, sendTelemetryEvent } from '.'; import { splitMultilineString } from '../webviews/webview-side/common'; -import { getAssociatedJupyterNotebook, isJupyterNotebook } from '../notebooks/helpers'; import { IExtensionSingleActivationService } from '../platform/activation/types'; import { IDocumentManager, IVSCodeNotebook } from '../platform/common/application/types'; import { isCI, isTestExecution, PYTHON_LANGUAGE } from '../platform/common/constants'; @@ -18,6 +17,7 @@ import { IDisposable, IDisposableRegistry } from '../platform/common/types'; import { noop } from '../platform/common/utils/misc'; import { EventName } from './constants'; import { getTelemetrySafeHashedString } from './helpers'; +import { getAssociatedJupyterNotebook, isJupyterNotebook } from '../platform/common/utils'; /* Python has a fairly rich import statement. Originally the matching regexp was kept simple for diff --git a/src/test/datascience/extensionRecommendation.unit.test.ts b/src/test/datascience/extensionRecommendation.unit.test.ts index 51d79e94119..1dcc0ce2a2e 100644 --- a/src/test/datascience/extensionRecommendation.unit.test.ts +++ b/src/test/datascience/extensionRecommendation.unit.test.ts @@ -9,11 +9,11 @@ import { disposeAllDisposables } from '../../platform/common/helpers'; import { IDisposable, IExtensions } from '../../platform/common/types'; import { sleep } from '../../platform/common/utils/async'; import { Common } from '../../platform/common/utils/localize'; -import { JupyterNotebookView } from '../../notebooks/constants'; import { VSCodeNotebookController } from '../../notebooks/controllers/vscodeNotebookController'; import { INotebookControllerManager } from '../../notebooks/types'; import { IJupyterKernelSpec } from '../../kernels/types'; import { ExtensionRecommendationService } from '../../platform/common/extensionRecommendation.node'; +import { JupyterNotebookView } from '../../platform/common/constants'; /* eslint-disable @typescript-eslint/no-explicit-any */ suite('DataScience Extension Recommendation', () => { diff --git a/src/test/datascience/interactiveWindow.vscode.common.test.ts b/src/test/datascience/interactiveWindow.vscode.common.test.ts index 115befe2314..ff245aae29c 100644 --- a/src/test/datascience/interactiveWindow.vscode.common.test.ts +++ b/src/test/datascience/interactiveWindow.vscode.common.test.ts @@ -35,7 +35,6 @@ import { waitForExecutionCompletedWithErrors, waitForTextOutput } from './notebook/helper'; -import { translateCellErrorOutput, getTextOutputValue } from '../../notebooks/helpers'; import { INotebookControllerManager } from '../../notebooks/types'; import { IInteractiveWindowProvider } from '../../interactive-window/types'; import { IInterpreterService } from '../../platform/interpreter/contracts'; @@ -43,6 +42,7 @@ import { areInterpreterPathsSame } from '../../platform/pythonEnvironments/info/ import { IS_REMOTE_NATIVE_TEST } from '../constants'; import { sleep } from '../core'; import { IPYTHON_VERSION_CODE } from '../constants'; +import { translateCellErrorOutput, getTextOutputValue } from '../../kernels/execution/helpers'; suite(`Interactive window`, async function () { this.timeout(120_000); diff --git a/src/test/datascience/jupyter/kernels/installationPrompts.vscode.test.ts b/src/test/datascience/jupyter/kernels/installationPrompts.vscode.test.ts index 7988739c3b6..7156912ddf4 100644 --- a/src/test/datascience/jupyter/kernels/installationPrompts.vscode.test.ts +++ b/src/test/datascience/jupyter/kernels/installationPrompts.vscode.test.ts @@ -22,7 +22,6 @@ import { import { createDeferred, sleep } from '../../../../platform/common/utils/async'; import { Common, DataScience } from '../../../../platform/common/utils/localize'; import { InteractiveWindowProvider } from '../../../../interactive-window/interactiveWindowProvider'; -import { hasErrorOutput, translateCellErrorOutput } from '../../../../notebooks/helpers'; import { IInterpreterService } from '../../../../platform/interpreter/contracts'; import { areInterpreterPathsSame, getInterpreterHash } from '../../../../platform/pythonEnvironments/info/interpreter'; import { captureScreenShot, IExtensionTestApi, waitForCondition } from '../../../common.node'; @@ -39,7 +38,6 @@ import { submitFromPythonFileUsingCodeWatcher, uninstallIPyKernel } from '../../helpers.node'; -import { JupyterNotebookView } from '../../../../notebooks/constants'; import { INotebookControllerManager } from '../../../../notebooks/types'; import { BaseKernelError, WrappedError } from '../../../../platform/errors/types'; import { clearInstalledIntoInterpreterMemento } from '../../../../kernels/installer/productInstaller'; @@ -65,10 +63,11 @@ import { import * as kernelSelector from '../../../../notebooks/controllers/kernelSelector'; import { noop } from '../../../core'; import { IInteractiveWindowProvider } from '../../../../interactive-window/types'; -import { Commands } from '../../../../platform/common/constants'; +import { Commands, JupyterNotebookView } from '../../../../platform/common/constants'; import { getDisplayPathFromLocalFile } from '../../../../platform/common/platform/fs-paths.node'; import { getOSType, OSType } from '../../../../platform/common/utils/platform'; import { isUri } from '../../../../platform/common/utils/misc'; +import { hasErrorOutput, translateCellErrorOutput } from '../../../../kernels/execution/helpers'; /* eslint-disable no-invalid-this, , , @typescript-eslint/no-explicit-any */ suite('DataScience Install IPyKernel (slow) (install)', function () { diff --git a/src/test/datascience/notebook/executionService.vscode.test.ts b/src/test/datascience/notebook/executionService.vscode.test.ts index f83ccaed556..2659da2a236 100644 --- a/src/test/datascience/notebook/executionService.vscode.test.ts +++ b/src/test/datascience/notebook/executionService.vscode.test.ts @@ -46,13 +46,13 @@ import { } from './helper.node'; import { openNotebook } from '../helpers.node'; import { noop } from '../../../platform/common/utils/misc'; -import { getTextOutputValue, hasErrorOutput, translateCellErrorOutput } from '../../../notebooks/helpers'; import { getDisplayPath } from '../../../platform/common/platform/fs-paths'; import { ProductNames } from '../../../kernels/installer/productNames'; import { Product } from '../../../kernels/installer/types'; import { IPYTHON_VERSION_CODE, IS_REMOTE_NATIVE_TEST } from '../../constants.node'; import { areInterpreterPathsSame } from '../../../platform/pythonEnvironments/info/interpreter'; import { getOSType, OSType } from '../../../platform/common/utils/platform'; +import { getTextOutputValue, translateCellErrorOutput, hasErrorOutput } from '../../../kernels/execution/helpers'; // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports const expectedPromptMessageSuffix = `requires ${ProductNames.get(Product.ipykernel)!} to be installed.`; diff --git a/src/test/datascience/notebook/helper.ts b/src/test/datascience/notebook/helper.ts index fc3e941ee93..ced73af57da 100644 --- a/src/test/datascience/notebook/helper.ts +++ b/src/test/datascience/notebook/helper.ts @@ -48,9 +48,7 @@ import { DebugProtocol } from 'vscode-debugprotocol'; import { DataScience } from '../../../platform/common/utils/localize'; import { LastSavedNotebookCellLanguage } from '../../../intellisense/cellLanguageService'; import { VSCodeNotebookController } from '../../../notebooks/controllers/vscodeNotebookController'; -import { chainWithPendingUpdates } from '../../../notebooks/execution/notebookUpdater'; -import { NotebookCellStateTracker, hasErrorOutput, getTextOutputValue } from '../../../notebooks/helpers'; -import { INotebookControllerManager, CellOutputMimeTypes, INotebookEditorProvider } from '../../../notebooks/types'; +import { INotebookControllerManager, INotebookEditorProvider } from '../../../notebooks/types'; import { InteractiveControllerIdSuffix } from '../../../notebooks/controllers/notebookControllerManager'; import { IVSCodeNotebookController } from '../../../notebooks/controllers/types'; import { IS_SMOKE_TEST } from '../../constants'; @@ -63,6 +61,13 @@ import { VSCodeNotebook } from '../../../platform/common/application/notebook'; import { IDebuggingManager, IKernelDebugAdapter } from '../../../kernels/debugger/types'; import { PythonKernelCompletionProvider } from '../../../intellisense/pythonKernelCompletionProvider'; import { verifySelectedControllerIsRemoteForRemoteTests } from '../helpers'; +import { + NotebookCellStateTracker, + hasErrorOutput, + CellOutputMimeTypes, + getTextOutputValue +} from '../../../kernels/execution/helpers'; +import { chainWithPendingUpdates } from '../../../kernels/execution/notebookUpdater'; // Running in Conda environments, things can be a little slower. export const defaultNotebookTestTimeout = 60_000; diff --git a/src/test/datascience/notebook/intellisense/completion.vscode.test.ts b/src/test/datascience/notebook/intellisense/completion.vscode.test.ts index ca3633a053f..c3d098fa1aa 100644 --- a/src/test/datascience/notebook/intellisense/completion.vscode.test.ts +++ b/src/test/datascience/notebook/intellisense/completion.vscode.test.ts @@ -9,7 +9,6 @@ import { IVSCodeNotebook } from '../../../../platform/common/application/types'; import { traceInfo } from '../../../../platform/logging'; import { IDisposable } from '../../../../platform/common/types'; import { InteractiveWindowProvider } from '../../../../interactive-window/interactiveWindowProvider'; -import { getTextOutputValue } from '../../../../notebooks/helpers'; import { captureScreenShot, IExtensionTestApi } from '../../../common.node'; import { IS_REMOTE_NATIVE_TEST } from '../../../constants.node'; import { initialize } from '../../../initialize.node'; @@ -26,6 +25,7 @@ import { import { IInteractiveWindowProvider } from '../../../../interactive-window/types'; import { setIntellisenseTimeout } from '../../../../intellisense/pythonKernelCompletionProvider'; import { Settings } from '../../../../platform/common/constants'; +import { getTextOutputValue } from '../../../../kernels/execution/helpers'; /* eslint-disable @typescript-eslint/no-explicit-any, no-invalid-this */ suite('DataScience - VSCode Intellisense Notebook and Interactive Code Completion (slow)', function () { diff --git a/src/test/datascience/notebook/interruptRestart.vscode.test.ts b/src/test/datascience/notebook/interruptRestart.vscode.test.ts index 930a17fd682..123264d8c25 100644 --- a/src/test/datascience/notebook/interruptRestart.vscode.test.ts +++ b/src/test/datascience/notebook/interruptRestart.vscode.test.ts @@ -29,8 +29,8 @@ import { waitForOutputs, clickOKForRestartPrompt } from './helper.node'; -import { hasErrorOutput, NotebookCellStateTracker, getTextOutputValue } from '../../../notebooks/helpers'; import { Commands } from '../../../platform/common/constants'; +import { hasErrorOutput, NotebookCellStateTracker, getTextOutputValue } from '../../../kernels/execution/helpers'; /* eslint-disable @typescript-eslint/no-explicit-any, no-invalid-this, */ /* diff --git a/src/test/datascience/notebook/kernelCrashes.vscode.test.ts b/src/test/datascience/notebook/kernelCrashes.vscode.test.ts index 79f0813673f..ff0134b2929 100644 --- a/src/test/datascience/notebook/kernelCrashes.vscode.test.ts +++ b/src/test/datascience/notebook/kernelCrashes.vscode.test.ts @@ -39,8 +39,8 @@ import { sleep } from '../../core'; import { getDisplayNameOrNameOfKernelConnection } from '../../../kernels/helpers'; import { Uri, window, workspace } from 'vscode'; import { getDisplayPath } from '../../../platform/common/platform/fs-paths'; -import { translateCellErrorOutput } from '../../../notebooks/helpers'; import { INotebookEditorProvider } from '../../../notebooks/types'; +import { translateCellErrorOutput } from '../../../kernels/execution/helpers'; const codeToKillKernel = dedent` import IPython diff --git a/src/test/datascience/notebook/kernelRefresh.vscode.test.ts b/src/test/datascience/notebook/kernelRefresh.vscode.test.ts index b4f6cba9049..4d0f896f668 100644 --- a/src/test/datascience/notebook/kernelRefresh.vscode.test.ts +++ b/src/test/datascience/notebook/kernelRefresh.vscode.test.ts @@ -24,8 +24,8 @@ import { } from './helper.node'; import { IS_CONDA_TEST } from '../../constants.node'; import { EnvironmentType } from '../../../platform/pythonEnvironments/info'; -import { JupyterNotebookView } from '../../../notebooks/constants'; import { INotebookControllerManager } from '../../../notebooks/types'; +import { JupyterNotebookView } from '../../../platform/common/constants'; /* eslint-disable @typescript-eslint/no-explicit-any, no-invalid-this */ suite('DataScience - VSCode Notebook - (Conda Env Detection) (slow)', function () { diff --git a/src/test/datascience/notebook/kernelSelection.vscode.test.ts b/src/test/datascience/notebook/kernelSelection.vscode.test.ts index 84754155297..54421122193 100644 --- a/src/test/datascience/notebook/kernelSelection.vscode.test.ts +++ b/src/test/datascience/notebook/kernelSelection.vscode.test.ts @@ -35,8 +35,8 @@ import { defaultNotebookTestTimeout, createTemporaryNotebookFromFile } from './helper.node'; -import { getTextOutputValue } from '../../../notebooks/helpers'; import { getOSType, OSType } from '../../../platform/common/utils/platform'; +import { getTextOutputValue } from '../../../kernels/execution/helpers'; /* eslint-disable no-invalid-this, , , @typescript-eslint/no-explicit-any */ suite('DataScience - VSCode Notebook - Kernel Selection', function () { diff --git a/src/test/datascience/notebook/outputDisplayOrder.vscode.test.ts b/src/test/datascience/notebook/outputDisplayOrder.vscode.test.ts index 9dd6dcb0cdb..af6e7055adf 100644 --- a/src/test/datascience/notebook/outputDisplayOrder.vscode.test.ts +++ b/src/test/datascience/notebook/outputDisplayOrder.vscode.test.ts @@ -13,7 +13,7 @@ import { closeNotebooksAndCleanUpAfterTests } from './helper.node'; import { Uri, window } from 'vscode'; import { initialize } from '../../initialize.node'; import type * as nbformat from '@jupyterlab/nbformat'; -import { cellOutputToVSCCellOutput } from '../../../notebooks/helpers'; +import { cellOutputToVSCCellOutput } from '../../../kernels/execution/helpers'; /* eslint-disable @typescript-eslint/no-explicit-any, no-invalid-this */ suite('DataScience - VSCode Notebook - (Validate Output order)', function () { diff --git a/src/test/datascience/notebook/updateNotebookMetadata.unit.test.ts b/src/test/datascience/notebook/updateNotebookMetadata.unit.test.ts index 5b5908c206f..d5e91a8df32 100644 --- a/src/test/datascience/notebook/updateNotebookMetadata.unit.test.ts +++ b/src/test/datascience/notebook/updateNotebookMetadata.unit.test.ts @@ -4,8 +4,8 @@ import type * as nbformat from '@jupyterlab/nbformat'; import { assert } from 'chai'; import { Uri } from 'vscode'; +import { updateNotebookMetadata } from '../../../kernels/execution/helpers'; import { IJupyterKernelSpec, KernelConnectionMetadata } from '../../../kernels/types'; -import { updateNotebookMetadata } from '../../../notebooks/helpers'; import { EnvironmentType, PythonEnvironment } from '../../../platform/pythonEnvironments/info'; // Function return type diff --git a/src/test/datascience/plotViewer/plotViewer.vscode.test.ts b/src/test/datascience/plotViewer/plotViewer.vscode.test.ts index 44bd0e935f4..fe010e90991 100644 --- a/src/test/datascience/plotViewer/plotViewer.vscode.test.ts +++ b/src/test/datascience/plotViewer/plotViewer.vscode.test.ts @@ -8,7 +8,6 @@ import * as vscode from 'vscode'; import { IVSCodeNotebook } from '../../../platform/common/application/types'; import { traceInfo } from '../../../platform/logging'; import { IDisposable } from '../../../platform/common/types'; -import { createJupyterCellFromVSCNotebookCell } from '../../../notebooks/helpers'; import { IExtensionTestApi, waitForCondition } from '../../common.node'; import { closeActiveWindows, initialize } from '../../initialize.node'; import { @@ -19,6 +18,7 @@ import { runAllCellsInActiveNotebook, waitForExecutionCompletedSuccessfully } from '../notebook/helper.node'; +import { createJupyterCellFromVSCNotebookCell } from '../../../kernels/execution/helpers'; suite('VSCode Notebook PlotViewer integration - VSCode Notebook', function () { let api: IExtensionTestApi; diff --git a/src/test/initialize.ts b/src/test/initialize.ts index 8beec8b2f44..62278557ee3 100644 --- a/src/test/initialize.ts +++ b/src/test/initialize.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { clearPendingChainedUpdatesForTests } from '../notebooks/execution/notebookUpdater'; +import { clearPendingChainedUpdatesForTests } from '../kernels/execution/notebookUpdater'; import { IExtensionApi } from '../platform/api'; import { disposeAllDisposables } from '../platform/common/helpers'; import { IDisposable } from '../platform/common/types'; diff --git a/src/test/interactive-winndow/generatedCodeStorageManager.unit.test.ts b/src/test/interactive-winndow/generatedCodeStorageManager.unit.test.ts index 679a76b9e2a..450f261a28a 100644 --- a/src/test/interactive-winndow/generatedCodeStorageManager.unit.test.ts +++ b/src/test/interactive-winndow/generatedCodeStorageManager.unit.test.ts @@ -11,9 +11,9 @@ import { } from '../../interactive-window/editor-integration/types'; import { GeneratedCodeStorageManager } from '../../interactive-window/generatedCodeStoreManager'; import { IKernel, IKernelProvider } from '../../kernels/types'; -import { InteractiveWindowView } from '../../notebooks/constants'; import { IVSCodeNotebookController } from '../../notebooks/controllers/types'; import { INotebookControllerManager } from '../../notebooks/types'; +import { InteractiveWindowView } from '../../platform/common/constants'; import { disposeAllDisposables } from '../../platform/common/helpers'; import { IDisposable } from '../../platform/common/types'; import { mockedVSCodeNamespaces } from '../vscode-mock'; diff --git a/src/test/kernels/kernelProvider.node.unit.test.ts b/src/test/kernels/kernelProvider.node.unit.test.ts index d1a42e56217..62940a15e17 100644 --- a/src/test/kernels/kernelProvider.node.unit.test.ts +++ b/src/test/kernels/kernelProvider.node.unit.test.ts @@ -4,12 +4,12 @@ import { assert } from 'chai'; import { anything, instance, mock, when } from 'ts-mockito'; import { EventEmitter, NotebookController, NotebookDocument, Uri } from 'vscode'; +import { CellOutputDisplayIdTracker } from '../../kernels/execution/cellDisplayIdTracker'; import { KernelProvider as NodeKernelProvider } from '../../kernels/kernelProvider.node'; import { IKernelProvider, INotebookProvider, KernelConnectionMetadata, KernelOptions } from '../../kernels/types'; -import { JupyterNotebookView } from '../../notebooks/constants'; -import { CellOutputDisplayIdTracker } from '../../notebooks/execution/cellDisplayIdTracker'; import { IApplicationShell, IVSCodeNotebook, IWorkspaceService } from '../../platform/common/application/types'; import { AsyncDisposableRegistry } from '../../platform/common/asyncDisposableRegistry'; +import { JupyterNotebookView } from '../../platform/common/constants'; import { disposeAllDisposables } from '../../platform/common/helpers'; import { IFileSystemNode } from '../../platform/common/platform/types.node'; import { IPythonExecutionFactory } from '../../platform/common/process/types.node'; diff --git a/src/webviews/extension-side/variablesView/notebookWatcher.ts b/src/webviews/extension-side/variablesView/notebookWatcher.ts index f865ac3966d..21c85a708bc 100644 --- a/src/webviews/extension-side/variablesView/notebookWatcher.ts +++ b/src/webviews/extension-side/variablesView/notebookWatcher.ts @@ -13,14 +13,14 @@ import { } from 'vscode'; import '../../../platform/common/extensions'; import { IKernel, IKernelProvider } from '../../../kernels/types'; -import { JupyterNotebookView } from '../../../notebooks/constants'; -import { isJupyterNotebook } from '../../../notebooks/helpers'; import { IActiveNotebookChangedEvent, INotebookWatcher } from './types'; import { IInteractiveWindowProvider } from '../../../interactive-window/types'; import { IVSCodeNotebook } from '../../../platform/common/application/types'; import { IDisposableRegistry } from '../../../platform/common/types'; import { IDataViewerFactory } from '../dataviewer/types'; import { getAssociatedNotebookDocument } from '../../../kernels/helpers'; +import { JupyterNotebookView } from '../../../platform/common/constants'; +import { isJupyterNotebook } from '../../../platform/common/utils'; type KernelStateEventArgs = { notebook: NotebookDocument;