From 49385ce7e60dcd37bbc7464bceb11ec64446449d Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Tue, 21 Jun 2022 11:34:34 -0700 Subject: [PATCH] extension activation and context registration (#10520) * Extension activation and context * update telemetry * :lipstick: --- TELEMETRY.md | 2 +- .../installer/productInstaller.node.ts | 59 +------------------ src/platform/activation/types.ts | 14 ----- src/test/datascience/datascience.unit.test.ts | 2 +- .../{ => activation}/activationManager.ts | 2 +- .../{ => activation}/globalActivation.ts | 26 ++++---- .../workspaceActivation.node.ts | 24 ++++---- .../{ => context}/activeEditorContext.ts | 24 ++++---- .../{ => context}/amlContext.node.ts | 4 +- .../extension-side/serviceRegistry.node.ts | 10 ++-- .../extension-side/serviceRegistry.web.ts | 6 +- 11 files changed, 53 insertions(+), 120 deletions(-) rename src/webviews/extension-side/{ => activation}/activationManager.ts (96%) rename src/webviews/extension-side/{ => activation}/globalActivation.ts (85%) rename src/webviews/extension-side/{ => activation}/workspaceActivation.node.ts (83%) rename src/webviews/extension-side/{ => context}/activeEditorContext.ts (93%) rename src/webviews/extension-side/{ => context}/amlContext.node.ts (79%) diff --git a/TELEMETRY.md b/TELEMETRY.md index d1971fbe9af..6a3e729c9e2 100644 --- a/TELEMETRY.md +++ b/TELEMETRY.md @@ -8335,7 +8335,7 @@ No properties for event ## Locations Used -[src/webviews/extension-side/globalActivation.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/webviews/extension-side/globalActivation.ts) +[src/webviews/extension-side/activation/globalActivation.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/webviews/extension-side/activation/globalActivation.ts) ```typescript resultSettings[k] = currentValue; } diff --git a/src/kernels/installer/productInstaller.node.ts b/src/kernels/installer/productInstaller.node.ts index b9d956adf9e..eb3d77120dd 100644 --- a/src/kernels/installer/productInstaller.node.ts +++ b/src/kernels/installer/productInstaller.node.ts @@ -1,7 +1,7 @@ /* eslint-disable max-classes-per-file */ import { inject, injectable, named } from 'inversify'; -import * as semver from 'semver'; + import { CancellationTokenSource, Event, EventEmitter, Memento, Uri } from 'vscode'; import { ProductNames } from './productNames'; import { @@ -12,7 +12,6 @@ import { IProductService, ModuleInstallFlags, Product, - ProductInstallStatus, ProductType } from './types'; import { logValue, traceDecoratorVerbose } from '../../platform/logging'; @@ -112,62 +111,6 @@ abstract class BaseInstaller { }); } - /** - * - * @param product A product which supports SemVer versioning. - * @param semVerRequirement A SemVer version requirement. - * @param resource A URI or a PythonEnvironment. - */ - public async isProductVersionCompatible( - product: Product, - semVerRequirement: string, - interpreter: PythonEnvironment - ): Promise { - const version = await this.getProductSemVer(product, interpreter); - if (!version) { - return ProductInstallStatus.NotInstalled; - } - if (semver.satisfies(version, semVerRequirement)) { - return ProductInstallStatus.Installed; - } - return ProductInstallStatus.NeedsUpgrade; - } - - /** - * - * @param product A product which supports SemVer versioning. - * @param resource A URI or a PythonEnvironment. - */ - private async getProductSemVer(product: Product, interpreter: PythonEnvironment): Promise { - const executableName = this.getExecutableNameFromSettings(product, undefined); - const isModule = this.isExecutableAModule(product, undefined); - - let version; - if (isModule) { - const pythonProcess = await this.serviceContainer - .get(IPythonExecutionFactory) - .createActivatedEnvironment({ interpreter, allowEnvironmentFetchExceptions: true }); - const args = ['-c', `import ${executableName}; print(${executableName}.__version__)`]; - const result = await pythonProcess.exec(args, { mergeStdOutErr: true }); - version = result.stdout.trim(); - } else { - const process = await this.serviceContainer - .get(IProcessServiceFactory) - .create(undefined); - const result = await process.exec(executableName, ['--version'], { mergeStdOutErr: true }); - version = result.stdout.trim(); - } - if (!version) { - return null; - } - try { - return semver.coerce(version); - } catch (e) { - traceError(`Unable to parse version ${version} for product ${product}: `, e); - return null; - } - } - @traceDecoratorVerbose('Checking if product is installed') public async isInstalled(product: Product, @logValue('path') interpreter: PythonEnvironment): Promise { const executableName = this.getExecutableNameFromSettings(product, undefined); diff --git a/src/platform/activation/types.ts b/src/platform/activation/types.ts index 2d8427bf59a..c7d8501f30e 100644 --- a/src/platform/activation/types.ts +++ b/src/platform/activation/types.ts @@ -27,20 +27,6 @@ export interface IExtensionActivationManager extends IDisposable { activate(): Promise; } -export const IDownloadChannelRule = Symbol('IDownloadChannelRule'); -export enum PlatformName { - Windows32Bit = 'win-x86', - Windows64Bit = 'win-x64', - Mac64Bit = 'osx-x64', - Linux64Bit = 'linux-x64' -} -export const IPlatformData = Symbol('IPlatformData'); -export interface IPlatformData { - readonly platformName: PlatformName; - readonly engineDllName: string; - readonly engineExecutableName: string; -} - export const IExtensionSingleActivationService = Symbol('IExtensionSingleActivationService'); /** * Classes implementing this interface will have their `activate` methods diff --git a/src/test/datascience/datascience.unit.test.ts b/src/test/datascience/datascience.unit.test.ts index cace32623c5..67326747fa1 100644 --- a/src/test/datascience/datascience.unit.test.ts +++ b/src/test/datascience/datascience.unit.test.ts @@ -13,7 +13,7 @@ import { WorkspaceService } from '../../platform/common/application/workspace.no import { JupyterSettings } from '../../platform/common/configSettings'; import { ConfigurationService } from '../../platform/common/configuration/service.node'; import { IConfigurationService, IWatchableJupyterSettings } from '../../platform/common/types'; -import { GlobalActivation } from '../../webviews/extension-side/globalActivation'; +import { GlobalActivation } from '../../webviews/extension-side/activation/globalActivation'; import { DataScienceCodeLensProvider } from '../../interactive-window/editor-integration/codelensprovider'; import { RawNotebookSupportedService } from '../../kernels/raw/session/rawNotebookSupportedService.node'; import { IDataScienceCodeLensProvider } from '../../interactive-window/editor-integration/types'; diff --git a/src/webviews/extension-side/activationManager.ts b/src/webviews/extension-side/activation/activationManager.ts similarity index 96% rename from src/webviews/extension-side/activationManager.ts rename to src/webviews/extension-side/activation/activationManager.ts index beb685708cd..e895964b2ef 100644 --- a/src/webviews/extension-side/activationManager.ts +++ b/src/webviews/extension-side/activation/activationManager.ts @@ -8,7 +8,7 @@ import { IExtensionActivationManager, IExtensionSingleActivationService, IExtensionSyncActivationService -} from '../../platform/activation/types'; +} from '../../../platform/activation/types'; @injectable() export class ExtensionActivationManager implements IExtensionActivationManager { diff --git a/src/webviews/extension-side/globalActivation.ts b/src/webviews/extension-side/activation/globalActivation.ts similarity index 85% rename from src/webviews/extension-side/globalActivation.ts rename to src/webviews/extension-side/activation/globalActivation.ts index cea4e3c8313..318e0b7440c 100644 --- a/src/webviews/extension-side/globalActivation.ts +++ b/src/webviews/extension-side/activation/globalActivation.ts @@ -4,25 +4,25 @@ import type { JSONObject } from '@lumino/coreutils'; import { inject, injectable, multiInject, optional } from 'inversify'; import * as vscode from 'vscode'; -import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../platform/common/application/types'; -import { PYTHON_FILE_ANY_SCHEME, PYTHON_LANGUAGE } from '../../platform/common/constants'; -import { ContextKey } from '../../platform/common/contextKey'; -import '../../platform/common/extensions'; +import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../platform/common/application/types'; +import { PYTHON_FILE_ANY_SCHEME, PYTHON_LANGUAGE } from '../../../platform/common/constants'; +import { ContextKey } from '../../../platform/common/contextKey'; +import '../../../platform/common/extensions'; import { IConfigurationService, IDataScienceCommandListener, IDisposable, IDisposableRegistry, IExtensionContext -} from '../../platform/common/types'; -import { debounceAsync, swallowExceptions } from '../../platform/common/utils/decorators'; -import { noop } from '../../platform/common/utils/misc'; -import { sendTelemetryEvent } from '../../telemetry'; -import { EditorContexts, Telemetry } from '../../platform/common/constants'; -import { IExtensionSingleActivationService } from '../../platform/activation/types'; -import { IDataScienceCodeLensProvider } from '../../interactive-window/editor-integration/types'; -import { IRawNotebookSupportedService } from '../../kernels/raw/types'; -import { hasCells } from '../../interactive-window/editor-integration/cellFactory'; +} from '../../../platform/common/types'; +import { debounceAsync, swallowExceptions } from '../../../platform/common/utils/decorators'; +import { noop } from '../../../platform/common/utils/misc'; +import { sendTelemetryEvent } from '../../../telemetry'; +import { EditorContexts, Telemetry } from '../../../platform/common/constants'; +import { IExtensionSingleActivationService } from '../../../platform/activation/types'; +import { IDataScienceCodeLensProvider } from '../../../interactive-window/editor-integration/types'; +import { IRawNotebookSupportedService } from '../../../kernels/raw/types'; +import { hasCells } from '../../../interactive-window/editor-integration/cellFactory'; @injectable() export class GlobalActivation implements IExtensionSingleActivationService { diff --git a/src/webviews/extension-side/workspaceActivation.node.ts b/src/webviews/extension-side/activation/workspaceActivation.node.ts similarity index 83% rename from src/webviews/extension-side/workspaceActivation.node.ts rename to src/webviews/extension-side/activation/workspaceActivation.node.ts index 6628d0ebdf9..30fa9cd847b 100644 --- a/src/webviews/extension-side/workspaceActivation.node.ts +++ b/src/webviews/extension-side/activation/workspaceActivation.node.ts @@ -1,15 +1,19 @@ import { inject, injectable } from 'inversify'; import { TextDocument } from 'vscode'; -import { sendActivationTelemetry } from '../../telemetry/envFileTelemetry.node'; -import { IPythonExtensionChecker } from '../../platform/api/types'; -import { IWorkspaceService, IActiveResourceService, IDocumentManager } from '../../platform/common/application/types'; -import { PYTHON_LANGUAGE } from '../../platform/common/constants'; -import { IFileSystemNode } from '../../platform/common/platform/types.node'; -import { IDisposable, Resource } from '../../platform/common/types'; -import { Deferred } from '../../platform/common/utils/async'; -import { IInterpreterService } from '../../platform/interpreter/contracts'; -import { traceDecoratorError } from '../../platform/logging'; -import { IExtensionSingleActivationService } from '../../platform/activation/types'; +import { sendActivationTelemetry } from '../../../telemetry/envFileTelemetry.node'; +import { IPythonExtensionChecker } from '../../../platform/api/types'; +import { + IWorkspaceService, + IActiveResourceService, + IDocumentManager +} from '../../../platform/common/application/types'; +import { PYTHON_LANGUAGE } from '../../../platform/common/constants'; +import { IFileSystemNode } from '../../../platform/common/platform/types.node'; +import { IDisposable, Resource } from '../../../platform/common/types'; +import { Deferred } from '../../../platform/common/utils/async'; +import { IInterpreterService } from '../../../platform/interpreter/contracts'; +import { traceDecoratorError } from '../../../platform/logging'; +import { IExtensionSingleActivationService } from '../../../platform/activation/types'; @injectable() export class WorkspaceActivation implements IExtensionSingleActivationService { diff --git a/src/webviews/extension-side/activeEditorContext.ts b/src/webviews/extension-side/context/activeEditorContext.ts similarity index 93% rename from src/webviews/extension-side/activeEditorContext.ts rename to src/webviews/extension-side/context/activeEditorContext.ts index ed28376c074..7da02484dcf 100644 --- a/src/webviews/extension-side/activeEditorContext.ts +++ b/src/webviews/extension-side/context/activeEditorContext.ts @@ -4,18 +4,18 @@ 'use strict'; import { inject, injectable, optional } from 'inversify'; import { NotebookEditor, TextEditor } from 'vscode'; -import { IKernel, IKernelProvider } from '../../kernels/types'; -import { IExtensionSingleActivationService } from '../../platform/activation/types'; -import { ICommandManager, IDocumentManager, IVSCodeNotebook } from '../../platform/common/application/types'; -import { EditorContexts, PYTHON_LANGUAGE } from '../../platform/common/constants'; -import { ContextKey } from '../../platform/common/contextKey'; -import { IDisposable, IDisposableRegistry } from '../../platform/common/types'; -import { isNotebookCell, noop } from '../../platform/common/utils/misc'; -import { InteractiveWindowView, JupyterNotebookView } from '../../platform/common/constants'; -import { INotebookControllerManager } from '../../notebooks/types'; -import { IInteractiveWindowProvider, IInteractiveWindow } from '../../interactive-window/types'; -import { getNotebookMetadata, isJupyterNotebook, isPythonNotebook } from '../../platform/common/utils'; -import { getAssociatedNotebookDocument } from '../../kernels/helpers'; +import { IKernel, IKernelProvider } from '../../../kernels/types'; +import { IExtensionSingleActivationService } from '../../../platform/activation/types'; +import { ICommandManager, IDocumentManager, IVSCodeNotebook } from '../../../platform/common/application/types'; +import { EditorContexts, PYTHON_LANGUAGE } from '../../../platform/common/constants'; +import { ContextKey } from '../../../platform/common/contextKey'; +import { IDisposable, IDisposableRegistry } from '../../../platform/common/types'; +import { isNotebookCell, noop } from '../../../platform/common/utils/misc'; +import { InteractiveWindowView, JupyterNotebookView } from '../../../platform/common/constants'; +import { INotebookControllerManager } from '../../../notebooks/types'; +import { IInteractiveWindowProvider, IInteractiveWindow } from '../../../interactive-window/types'; +import { getNotebookMetadata, isJupyterNotebook, isPythonNotebook } from '../../../platform/common/utils'; +import { getAssociatedNotebookDocument } from '../../../kernels/helpers'; @injectable() export class ActiveEditorContextService implements IExtensionSingleActivationService, IDisposable { diff --git a/src/webviews/extension-side/amlContext.node.ts b/src/webviews/extension-side/context/amlContext.node.ts similarity index 79% rename from src/webviews/extension-side/amlContext.node.ts rename to src/webviews/extension-side/context/amlContext.node.ts index aeedb4347c6..8372f076f93 100644 --- a/src/webviews/extension-side/amlContext.node.ts +++ b/src/webviews/extension-side/context/amlContext.node.ts @@ -3,8 +3,8 @@ import { injectable } from 'inversify'; import { env } from 'vscode'; -import { IExtensionSingleActivationService } from '../../platform/activation/types'; -import { setSharedProperty } from '../../telemetry'; +import { IExtensionSingleActivationService } from '../../../platform/activation/types'; +import { setSharedProperty } from '../../../telemetry'; const amlComputeRemoteName = 'amlext'; diff --git a/src/webviews/extension-side/serviceRegistry.node.ts b/src/webviews/extension-side/serviceRegistry.node.ts index 8c0b92a398c..1395b439e40 100644 --- a/src/webviews/extension-side/serviceRegistry.node.ts +++ b/src/webviews/extension-side/serviceRegistry.node.ts @@ -41,15 +41,15 @@ import { DataViewerFactory } from './dataviewer/dataViewerFactory'; import { NotebookWatcher } from './variablesView/notebookWatcher'; import { ExtensionSideRenderer, IExtensionSideRenderer } from './renderer'; import { ExtensionRecommendationService } from './extensionRecommendation.node'; -import { ActiveEditorContextService } from './activeEditorContext'; -import { AmlComputeContext } from './amlContext.node'; +import { ActiveEditorContextService } from './context/activeEditorContext'; +import { AmlComputeContext } from './context/amlContext.node'; import { IImportTracker, ImportTracker } from './importTracker.node'; -import { GlobalActivation } from './globalActivation'; +import { GlobalActivation } from './activation/globalActivation'; import { JupyterKernelServiceFactory } from './api/kernelApi'; import { IExportedKernelServiceFactory } from './api/api'; import { ApiAccessService } from './api/apiAccessService'; -import { WorkspaceActivation } from './workspaceActivation.node'; -import { ExtensionActivationManager } from './activationManager'; +import { WorkspaceActivation } from './activation/workspaceActivation.node'; +import { ExtensionActivationManager } from './activation/activationManager'; import { DataScienceSurveyBanner, ISurveyBanner } from './survey/dataScienceSurveyBanner.node'; export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) { diff --git a/src/webviews/extension-side/serviceRegistry.web.ts b/src/webviews/extension-side/serviceRegistry.web.ts index aeaa3de2553..0b83adea9da 100644 --- a/src/webviews/extension-side/serviceRegistry.web.ts +++ b/src/webviews/extension-side/serviceRegistry.web.ts @@ -23,15 +23,15 @@ import { CommandRegistry as ExportCommandRegistry } from './import-export/comman import { NotebookWatcher } from './variablesView/notebookWatcher'; import { DataViewerFactory } from './dataviewer/dataViewerFactory'; import { ExtensionSideRenderer, IExtensionSideRenderer } from './renderer'; -import { ActiveEditorContextService } from './activeEditorContext'; -import { GlobalActivation } from './globalActivation'; +import { ActiveEditorContextService } from './context/activeEditorContext'; +import { GlobalActivation } from './activation/globalActivation'; import { DataViewer } from './dataviewer/dataViewer'; import { INotebookExporter } from '../../kernels/jupyter/types'; import { JupyterExporter } from './import-export/jupyterExporter'; import { JupyterKernelServiceFactory } from './api/kernelApi'; import { IExportedKernelServiceFactory } from './api/api'; import { ApiAccessService } from './api/apiAccessService'; -import { ExtensionActivationManager } from './activationManager'; +import { ExtensionActivationManager } from './activation/activationManager'; export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) { serviceManager.addSingleton(IExtensionSingleActivationService, GlobalActivation);