Skip to content

Commit 8630720

Browse files
authored
Fixes microsoft#155179 by implementing DeprecatedExtensionMigratorContribution (microsoft#155318)
* Fixes microsoft#155179 by implementing DeprecatedExtensionMigratorContribution * Fixes CI.
1 parent 05d1f4a commit 8630720

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

build/lib/i18n.resources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@
294294
"name": "vs/workbench/contrib/audioCues",
295295
"project": "vscode-workbench"
296296
},
297+
{
298+
"name": "vs/workbench/contrib/deprecatedExtensionMigrator",
299+
"project": "vscode-workbench"
300+
},
297301
{
298302
"name": "vs/workbench/contrib/offline",
299303
"project": "vscode-workbench"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 { Action } from 'vs/base/common/actions';
7+
import { onUnexpectedError } from 'vs/base/common/errors';
8+
import { isDefined } from 'vs/base/common/types';
9+
import { localize } from 'vs/nls';
10+
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
11+
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
12+
import { IOpenerService } from 'vs/platform/opener/common/opener';
13+
import { Registry } from 'vs/platform/registry/common/platform';
14+
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
15+
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
16+
import { IExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/common/extensions';
17+
import { EnablementState } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
18+
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
19+
20+
class DeprecatedExtensionMigratorContribution {
21+
constructor(
22+
@IConfigurationService private readonly configurationService: IConfigurationService,
23+
@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
24+
@IStorageService private readonly storageService: IStorageService,
25+
@INotificationService private readonly notificationService: INotificationService,
26+
@IOpenerService private readonly openerService: IOpenerService
27+
) {
28+
this.init().catch(onUnexpectedError);
29+
}
30+
31+
private async init(): Promise<void> {
32+
const bracketPairColorizerId = 'coenraads.bracket-pair-colorizer';
33+
34+
await this.extensionsWorkbenchService.queryLocal();
35+
const extension = this.extensionsWorkbenchService.installed.find(e => e.identifier.id === bracketPairColorizerId);
36+
if (
37+
!extension ||
38+
((extension.enablementState !== EnablementState.EnabledGlobally) &&
39+
(extension.enablementState !== EnablementState.EnabledWorkspace))
40+
) {
41+
return;
42+
}
43+
44+
const state = await this.getState();
45+
const disablementLogEntry = state.disablementLog.some(d => d.extensionId === bracketPairColorizerId);
46+
47+
if (disablementLogEntry) {
48+
return;
49+
}
50+
51+
state.disablementLog.push({ extensionId: bracketPairColorizerId, disablementDateTime: new Date().getTime() });
52+
await this.setState(state);
53+
54+
await this.extensionsWorkbenchService.setEnablement(extension, EnablementState.DisabledGlobally);
55+
56+
const nativeBracketPairColorizationEnabledKey = 'editor.bracketPairColorization.enabled';
57+
const bracketPairColorizationEnabled = !!this.configurationService.inspect(nativeBracketPairColorizationEnabledKey).user;
58+
59+
this.notificationService.notify({
60+
message: localize('bracketPairColorizer.notification', "The extension 'Bracket pair Colorizer' got disabled because it was deprecated."),
61+
severity: Severity.Info,
62+
actions: {
63+
primary: [
64+
new Action('', localize('bracketPairColorizer.notification.action.uninstall', "Uninstall Extension"), undefined, undefined, () => {
65+
this.extensionsWorkbenchService.uninstall(extension);
66+
}),
67+
],
68+
secondary: [
69+
!bracketPairColorizationEnabled ? new Action('', localize('bracketPairColorizer.notification.action.enableNative', "Enable Native Bracket Pair Colorization"), undefined, undefined, () => {
70+
this.configurationService.updateValue(nativeBracketPairColorizationEnabledKey, true, ConfigurationTarget.USER);
71+
}) : undefined,
72+
new Action('', localize('bracketPairColorizer.notification.action.showMoreInfo', "More Info"), undefined, undefined, () => {
73+
this.openerService.open('https://github.com/microsoft/vscode/issues/155179');
74+
}),
75+
].filter(isDefined),
76+
}
77+
});
78+
}
79+
80+
private readonly storageKey = 'deprecatedExtensionMigrator.state';
81+
82+
private async getState(): Promise<State> {
83+
const jsonStr = await this.storageService.get(this.storageKey, StorageScope.APPLICATION, '');
84+
if (jsonStr === '') {
85+
return { disablementLog: [] };
86+
}
87+
return JSON.parse(jsonStr) as State;
88+
}
89+
90+
private async setState(state: State): Promise<void> {
91+
const json = JSON.stringify(state);
92+
await this.storageService.store(this.storageKey, json, StorageScope.APPLICATION, StorageTarget.USER);
93+
}
94+
}
95+
96+
interface State {
97+
disablementLog: {
98+
extensionId: string;
99+
disablementDateTime: number;
100+
}[];
101+
}
102+
103+
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DeprecatedExtensionMigratorContribution, LifecyclePhase.Restored);

src/vs/workbench/workbench.common.main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,7 @@ import 'vs/workbench/contrib/list/browser/list.contribution';
349349
// Audio Cues
350350
import 'vs/workbench/contrib/audioCues/browser/audioCues.contribution';
351351

352+
// Deprecated Extension Migrator
353+
import 'vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExtensionMigrator.contribution';
354+
352355
//#endregion

0 commit comments

Comments
 (0)