From 773c398dfce3f30b0933d863d087b54561fafe44 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Wed, 6 May 2020 11:36:04 -0700 Subject: [PATCH] api: implement extension mode api (#95926) (#97081) --- src/vs/vscode.proposed.d.ts | 37 +++++++++++++++++++ .../workbench/api/common/extHost.api.impl.ts | 1 + .../api/common/extHostExtensionService.ts | 12 +++++- src/vs/workbench/api/common/extHostTypes.ts | 24 ++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index f19ca070408..da705cb2bb8 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1742,6 +1742,43 @@ declare module 'vscode' { //#endregion + //#region @connor4312 extension mode: https://github.com/microsoft/vscode/issues/95926 + + /** + * The ExtensionMode is provided on the `ExtensionContext` and indicates the + * mode the specific extension is running in. + */ + export enum ExtensionMode { + /** + * The extension is installed normally (for example, from the marketplace + * or VSIX) in VS Code. + */ + Release = 1, + + /** + * The extension is running from an `--extensionDevelopmentPath` provided + * when launching VS Code. + */ + Development = 2, + + /** + * The extension is running from an `--extensionDevelopmentPath` and + * the extension host is running unit tests. + */ + Test = 3, + } + + export interface ExtensionContext { + /** + * The mode the extension is running in. This is specific to the current + * extension. One extension may be in `ExtensionMode.Development` while + * other extensions in the host run in `ExtensionMode.Release`. + */ + readonly extensionMode: ExtensionMode; + } + + //#endregion + //#region https://github.com/microsoft/vscode/issues/39441 export interface CompletionItem { diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index ca1efcab306..a4736ede416 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -993,6 +993,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I EvaluatableExpression: extHostTypes.EvaluatableExpression, EventEmitter: Emitter, ExtensionKind: extHostTypes.ExtensionKind, + ExtensionMode: extHostTypes.ExtensionMode, CustomExecution: extHostTypes.CustomExecution, CustomExecution2: extHostTypes.CustomExecution, FileChangeType: extHostTypes.FileChangeType, diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts index d9ceacee59b..d4ab9840abf 100644 --- a/src/vs/workbench/api/common/extHostExtensionService.ts +++ b/src/vs/workbench/api/common/extHostExtensionService.ts @@ -16,7 +16,7 @@ import { ExtHostConfiguration, IExtHostConfiguration } from 'vs/workbench/api/co import { ActivatedExtension, EmptyExtension, ExtensionActivationReason, ExtensionActivationTimes, ExtensionActivationTimesBuilder, ExtensionsActivator, IExtensionAPI, IExtensionModule, HostExtension, ExtensionActivationTimesFragment } from 'vs/workbench/api/common/extHostExtensionActivator'; import { ExtHostStorage, IExtHostStorage } from 'vs/workbench/api/common/extHostStorage'; import { ExtHostWorkspace, IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; -import { ExtensionActivationError } from 'vs/workbench/services/extensions/common/extensions'; +import { ExtensionActivationError, checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions'; import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry'; import { CancellationTokenSource } from 'vs/base/common/cancellation'; import * as errors from 'vs/base/common/errors'; @@ -25,7 +25,7 @@ import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensio import { Schemas } from 'vs/base/common/network'; import { VSBuffer } from 'vs/base/common/buffer'; import { ExtensionMemento } from 'vs/workbench/api/common/extHostMemento'; -import { RemoteAuthorityResolverError } from 'vs/workbench/api/common/extHostTypes'; +import { RemoteAuthorityResolverError, ExtensionMode } from 'vs/workbench/api/common/extHostTypes'; import { ResolvedAuthority, ResolvedOptions, RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService'; @@ -358,8 +358,12 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio const globalState = new ExtensionMemento(extensionDescription.identifier.value, true, this._storage); const workspaceState = new ExtensionMemento(extensionDescription.identifier.value, false, this._storage); + const extensionMode = extensionDescription.isUnderDevelopment + ? (this._initData.environment.extensionTestsLocationURI ? ExtensionMode.Test : ExtensionMode.Development) + : ExtensionMode.Release; this._logService.trace(`ExtensionService#loadExtensionContext ${extensionDescription.identifier.value}`); + return Promise.all([ globalState.whenReady, workspaceState.whenReady, @@ -376,6 +380,10 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio get globalStoragePath() { return that._storagePath.globalValue(extensionDescription); }, asAbsolutePath(relativePath: string) { return path.join(extensionDescription.extensionLocation.fsPath, relativePath); }, get logPath() { return path.join(that._initData.logsLocation.fsPath, extensionDescription.identifier.value); }, + get extensionMode() { + checkProposedApiEnabled(extensionDescription); + return extensionMode; + }, get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); } }); }); diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 89aad35b2a5..4894d276e46 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -2742,3 +2742,27 @@ export class TimelineItem implements vscode.TimelineItem { } //#endregion Timeline + +//#region ExtensionContext + +export enum ExtensionMode { + /** + * The extension is installed normally (for example, from the marketplace + * or VSIX) in VS Code. + */ + Release = 1, + + /** + * The extension is running from an `--extensionDevelopmentPath` provided + * when launching VS Code. + */ + Development = 2, + + /** + * The extension is running from an `--extensionDevelopmentPath` and + * the extension host is running unit tests. + */ + Test = 3, +} + +//#endregion ExtensionContext -- GitLab