diff options
Diffstat (limited to 'src/vs/workbench')
4 files changed, 49 insertions, 18 deletions
diff --git a/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts b/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts index 541ad44093a..e152bd1bc9c 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts @@ -45,7 +45,6 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; -import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { IQuickAccessRegistry, Extensions } from 'vs/platform/quickinput/common/quickAccess'; import { InstallExtensionQuickAccessProvider, ManageExtensionsQuickAccessProvider } from 'vs/workbench/contrib/extensions/browser/extensionsQuickAccess'; import { ExtensionRecommendationsService } from 'vs/workbench/contrib/extensions/browser/extensionRecommendationsService'; @@ -450,15 +449,11 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, id: string) { - const configurationService = accessor.get(IConfigurationService); - const ignoredExtensions = [...configurationService.getValue<string[]>('sync.ignoredExtensions')]; - const index = ignoredExtensions.findIndex(ignoredExtension => areSameExtensions({ id: ignoredExtension }, { id })); - if (index !== -1) { - ignoredExtensions.splice(index, 1); - } else { - ignoredExtensions.push(id); + const extensionsWorkbenchService = accessor.get(IExtensionsWorkbenchService); + const extension = extensionsWorkbenchService.local.find(e => areSameExtensions({ id }, e.identifier)); + if (extension) { + return extensionsWorkbenchService.toggleExtensionIgnoredToSync(extension); } - return configurationService.updateValue('sync.ignoredExtensions', ignoredExtensions.length ? ignoredExtensions : undefined, ConfigurationTarget.USER); } }); diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts b/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts index a08e08da5cd..71f209daca1 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts @@ -808,7 +808,7 @@ export class MenuItemExtensionAction extends ExtensionAction { constructor( private readonly action: IAction, - @IConfigurationService private readonly configurationService: IConfigurationService + @IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService, ) { super(action.id, action.label); } @@ -818,7 +818,7 @@ export class MenuItemExtensionAction extends ExtensionAction { return; } if (this.action.id === TOGGLE_IGNORE_EXTENSION_ACTION_ID) { - this.checked = !this.configurationService.getValue<string[]>('sync.ignoredExtensions').some(id => areSameExtensions({ id }, this.extension!.identifier)); + this.checked = !this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension); } } @@ -2660,7 +2660,8 @@ export class SyncIgnoredIconAction extends ExtensionAction { private static readonly DISABLE_CLASS = `${SyncIgnoredIconAction.ENABLE_CLASS} hide`; constructor( - @IConfigurationService private readonly configurationService: IConfigurationService + @IConfigurationService private readonly configurationService: IConfigurationService, + @IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService, ) { super('extensions.syncignore', '', SyncIgnoredIconAction.DISABLE_CLASS, false); this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectedKeys.includes('sync.ignoredExtensions'))(() => this.update())); @@ -2670,11 +2671,8 @@ export class SyncIgnoredIconAction extends ExtensionAction { update(): void { this.class = SyncIgnoredIconAction.DISABLE_CLASS; - if (this.extension) { - const ignoredExtensions = this.configurationService.getValue<string[]>('sync.ignoredExtensions') || []; - if (ignoredExtensions.some(id => areSameExtensions({ id }, this.extension!.identifier))) { - this.class = SyncIgnoredIconAction.ENABLE_CLASS; - } + if (this.extension && this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension)) { + this.class = SyncIgnoredIconAction.ENABLE_CLASS; } } diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts b/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts index 29f0c58c756..0b6d0a5f6c8 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts @@ -19,7 +19,7 @@ import { import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionManagementServer } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; import { getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, areSameExtensions, getMaliciousExtensionsSet, groupByExtension, ExtensionIdentifierWithVersion } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { URI } from 'vs/base/common/uri'; import { IExtension, ExtensionState, IExtensionsWorkbenchService, AutoUpdateConfigurationKey, AutoCheckUpdatesConfigurationKey } from 'vs/workbench/contrib/extensions/common/extensions'; @@ -37,6 +37,7 @@ import { IExtensionManifest, ExtensionType, IExtension as IPlatformExtension, is import { IModeService } from 'vs/editor/common/services/modeService'; import { IProductService } from 'vs/platform/product/common/productService'; import { asDomUri } from 'vs/base/browser/dom'; +import { getIgnoredExtensions } from 'vs/platform/userDataSync/common/extensionsMerge'; interface IExtensionStateProvider<T> { (extension: Extension): T; @@ -863,6 +864,39 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension }, () => this.extensionService.reinstallFromGallery(toReinstall).then(() => this.local.filter(local => areSameExtensions(local.identifier, extension.identifier))[0])); } + isExtensionIgnoredToSync(extension: IExtension): boolean { + const localExtensions = (this.extensionManagementServerService.localExtensionManagementServer && this.extensionManagementServerService.remoteExtensionManagementServer + ? this.local.filter(i => i.server === this.extensionManagementServerService.localExtensionManagementServer) + : this.local) + .filter(l => !!l.local) + .map(l => l.local!); + + const ignoredExtensions = getIgnoredExtensions(localExtensions, this.configurationService); + return ignoredExtensions.includes(extension.identifier.id.toLowerCase()); + } + + toggleExtensionIgnoredToSync(extension: IExtension): Promise<void> { + const isIgnored = this.isExtensionIgnoredToSync(extension); + const isDefaultIgnored = extension.local?.isMachineScoped; + const id = extension.identifier.id.toLowerCase(); + + // first remove the extension completely from ignored extensions + let currentValue = [...this.configurationService.getValue<string[]>('sync.ignoredExtensions')].map(id => id.toLowerCase()); + currentValue = currentValue.filter(v => v !== id && v !== `-${id}`); + + // If ignored, then add only if it is ignored by default + if (isIgnored && isDefaultIgnored) { + currentValue.push(`-${id}`); + } + + // If asked not to sync, then add only if it is not ignored by default + if (!isIgnored && !isDefaultIgnored) { + currentValue.push(id); + } + + return this.configurationService.updateValue('sync.ignoredExtensions', currentValue.length ? currentValue : undefined, ConfigurationTarget.USER); + } + private installWithProgress<T>(installTask: () => Promise<T>, extensionName?: string): Promise<T> { const title = extensionName ? nls.localize('installing named extension', "Installing '{0}' extension....", extensionName) : nls.localize('installing extension', 'Installing extension....'); return this.progressService.withProgress({ diff --git a/src/vs/workbench/contrib/extensions/common/extensions.ts b/src/vs/workbench/contrib/extensions/common/extensions.ts index fae5943aaf6..6119b8de80c 100644 --- a/src/vs/workbench/contrib/extensions/common/extensions.ts +++ b/src/vs/workbench/contrib/extensions/common/extensions.ts @@ -88,6 +88,10 @@ export interface IExtensionsWorkbenchService { setEnablement(extensions: IExtension | IExtension[], enablementState: EnablementState): Promise<void>; open(extension: IExtension, options?: { sideByside?: boolean, preserveFocus?: boolean, pinned?: boolean }): Promise<any>; checkForUpdates(): Promise<void>; + + // Sync APIs + isExtensionIgnoredToSync(extension: IExtension): boolean; + toggleExtensionIgnoredToSync(extension: IExtension): Promise<void>; } export const ConfigurationKey = 'extensions'; |