Skip to content

Commit f1aa092

Browse files
committed
adopt ext host service world, add dummy implementations for some services
1 parent 171d9cb commit f1aa092

8 files changed

Lines changed: 137 additions & 1949 deletions

File tree

src/vs/workbench/api/common/extHostExtensionService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
385385
try {
386386
activationTimesBuilder.activateCallStart();
387387
logService.trace(`ExtensionService#_callActivateOptional ${extensionId.value}`);
388-
const activateResult: Promise<IExtensionAPI> = extensionModule.activate.apply(global, [context]);
388+
const scope = typeof global === 'object' ? global : self; //todo@joh not so nice
389+
const activateResult: Promise<IExtensionAPI> = extensionModule.activate.apply(scope, [context]);
389390
activationTimesBuilder.activateCallStop();
390391

391392
activationTimesBuilder.activateResolveStart();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { createApiFactoryAndRegisterActors } from 'vs/workbench/api/common/extHost.api.impl';
7+
import { ExtensionActivationTimesBuilder } from 'vs/workbench/api/common/extHostExtensionActivator';
8+
import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
9+
import { endsWith } from 'vs/base/common/strings';
10+
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
11+
12+
export class ExtHostExtensionService extends AbstractExtHostExtensionService {
13+
14+
protected async _beforeAlmostReadyToRunExtensions(): Promise<void> {
15+
// initialize API and register actors
16+
const factory = this._instaService.invokeFunction(createApiFactoryAndRegisterActors);
17+
18+
// globally define the vscode module and share that for all extensions
19+
// todo@joh have an instance per extension, not a shared one....
20+
const sharedApiInstance = factory(nullExtensionDescription, this._registry, await this._extHostConfiguration.getConfigProvider());
21+
define('vscode', sharedApiInstance);
22+
}
23+
24+
protected _loadCommonJSModule<T>(modulePath: string, activationTimesBuilder: ExtensionActivationTimesBuilder): Promise<T> {
25+
// fake commonjs world
26+
const module = { exports: {} };
27+
//@ts-ignore
28+
self['module'] = module;
29+
//@ts-ignore
30+
self['exports'] = module.exports;
31+
// that's improper but might help extensions that aren't author correctly
32+
// @ts-ignore
33+
self['window'] = self;
34+
35+
try {
36+
activationTimesBuilder.codeLoadingStart();
37+
// import the single (!) script, make sure it's a JS-file
38+
const suffix = '.js';
39+
if (endsWith(modulePath, suffix)) {
40+
importScripts(modulePath);
41+
} else {
42+
importScripts(modulePath + suffix);
43+
}
44+
} finally {
45+
activationTimesBuilder.codeLoadingStop();
46+
}
47+
48+
// return what it exported
49+
return Promise.resolve(module.exports as T);
50+
}
51+
52+
public async $setRemoteEnvironment(env: { [key: string]: string | null }): Promise<void> {
53+
throw new Error('Not supported');
54+
}
55+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
7+
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
8+
9+
export class ExtensionStoragePaths implements IExtensionStoragePaths {
10+
11+
readonly _serviceBrand: undefined;
12+
13+
readonly whenReady: Promise<any> = Promise.resolve();
14+
15+
//todo@joh -> this isn't proper but also hard to get right...
16+
workspaceValue(_extension: IExtensionDescription): string | undefined {
17+
return '';
18+
}
19+
20+
globalValue(_extension: IExtensionDescription): string {
21+
return '';
22+
}
23+
}

src/vs/workbench/services/extensions/worker/extHost.api.impl.ts

Lines changed: 0 additions & 964 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
7+
import { IExtHostOutputService, ExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
8+
import { IExtHostWorkspace, ExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
9+
import { IExtHostDecorations, ExtHostDecorations } from 'vs/workbench/api/common/extHostDecorations';
10+
import { IExtHostConfiguration, ExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration';
11+
import { IExtHostCommands, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
12+
import { IExtHostDocumentsAndEditors, ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
13+
import { IExtHostTerminalService } from 'vs/workbench/api/common/extHostTerminalService';
14+
import { IExtHostTask } from 'vs/workbench/api/common/extHostTask';
15+
import { IExtHostDebugService } from 'vs/workbench/api/common/extHostDebugService';
16+
import { IExtHostSearch } from 'vs/workbench/api/common/extHostSearch';
17+
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
18+
import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
19+
import { IExtHostStorage, ExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
20+
import { ExtHostExtensionService } from 'vs/workbench/api/worker/extHostExtensionService';
21+
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
22+
import { ExtensionStoragePaths } from 'vs/workbench/api/worker/extHostStoragePaths';
23+
24+
25+
// register singleton services
26+
registerSingleton(IExtHostOutputService, ExtHostOutputService);
27+
registerSingleton(IExtHostWorkspace, ExtHostWorkspace);
28+
registerSingleton(IExtHostDecorations, ExtHostDecorations);
29+
registerSingleton(IExtHostConfiguration, ExtHostConfiguration);
30+
registerSingleton(IExtHostCommands, ExtHostCommands);
31+
registerSingleton(IExtHostDocumentsAndEditors, ExtHostDocumentsAndEditors);
32+
registerSingleton(IExtHostStorage, ExtHostStorage);
33+
registerSingleton(IExtensionStoragePaths, ExtensionStoragePaths);
34+
registerSingleton(IExtHostExtensionService, ExtHostExtensionService);
35+
36+
// register services that only throw errors
37+
function NotImplementedProxy<T>(name: ServiceIdentifier<T>): { new(): T } {
38+
return <any>class {
39+
constructor() {
40+
return new Proxy({}, {
41+
get(_target: any, prop: any) {
42+
throw new Error(`Not Implemented: ${name}->${String(prop)}`);
43+
}
44+
});
45+
}
46+
};
47+
}
48+
registerSingleton(IExtHostTerminalService, class extends NotImplementedProxy(IExtHostTerminalService) { });
49+
registerSingleton(IExtHostTask, class extends NotImplementedProxy(IExtHostTask) { });
50+
registerSingleton(IExtHostDebugService, class extends NotImplementedProxy(IExtHostDebugService) { });
51+
registerSingleton(IExtHostSearch, class extends NotImplementedProxy(IExtHostSearch) { });

0 commit comments

Comments
 (0)