Skip to content

Commit

Permalink
add ExtensionKind and remoteName propsed APIs, #74188
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 20, 2019
1 parent 6326c5d commit e1ac9a2
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 23 deletions.
48 changes: 44 additions & 4 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,58 @@
declare module 'vscode' {

//#region Joh - ExecutionContext

// THIS is a deprecated proposal
export enum ExtensionExecutionContext {
Local = 1,
Remote = 2
}
export interface ExtensionContext {
executionContext: ExtensionExecutionContext;
}
//#endregion

//#region Joh - ExtensionKind, vscode.env.remoteKind

/**
* In a remote window the extension kind describes if an extension
* runs where the UI (window) runs or if an extension runs remotely.
*/
export enum ExtensionKind {

/**
* Extension runs where the UI runs.
*/
UI = 1,

/**
* Extension runs where the remote extension host runs.
*/
Workspace = 2
}

export interface ExtensionContext {

/**
* Describes the context in which this extension is executed, e.g.
* a Node.js-context on the same machine or on a remote machine
* The extension kind describes if an extension runs where the UI runs
* or if an extension runs where the remote extension host runs. The extension kind
* if defined in the `package.json` file of extensions but can also be refined
* via the the `remote.extensionKind`-setting. When no remote extension host exists,
* the value is [`ExtensionKind.UI`](#ExtensionKind.UI).
*/
executionContext: ExtensionExecutionContext;
extensionKind: ExtensionKind;
}

export namespace env {
/**
* The name of a remote. Defined by extensions, popular samples are `wsl` for the Windows
* Subsystem for Linux or `ssh` for remotes using a secure shell.
*
* *Note* that the value is `undefined` when there is no remote extension host but that the
* value is defined in all extension hosts (local and remote) in case a remote extension host
* exists. Use [`ExtensionContext#extensionKind`](#ExtensionContext.extensionKind) to know if
* a specific extension runs remote or not.
*/
export const remoteName: string | undefined;
}

//#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface IInitData {
logLevel: LogLevel;
logsLocation: URI;
autoStart: boolean;
remoteAuthority?: string | null;
remote: { isRemote: boolean; authority: string | undefined; };
}

