提交 e1ac9a24 编写于 作者: J Johannes Rieken

add ExtensionKind and remoteName propsed APIs, #74188

上级 6326c5d6
......@@ -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
......
......@@ -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 {
......
......@@ -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 {
......@@ -26,6 +28,7 @@ export interface IExtensionContext {
asAbsolutePath(relativePath: string): string;
readonly logPath: string;
executionContext: number;
extensionKind: ExtensionKind;
}
/**
......
......@@ -38,7 +38,9 @@ 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;
......@@ -46,11 +48,9 @@ export class ExtensionMemento implements IExtensionMemento {
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 {
......
......@@ -2319,3 +2319,8 @@ export enum ExtensionExecutionContext {
Local = 1,
Remote = 2
}
export enum ExtensionKind {
UI = 1,
Workspace = 2
}
......@@ -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
});
......@@ -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
......@@ -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
......@@ -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,
......
......@@ -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 {
......@@ -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),
......@@ -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);
......@@ -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
});
});
}
......@@ -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;
}
......
......@@ -197,6 +197,10 @@ 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,
......@@ -204,7 +208,6 @@ export class RemoteExtensionHostClient extends Disposable implements IExtensionH
logLevel: this._logService.getLevel(),
logsLocation: remoteExtensionHostData.extensionHostLogsPath,
autoStart: true,
remoteAuthority: this._initDataProvider.remoteAuthority,
};
return r;
});
......
......@@ -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,
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册