extensionsUtil.ts 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
import { getGalleryExtensionId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { isNonEmptyArray } from 'vs/base/common/arrays';
10
import product from 'vs/platform/product/node/product';
11

12
export function isUIExtension(manifest: IExtensionManifest, uiContributions: string[], configurationService: IConfigurationService): boolean {
13
	const extensionId = getGalleryExtensionId(manifest.publisher, manifest.name);
14 15
	const extensionKind = getExtensionKind(manifest, configurationService);
	switch (extensionKind) {
16 17 18
		case 'ui': return true;
		case 'workspace': return false;
		default: {
19
			// Tagged as UI extension in product
20 21 22
			if (isNonEmptyArray(product.uiExtensions) && product.uiExtensions.some(id => areSameExtensions({ id }, { id: extensionId }))) {
				return true;
			}
23
			// Not an UI extension if it has main
24 25 26
			if (manifest.main) {
				return false;
			}
27 28 29 30
			// Not an UI extension if it has dependencies or an extension pack
			if (isNonEmptyArray(manifest.extensionDependencies) || isNonEmptyArray(manifest.extensionPack)) {
				return false;
			}
31
			if (manifest.contributes) {
32
				// Not an UI extension if it has no ui contributions
33 34 35
				if (!uiContributions.length || Object.keys(manifest.contributes).some(contribution => uiContributions.indexOf(contribution) === -1)) {
					return false;
				}
36 37 38 39 40
			}
			return true;
		}
	}
}
41 42 43

function getExtensionKind(manifest: IExtensionManifest, configurationService: IConfigurationService): string | undefined {
	const extensionId = getGalleryExtensionId(manifest.publisher, manifest.name);
44
	const configuredExtensionKinds = configurationService.getValue<{ [key: string]: string }>('remote.extensionKind') || {};
45 46 47 48 49 50 51
	for (const id of Object.keys(configuredExtensionKinds)) {
		if (areSameExtensions({ id: extensionId }, { id })) {
			return configuredExtensionKinds[id];
		}
	}
	return manifest.extensionKind;
}