Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/extensions/common/extensionsUtil.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 { ExtensionIdentifierMap, IExtensionDescription } from '../../../../platform/extensions/common/extensions.js';
7
import { localize } from '../../../../nls.js';
8
import { ILogService } from '../../../../platform/log/common/log.js';
9
import * as semver from '../../../../base/common/semver/semver.js';
10
import { Mutable } from '../../../../base/common/types.js';
11
12
// TODO: @sandy081 merge this with deduping in extensionsScannerService.ts
13
export function dedupExtensions(system: IExtensionDescription[], user: IExtensionDescription[], workspace: IExtensionDescription[], development: IExtensionDescription[], logService: ILogService): IExtensionDescription[] {
14
const result = new ExtensionIdentifierMap<IExtensionDescription>();
15
system.forEach((systemExtension) => {
16
const extension = result.get(systemExtension.identifier);
17
if (extension) {
18
logService.warn(localize('overwritingExtension', "Overwriting extension {0} with {1}.", extension.extensionLocation.fsPath, systemExtension.extensionLocation.fsPath));
19
}
20
result.set(systemExtension.identifier, systemExtension);
21
});
22
user.forEach((userExtension) => {
23
const extension = result.get(userExtension.identifier);
24
if (extension) {
25
if (extension.isBuiltin) {
26
if (semver.gte(extension.version, userExtension.version)) {
27
logService.warn(`Skipping extension ${userExtension.extensionLocation.path} in favour of the builtin extension ${extension.extensionLocation.path}.`);
28
return;
29
}
30
// Overwriting a builtin extension inherits the `isBuiltin` property and it doesn't show a warning
31
(<Mutable<IExtensionDescription>>userExtension).isBuiltin = true;
32
} else {
33
logService.warn(localize('overwritingExtension', "Overwriting extension {0} with {1}.", extension.extensionLocation.fsPath, userExtension.extensionLocation.fsPath));
34
}
35
} else if (userExtension.isBuiltin) {
36
logService.warn(`Skipping obsolete builtin extension ${userExtension.extensionLocation.path}`);
37
return;
38
}
39
result.set(userExtension.identifier, userExtension);
40
});
41
workspace.forEach(workspaceExtension => {
42
const extension = result.get(workspaceExtension.identifier);
43
if (extension) {
44
logService.warn(localize('overwritingWithWorkspaceExtension', "Overwriting {0} with Workspace Extension {1}.", extension.extensionLocation.fsPath, workspaceExtension.extensionLocation.fsPath));
45
}
46
result.set(workspaceExtension.identifier, workspaceExtension);
47
});
48
development.forEach(developedExtension => {
49
logService.info(localize('extensionUnderDevelopment', "Loading development extension at {0}", developedExtension.extensionLocation.fsPath));
50
const extension = result.get(developedExtension.identifier);
51
if (extension) {
52
if (extension.isBuiltin) {
53
// Overwriting a builtin extension inherits the `isBuiltin` property
54
(<Mutable<IExtensionDescription>>developedExtension).isBuiltin = true;
55
}
56
}
57
result.set(developedExtension.identifier, developedExtension);
58
});
59
return Array.from(result.values());
60
}
61
62