export interface IConfigurationInitData extends IConfigurationData {
Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/api/common/extHostExtensionActivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { ExtensionActivationError, MissingDependencyError } from 'vs/workbench/services/extensions/common/extensions';
import { ExtensionKind } from 'vs/workbench/api/common/extHostTypes';

const NO_OP_VOID_PROMISE = Promise.resolve<void>(undefined);

export interface IExtensionMemento {
get<T>(key: string): T | undefined;
get<T>(key: string, defaultValue: T): T;
update(key: string, value: any): Promise<boolean>;
update(key: string, value: any): Promise<void>;
}

export interface IExtensionContext {
Expand All @@ -26,6 +28,7 @@ export interface IExtensionContext {
asAbsolutePath(relativePath: string): string;
readonly logPath: string;
executionContext: number;
extensionKind: ExtensionKind;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/api/common/extHostMemento.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ export class ExtensionMemento implements IExtensionMemento {
return this._init;
}

get<T>(key: string, defaultValue: T): T {
get<T>(key: string): T | undefined;
get<T>(key: string, defaultValue: T): T;
get<T>(key: string, defaultValue?: T): T {
let value = this._value[key];
if (typeof value === 'undefined') {
value = defaultValue;
}
return value;
}

update(key: string, value: any): Promise<boolean> {
update(key: string, value: any): Promise<void> {
this._value[key] = value;
return this._storage
.setValue(this._shared, this._id, this._value)
.then(() => true);
return this._storage.setValue(this._shared, this._id, this._value);
}

dispose(): void {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2319,3 +2319,8 @@ export enum ExtensionExecutionContext {
Local = 1,
Remote = 2
}

export enum ExtensionKind {
UI = 1,
Workspace = 2
}
21 changes: 17 additions & 4 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ export function createApiFactory(
const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, new ExtHostOutputService(LogOutputChannelFactory, initData.logsLocation, rpcProtocol));
rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage);
if (initData.remoteAuthority) {
if (initData.remote.authority) {
extHostTask.registerTaskSystem(Schemas.vscodeRemote, {
scheme: Schemas.vscodeRemote,
authority: initData.remoteAuthority,
authority: initData.remote.authority,
platform: process.platform
});

Expand All @@ -150,7 +150,7 @@ export function createApiFactory(
const extHostLanguages = new ExtHostLanguages(rpcProtocol, extHostDocuments);

// Register an output channel for exthost log
const outputChannelName = initData.remoteAuthority ? nls.localize('remote extension host Log', "Remote Extension Host") : nls.localize('extension host Log', "Extension Host");
const outputChannelName = initData.remote.isRemote ? nls.localize('remote extension host Log', "Remote Extension Host") : nls.localize('extension host Log', "Extension Host");
extHostOutputService.createOutputChannelFromLogFile(outputChannelName, extHostLogService.logFile);

// Register API-ish commands
Expand Down Expand Up @@ -258,12 +258,24 @@ export function createApiFactory(
return extHostTerminalService.getDefaultShell(configProvider);
},
openExternal(uri: URI) {
return extHostWindow.openUri(uri, { allowTunneling: !!initData.remoteAuthority });
return extHostWindow.openUri(uri, { allowTunneling: !!initData.remote.isRemote });
},
get webviewResourceRoot() {
checkProposedApiEnabled(extension);
return initData.environment.webviewResourceRoot;
},
get remoteName() {
checkProposedApiEnabled(extension);
if (!initData.remote.authority) {
return undefined;
}
const pos = initData.remote.authority.indexOf('+');
if (pos < 0) {
// funky? bad authority?
return initData.remote.authority;
}
return initData.remote.authority.substr(0, pos);
}
};
if (!initData.environment.extensionTestsLocationURI) {
// allow to patch env-function when running tests
Expand Down Expand Up @@ -824,6 +836,7 @@ export function createApiFactory(
EndOfLine: extHostTypes.EndOfLine,
EventEmitter: Emitter,
ExtensionExecutionContext: extHostTypes.ExtensionExecutionContext,
ExtensionKind: extHostTypes.ExtensionKind,
CustomExecution: extHostTypes.CustomExecution,
FileChangeType: extHostTypes.FileChangeType,
FileSystemError: extHostTypes.FileSystemError,
Expand Down
11 changes: 6 additions & 5 deletions src/vs/workbench/api/node/extHostExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { withNullAsUndefined } from 'vs/base/common/types';
import { VSBuffer } from 'vs/base/common/buffer';
import { ExtensionMemento } from 'vs/workbench/api/common/extHostMemento';
import { ExtensionStoragePaths } from 'vs/workbench/api/node/extHostStoragePaths';
import { RemoteAuthorityResolverError, ExtensionExecutionContext } from 'vs/workbench/api/common/extHostTypes';
import { RemoteAuthorityResolverError, ExtensionExecutionContext, ExtensionKind } from 'vs/workbench/api/common/extHostTypes';
import { IURITransformer } from 'vs/base/common/uriIpc';

interface ITestRunner {
Expand Down Expand Up @@ -153,7 +153,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
const extensionPaths = await this.getExtensionPathIndex();
NodeModuleRequireInterceptor.INSTANCE.register(new VSCodeNodeModuleFactory(this._extensionApiFactory, extensionPaths, this._registry, configProvider));
NodeModuleRequireInterceptor.INSTANCE.register(new KeytarNodeModuleFactory(this._extHostContext.getProxy(MainContext.MainThreadKeytar), this._environment));
if (this._initData.remoteAuthority) {
if (this._initData.remote.isRemote) {
NodeModuleRequireInterceptor.INSTANCE.register(new OpenNodeModuleFactory(
this._extHostContext.getProxy(MainContext.MainThreadWindow),
this._extHostContext.getProxy(MainContext.MainThreadTelemetry),
Expand Down Expand Up @@ -340,7 +340,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
});
}

private _loadExtensionContext(extensionDescription: IExtensionDescription): Promise<IExtensionContext> {
private _loadExtensionContext(extensionDescription: IExtensionDescription): Promise<vscode.ExtensionContext> {

const globalState = new ExtensionMemento(extensionDescription.identifier.value, true, this._storage);
const workspaceState = new ExtensionMemento(extensionDescription.identifier.value, false, this._storage);
Expand All @@ -361,7 +361,8 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
globalStoragePath: this._storagePath.globalValue(extensionDescription),
asAbsolutePath: (relativePath: string) => { return path.join(extensionDescription.extensionLocation.fsPath, relativePath); },
logPath: that._extHostLogService.getLogDirectory(extensionDescription.identifier),
executionContext: this._initData.remoteAuthority ? ExtensionExecutionContext.Remote : ExtensionExecutionContext.Local
executionContext: this._initData.remote.isRemote ? ExtensionExecutionContext.Remote : ExtensionExecutionContext.Local,
extensionKind: this._initData.remote.isRemote ? ExtensionKind.Workspace : ExtensionKind.UI
});
});
}
Expand Down Expand Up @@ -562,7 +563,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
// messages to the main process, we delay the exit() by some time
setTimeout(() => {
// If extension tests are running, give the exit code to the renderer
if (this._initData.remoteAuthority && !!this._initData.environment.extensionTestsLocationURI) {
if (this._initData.remote.isRemote && !!this._initData.environment.extensionTestsLocationURI) {
this._mainThreadExtensionsProxy.$onExtensionHostExit(code);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,17 @@ export class RemoteExtensionHostClient extends Disposable implements IExtensionH
id: workspace.id,
name: this._labelService.getWorkspaceLabel(workspace)
},
remote: {
isRemote: true,
authority: this._initDataProvider.remoteAuthority
},
resolvedExtensions: resolvedExtensions,
hostExtensions: hostExtensions,
extensions: remoteExtensionHostData.extensions,
telemetryInfo,
logLevel: this._logService.getLevel(),
logsLocation: remoteExtensionHostData.extensionHostLogsPath,
autoStart: true,
remoteAuthority: this._initDataProvider.remoteAuthority,
};
return r;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ export class ExtensionHostProcessWorker implements IExtensionHostStarter {
name: this._labelService.getWorkspaceLabel(workspace),
isUntitled: workspace.configuration ? isEqualOrParent(workspace.configuration, this._environmentService.untitledWorkspacesHome) : false
},
remote: {
authority: this._environmentService.configuration.remoteAuthority,
isRemote: false
},
resolvedExtensions: [],
hostExtensions: [],
extensions: extensionDescriptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ export async function startExtensionHostProcess(): Promise<void> {

// Attempt to load uri transformer
let uriTransformer: IURITransformer | null = null;
if (initData.remoteAuthority && args.uriTransformerPath) {
if (initData.remote.authority && args.uriTransformerPath) {
try {
const rawURITransformerFactory = <any>require.__$__nodeRequire(args.uriTransformerPath);
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(initData.remoteAuthority);
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(initData.remote.authority);
uriTransformer = new URITransformer(rawURITransformer);
} catch (e) {
console.error(e);
Expand Down

0 comments on commit e1ac9a2

Please sign in to comment.