|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 |
| -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
7 |
| -import { IExtensionManifest, ExtensionKind, ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; |
8 |
| -import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry'; |
9 |
| -import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; |
10 |
| -import { isNonEmptyArray } from 'vs/base/common/arrays'; |
11 |
| -import { IProductService } from 'vs/platform/product/common/productService'; |
| 6 | +import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; |
12 | 7 | import { ILog } from 'vs/workbench/services/extensions/common/extensionPoints';
|
13 | 8 | import { localize } from 'vs/nls';
|
14 | 9 |
|
@@ -39,143 +34,3 @@ export function dedupExtensions(system: IExtensionDescription[], user: IExtensio
|
39 | 34 | result.forEach((value) => r.push(value));
|
40 | 35 | return r;
|
41 | 36 | }
|
42 |
| - |
43 |
| -export class ExtensionKindController2 { |
44 |
| - constructor( |
45 |
| - @IProductService private readonly productService: IProductService, |
46 |
| - @IConfigurationService private readonly configurationService: IConfigurationService, |
47 |
| - ) { |
48 |
| - } |
49 |
| - prefersExecuteOnUI(manifest: IExtensionManifest): boolean { |
50 |
| - const extensionKind = this.getExtensionKind(manifest); |
51 |
| - return (extensionKind.length > 0 && extensionKind[0] === 'ui'); |
52 |
| - } |
53 |
| - |
54 |
| - prefersExecuteOnWorkspace(manifest: IExtensionManifest): boolean { |
55 |
| - const extensionKind = this.getExtensionKind(manifest); |
56 |
| - return (extensionKind.length > 0 && extensionKind[0] === 'workspace'); |
57 |
| - } |
58 |
| - |
59 |
| - prefersExecuteOnWeb(manifest: IExtensionManifest): boolean { |
60 |
| - const extensionKind = this.getExtensionKind(manifest); |
61 |
| - return (extensionKind.length > 0 && extensionKind[0] === 'web'); |
62 |
| - } |
63 |
| - |
64 |
| - canExecuteOnUI(manifest: IExtensionManifest): boolean { |
65 |
| - const extensionKind = this.getExtensionKind(manifest); |
66 |
| - return extensionKind.some(kind => kind === 'ui'); |
67 |
| - } |
68 |
| - |
69 |
| - canExecuteOnWorkspace(manifest: IExtensionManifest): boolean { |
70 |
| - const extensionKind = this.getExtensionKind(manifest); |
71 |
| - return extensionKind.some(kind => kind === 'workspace'); |
72 |
| - } |
73 |
| - |
74 |
| - canExecuteOnWeb(manifest: IExtensionManifest): boolean { |
75 |
| - const extensionKind = this.getExtensionKind(manifest); |
76 |
| - return extensionKind.some(kind => kind === 'web'); |
77 |
| - } |
78 |
| - |
79 |
| - getExtensionKind(manifest: IExtensionManifest): ExtensionKind[] { |
80 |
| - // check in config |
81 |
| - let result = getConfiguredExtensionKind(manifest, this.configurationService); |
82 |
| - if (typeof result !== 'undefined') { |
83 |
| - return toArray(result); |
84 |
| - } |
85 |
| - |
86 |
| - // check product.json |
87 |
| - result = getProductExtensionKind(manifest, this.productService); |
88 |
| - if (typeof result !== 'undefined') { |
89 |
| - return result; |
90 |
| - } |
91 |
| - |
92 |
| - // check the manifest itself |
93 |
| - result = manifest.extensionKind; |
94 |
| - if (typeof result !== 'undefined') { |
95 |
| - return toArray(result); |
96 |
| - } |
97 |
| - |
98 |
| - return deduceExtensionKind(manifest); |
99 |
| - } |
100 |
| -} |
101 |
| - |
102 |
| -export function deduceExtensionKind(manifest: IExtensionManifest): ExtensionKind[] { |
103 |
| - // Not an UI extension if it has main |
104 |
| - if (manifest.main) { |
105 |
| - if (manifest.browser) { |
106 |
| - return ['workspace', 'web']; |
107 |
| - } |
108 |
| - return ['workspace']; |
109 |
| - } |
110 |
| - |
111 |
| - if (manifest.browser) { |
112 |
| - return ['web']; |
113 |
| - } |
114 |
| - |
115 |
| - // Not an UI nor web extension if it has dependencies or an extension pack |
116 |
| - if (isNonEmptyArray(manifest.extensionDependencies) || isNonEmptyArray(manifest.extensionPack)) { |
117 |
| - return ['workspace']; |
118 |
| - } |
119 |
| - |
120 |
| - if (manifest.contributes) { |
121 |
| - // Not an UI nor web extension if it has no ui contributions |
122 |
| - for (const contribution of Object.keys(manifest.contributes)) { |
123 |
| - if (!isUIExtensionPoint(contribution)) { |
124 |
| - return ['workspace']; |
125 |
| - } |
126 |
| - } |
127 |
| - } |
128 |
| - |
129 |
| - return ['ui', 'workspace', 'web']; |
130 |
| -} |
131 |
| - |
132 |
| -let _uiExtensionPoints: Set<string> | null = null; |
133 |
| -function isUIExtensionPoint(extensionPoint: string): boolean { |
134 |
| - if (_uiExtensionPoints === null) { |
135 |
| - const uiExtensionPoints = new Set<string>(); |
136 |
| - ExtensionsRegistry.getExtensionPoints().filter(e => e.defaultExtensionKind !== 'workspace').forEach(e => { |
137 |
| - uiExtensionPoints.add(e.name); |
138 |
| - }); |
139 |
| - _uiExtensionPoints = uiExtensionPoints; |
140 |
| - } |
141 |
| - return _uiExtensionPoints.has(extensionPoint); |
142 |
| -} |
143 |
| - |
144 |
| -let _productExtensionKindsMap: Map<string, ExtensionKind[]> | null = null; |
145 |
| -function getProductExtensionKind(manifest: IExtensionManifest, productService: IProductService): ExtensionKind[] | undefined { |
146 |
| - if (_productExtensionKindsMap === null) { |
147 |
| - const productExtensionKindsMap = new Map<string, ExtensionKind[]>(); |
148 |
| - if (productService.extensionKind) { |
149 |
| - for (const id of Object.keys(productService.extensionKind)) { |
150 |
| - productExtensionKindsMap.set(ExtensionIdentifier.toKey(id), productService.extensionKind[id]); |
151 |
| - } |
152 |
| - } |
153 |
| - _productExtensionKindsMap = productExtensionKindsMap; |
154 |
| - } |
155 |
| - |
156 |
| - const extensionId = getGalleryExtensionId(manifest.publisher, manifest.name); |
157 |
| - return _productExtensionKindsMap.get(ExtensionIdentifier.toKey(extensionId)); |
158 |
| -} |
159 |
| - |
160 |
| -let _configuredExtensionKindsMap: Map<string, ExtensionKind | ExtensionKind[]> | null = null; |
161 |
| -function getConfiguredExtensionKind(manifest: IExtensionManifest, configurationService: IConfigurationService): ExtensionKind | ExtensionKind[] | undefined { |
162 |
| - if (_configuredExtensionKindsMap === null) { |
163 |
| - const configuredExtensionKindsMap = new Map<string, ExtensionKind | ExtensionKind[]>(); |
164 |
| - const configuredExtensionKinds = configurationService.getValue<{ [key: string]: ExtensionKind | ExtensionKind[] }>('remote.extensionKind') || {}; |
165 |
| - for (const id of Object.keys(configuredExtensionKinds)) { |
166 |
| - configuredExtensionKindsMap.set(ExtensionIdentifier.toKey(id), configuredExtensionKinds[id]); |
167 |
| - } |
168 |
| - _configuredExtensionKindsMap = configuredExtensionKindsMap; |
169 |
| - } |
170 |
| - |
171 |
| - const extensionId = getGalleryExtensionId(manifest.publisher, manifest.name); |
172 |
| - return _configuredExtensionKindsMap.get(ExtensionIdentifier.toKey(extensionId)); |
173 |
| -} |
174 |
| - |
175 |
| -function toArray(extensionKind: ExtensionKind | ExtensionKind[]): ExtensionKind[] { |
176 |
| - if (Array.isArray(extensionKind)) { |
177 |
| - return extensionKind; |
178 |
| - } |
179 |
| - return extensionKind === 'ui' ? ['ui', 'workspace'] : [extensionKind]; |
180 |
| -} |
181 |
| - |
0 commit comments