UNPKG

@sussudio/platform

Version:

Internal APIs for VS Code's service injection the base services.

109 lines (108 loc) 4.5 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc, d; if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; }; import { distinct } from '@sussudio/base/common/arrays.mjs'; import { IConfigurationService } from '../../configuration/common/configuration.mjs'; import { createDecorator } from '../../instantiation/common/instantiation.mjs'; export const IIgnoredExtensionsManagementService = createDecorator('IIgnoredExtensionsManagementService'); let IgnoredExtensionsManagementService = class IgnoredExtensionsManagementService { configurationService; constructor(configurationService) { this.configurationService = configurationService; } hasToNeverSyncExtension(extensionId) { const configuredIgnoredExtensions = this.getConfiguredIgnoredExtensions(); return configuredIgnoredExtensions.includes(extensionId.toLowerCase()); } hasToAlwaysSyncExtension(extensionId) { const configuredIgnoredExtensions = this.getConfiguredIgnoredExtensions(); return configuredIgnoredExtensions.includes(`-${extensionId.toLowerCase()}`); } updateIgnoredExtensions(ignoredExtensionId, ignore) { // first remove the extension completely from ignored extensions let currentValue = [...this.configurationService.getValue('settingsSync.ignoredExtensions')].map((id) => id.toLowerCase(), ); currentValue = currentValue.filter((v) => v !== ignoredExtensionId && v !== `-${ignoredExtensionId}`); // Add only if ignored if (ignore) { currentValue.push(ignoredExtensionId.toLowerCase()); } return this.configurationService.updateValue( 'settingsSync.ignoredExtensions', currentValue.length ? currentValue : undefined, 2 /* ConfigurationTarget.USER */, ); } updateSynchronizedExtensions(extensionId, sync) { // first remove the extension completely from ignored extensions let currentValue = [...this.configurationService.getValue('settingsSync.ignoredExtensions')].map((id) => id.toLowerCase(), ); currentValue = currentValue.filter((v) => v !== extensionId && v !== `-${extensionId}`); // Add only if synced if (sync) { currentValue.push(`-${extensionId.toLowerCase()}`); } return this.configurationService.updateValue( 'settingsSync.ignoredExtensions', currentValue.length ? currentValue : undefined, 2 /* ConfigurationTarget.USER */, ); } getIgnoredExtensions(installed) { const defaultIgnoredExtensions = installed .filter((i) => i.isMachineScoped) .map((i) => i.identifier.id.toLowerCase()); const value = this.getConfiguredIgnoredExtensions().map((id) => id.toLowerCase()); const added = [], removed = []; if (Array.isArray(value)) { for (const key of value) { if (key.startsWith('-')) { removed.push(key.substring(1)); } else { added.push(key); } } } return distinct([...defaultIgnoredExtensions, ...added].filter((setting) => removed.indexOf(setting) === -1)); } getConfiguredIgnoredExtensions() { let userValue = this.configurationService.inspect('settingsSync.ignoredExtensions').userValue; if (userValue !== undefined) { return userValue; } userValue = this.configurationService.inspect('sync.ignoredExtensions').userValue; if (userValue !== undefined) { return userValue; } return (this.configurationService.getValue('settingsSync.ignoredExtensions') || []).map((id) => id.toLowerCase()); } }; IgnoredExtensionsManagementService = __decorate( [__param(0, IConfigurationService)], IgnoredExtensionsManagementService, ); export { IgnoredExtensionsManagementService };