Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/extensionManagement/electron-browser/extensionManagementServerService.ts
3296 views
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 { localize } from '../../../../nls.js';
7
import { Schemas } from '../../../../base/common/network.js';
8
import { ExtensionInstallLocation, IExtensionManagementServer, IExtensionManagementServerService } from '../common/extensionManagement.js';
9
import { IRemoteAgentService } from '../../remote/common/remoteAgentService.js';
10
import { IChannel } from '../../../../base/parts/ipc/common/ipc.js';
11
import { ISharedProcessService } from '../../../../platform/ipc/electron-browser/services.js';
12
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
13
import { NativeRemoteExtensionManagementService } from './remoteExtensionManagementService.js';
14
import { ILabelService } from '../../../../platform/label/common/label.js';
15
import { IExtension } from '../../../../platform/extensions/common/extensions.js';
16
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
17
import { NativeExtensionManagementService } from './nativeExtensionManagementService.js';
18
import { Disposable } from '../../../../base/common/lifecycle.js';
19
20
export class ExtensionManagementServerService extends Disposable implements IExtensionManagementServerService {
21
22
declare readonly _serviceBrand: undefined;
23
24
readonly localExtensionManagementServer: IExtensionManagementServer;
25
readonly remoteExtensionManagementServer: IExtensionManagementServer | null = null;
26
readonly webExtensionManagementServer: IExtensionManagementServer | null = null;
27
28
constructor(
29
@ISharedProcessService sharedProcessService: ISharedProcessService,
30
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
31
@ILabelService labelService: ILabelService,
32
@IInstantiationService instantiationService: IInstantiationService,
33
) {
34
super();
35
const localExtensionManagementService = this._register(instantiationService.createInstance(NativeExtensionManagementService, sharedProcessService.getChannel('extensions')));
36
this.localExtensionManagementServer = { extensionManagementService: localExtensionManagementService, id: 'local', label: localize('local', "Local") };
37
const remoteAgentConnection = remoteAgentService.getConnection();
38
if (remoteAgentConnection) {
39
const extensionManagementService = instantiationService.createInstance(NativeRemoteExtensionManagementService, remoteAgentConnection.getChannel<IChannel>('extensions'), this.localExtensionManagementServer);
40
this.remoteExtensionManagementServer = {
41
id: 'remote',
42
extensionManagementService,
43
get label() { return labelService.getHostLabel(Schemas.vscodeRemote, remoteAgentConnection.remoteAuthority) || localize('remote', "Remote"); },
44
};
45
}
46
47
}
48
49
getExtensionManagementServer(extension: IExtension): IExtensionManagementServer {
50
if (extension.location.scheme === Schemas.file) {
51
return this.localExtensionManagementServer;
52
}
53
if (this.remoteExtensionManagementServer && extension.location.scheme === Schemas.vscodeRemote) {
54
return this.remoteExtensionManagementServer;
55
}
56
throw new Error(`Invalid Extension ${extension.location}`);
57
}
58
59
getExtensionInstallLocation(extension: IExtension): ExtensionInstallLocation | null {
60
const server = this.getExtensionManagementServer(extension);
61
return server === this.remoteExtensionManagementServer ? ExtensionInstallLocation.Remote : ExtensionInstallLocation.Local;
62
}
63
}
64
65
registerSingleton(IExtensionManagementServerService, ExtensionManagementServerService, InstantiationType.Delayed);
66
67