Skip to content

Commit c547705

Browse files
committed
Remove old enable / disable commands
1 parent b3876fe commit c547705

File tree

3 files changed

+61
-86
lines changed

3 files changed

+61
-86
lines changed

client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"url": "https://github.com/Microsoft/vscode-eslint/issues"
1515
},
1616
"engines": {
17-
"vscode": "^1.43.0"
17+
"vscode": "^1.50.0"
1818
},
1919
"devDependencies": {
20-
"@types/vscode": "1.43.0"
20+
"@types/vscode": "1.50.0"
2121
},
2222
"dependencies": {
2323
"vscode-languageclient": "7.0.0-next.6"

client/src/extension.ts

Lines changed: 48 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -318,52 +318,6 @@ async function pickFolder(folders: ReadonlyArray<VWorkspaceFolder>, placeHolder:
318318
return selected.folder;
319319
}
320320

321-
function enable() {
322-
const folders = Workspace.workspaceFolders;
323-
if (!folders) {
324-
Window.showWarningMessage('ESLint can only be enabled if VS Code is opened on a workspace folder.');
325-
return;
326-
}
327-
const disabledFolders = folders.filter(folder => !Workspace.getConfiguration('eslint', folder.uri).get('enable', true));
328-
if (disabledFolders.length === 0) {
329-
if (folders.length === 1) {
330-
Window.showInformationMessage('ESLint is already enabled in the workspace.');
331-
} else {
332-
Window.showInformationMessage('ESLint is already enabled on all workspace folders.');
333-
}
334-
return;
335-
}
336-
pickFolder(disabledFolders, 'Select a workspace folder to enable ESLint for').then(folder => {
337-
if (!folder) {
338-
return;
339-
}
340-
Workspace.getConfiguration('eslint', folder.uri).update('enable', true);
341-
});
342-
}
343-
344-
function disable() {
345-
const folders = Workspace.workspaceFolders;
346-
if (!folders) {
347-
Window.showErrorMessage('ESLint can only be disabled if VS Code is opened on a workspace folder.');
348-
return;
349-
}
350-
const enabledFolders = folders.filter(folder => Workspace.getConfiguration('eslint', folder.uri).get('enable', true));
351-
if (enabledFolders.length === 0) {
352-
if (folders.length === 1) {
353-
Window.showInformationMessage('ESLint is already disabled in the workspace.');
354-
} else {
355-
Window.showInformationMessage('ESLint is already disabled on all workspace folders.');
356-
}
357-
return;
358-
}
359-
pickFolder(enabledFolders, 'Select a workspace folder to disable ESLint for').then(folder => {
360-
if (!folder) {
361-
return;
362-
}
363-
Workspace.getConfiguration('eslint', folder.uri).update('enable', false);
364-
});
365-
}
366-
367321
function createDefaultConfiguration(): void {
368322
const folders = Workspace.workspaceFolders;
369323
if (!folders) {
@@ -495,12 +449,22 @@ function updateStatusInfo(param: StatusParams): void {
495449
}
496450
}
497451

498-
function getExecutionInfo(editor: TextEditor | undefined): ExecutionInfo | undefined {
452+
function getExecutionInfo(editor: TextEditor | undefined, strict: boolean): ExecutionInfo | undefined {
499453
if (editor === undefined) {
500454
return undefined;
501455
}
502456
const info = resource2ResourceInfo.get(editor.document.uri.toString());
503-
return info?.executionInfo;
457+
if (info !== undefined) {
458+
return info.executionInfo;
459+
}
460+
if (!strict) {
461+
const folder = Workspace.getWorkspaceFolder(editor.document.uri);
462+
if (folder !== undefined) {
463+
const values = workspaceFolder2ExecutionInfos.get(folder.uri.toString());
464+
return values && values[0];
465+
}
466+
}
467+
return undefined;
504468
}
505469

506470
function clearInfo(info: ExecutionInfo): void {
@@ -587,7 +551,7 @@ async function askForLibraryConfirmation(client: LanguageClient | undefined, con
587551
client && client.sendNotification(DidChangeConfigurationNotification.type, { settings: {} });
588552
}
589553

590-
async function manageLibraryConfirmations(client: LanguageClient | undefined, context: ExtensionContext, update: undefined | (() => void)): Promise<void> {
554+
async function resetLibraryConfirmations(client: LanguageClient | undefined, context: ExtensionContext, update: undefined | (() => void)): Promise<void> {
591555
interface ESLintQuickPickItem extends QuickPickItem {
592556
kind: 'all' | 'allConfirmed' | 'allRejected' | 'session' | 'alwaysAllow';
593557
}
@@ -625,6 +589,10 @@ async function manageLibraryConfirmations(client: LanguageClient | undefined, co
625589
context.globalState.update(eslintExecutionKey, eslintExecutionState);
626590
context.globalState.update(eslintAlwaysAllowExecutionKey, eslintAlwaysAllowExecutionState);
627591
disabledLibraries.clear();
592+
libraryPath2ExecutionInfo.clear();
593+
resource2ResourceInfo.clear();
594+
workspaceFolder2ExecutionInfos.clear();
595+
update && update();
628596
client && client.sendNotification(DidChangeConfigurationNotification.type, { settings: {} });
629597
}
630598

@@ -663,19 +631,19 @@ export function activate(context: ExtensionContext) {
663631
const openListener: Disposable = Workspace.onDidOpenTextDocument(didOpenTextDocument);
664632
const configurationListener: Disposable = Workspace.onDidChangeConfiguration(configurationChanged);
665633

666-
const notValidating = () => Window.showInformationMessage('ESLint is not running. By default only JavaScript files are validated. If you want to validate other file types please specify them in the \'eslint.validate\' setting.');
634+
const notValidating = () => Window.showInformationMessage('ESLint is not running. By default only TypeScript and JavaScript files are validated. If you want to validate other file types please specify them in the \'eslint.probe\' setting.');
667635
onActivateCommands = [
668636
Commands.registerCommand('eslint.executeAutofix', notValidating),
669637
Commands.registerCommand('eslint.showOutputChannel', notValidating),
670-
Commands.registerCommand('eslint.manageLibraryConfirmations', () => {
671-
manageLibraryConfirmations(undefined, context, undefined);
638+
Commands.registerCommand('eslint.migrateSettings', notValidating),
639+
Commands.registerCommand('eslint.manageLibraryExecution', notValidating),
640+
Commands.registerCommand('eslint.resetLibraryExecution', () => {
641+
resetLibraryConfirmations(undefined, context, undefined);
672642
})
673643
];
674644

675645
context.subscriptions.push(
676-
Commands.registerCommand('eslint.createConfig', createDefaultConfiguration),
677-
Commands.registerCommand('eslint.enable', enable),
678-
Commands.registerCommand('eslint.disable', disable),
646+
Commands.registerCommand('eslint.createConfig', createDefaultConfiguration)
679647
);
680648
taskProvider = new TaskProvider();
681649
taskProvider.start();
@@ -1029,7 +997,7 @@ function realActivate(context: ExtensionContext): void {
1029997
let color: ThemeColor | undefined;
1030998
switch (status) {
1031999
case Status.ok:
1032-
icon = eslintAlwaysAllowExecutionState ? '$(globe)' : '$(check)';
1000+
icon = eslintAlwaysAllowExecutionState ? '$(check-all)' : '$(check)';
10331001
break;
10341002
case Status.warn:
10351003
icon = '$(alert)';
@@ -1052,7 +1020,7 @@ function realActivate(context: ExtensionContext): void {
10521020
tooltip = 'ESLint execution is not approved or denied yet.\nClick to open approval dialog.';
10531021
break;
10541022
default:
1055-
icon = eslintAlwaysAllowExecutionState ? '$(globe)' : '$(check)';
1023+
icon = eslintAlwaysAllowExecutionState ? '$(check-all)' : '$(check)';
10561024
}
10571025
statusBarItem.text = icon ? `${icon} ${text}` : text;
10581026
statusBarItem.color = color;
@@ -1118,11 +1086,11 @@ function realActivate(context: ExtensionContext): void {
11181086
provideCodeActions: (_document, _range, context) => {
11191087
for (const diag of context.diagnostics) {
11201088
if (diag === diagnostic) {
1121-
const result = new CodeAction('ESLint: Approve execution', CodeActionKind.QuickFix);
1089+
const result = new CodeAction('ESLint: Manage Library Execution', CodeActionKind.QuickFix);
11221090
result.isPreferred = true;
11231091
result.command = {
1124-
title: 'Confirm ESLint execution',
1125-
command: 'eslint.confirmExecution',
1092+
title: 'Manage Library Execution',
1093+
command: 'eslint.manageLibraryExecution',
11261094
arguments: [info.params]
11271095
};
11281096
return [result];
@@ -1167,7 +1135,7 @@ function realActivate(context: ExtensionContext): void {
11671135
return [result !== undefined ? ConfirmExecutionResult.toStatus(result) : Status.ok, false];
11681136
}
11691137

1170-
const executionInfo = getExecutionInfo(editor);
1138+
const executionInfo = getExecutionInfo(editor, true);
11711139
if (lastExecutionInfo !== executionInfo) {
11721140
clearLastExecutionInfo();
11731141
}
@@ -1848,7 +1816,7 @@ function realActivate(context: ExtensionContext): void {
18481816
});
18491817
}),
18501818
Commands.registerCommand('eslint.showOutputChannel', async () => {
1851-
const executionInfo = getExecutionInfo(Window.activeTextEditor);
1819+
const executionInfo = getExecutionInfo(Window.activeTextEditor, false);
18521820
if (executionInfo !== undefined && (executionInfo.result === ConfirmExecutionResult.confirmationPending || executionInfo.result === ConfirmExecutionResult.disabled)) {
18531821
await askForLibraryConfirmation(client, context, executionInfo.params, updateStatusBarAndDiagnostics);
18541822
return;
@@ -1860,7 +1828,7 @@ function realActivate(context: ExtensionContext): void {
18601828
}
18611829

18621830
if (globalStatus === Status.executionDenied) {
1863-
await manageLibraryConfirmations(client, context, updateStatusBarAndDiagnostics);
1831+
await resetLibraryConfirmations(client, context, updateStatusBarAndDiagnostics);
18641832
return;
18651833
}
18661834

@@ -1887,17 +1855,28 @@ function realActivate(context: ExtensionContext): void {
18871855
return;
18881856
}
18891857
}
1890-
await manageLibraryConfirmations(client, context, updateStatusBarAndDiagnostics);
1858+
await resetLibraryConfirmations(client, context, updateStatusBarAndDiagnostics);
18911859
}),
18921860
Commands.registerCommand('eslint.migrateSettings', () => {
18931861
migrateSettings();
18941862
}),
1895-
Commands.registerCommand('eslint.manageLibraryConfirmations', () => {
1896-
manageLibraryConfirmations(client, context, updateStatusBarAndDiagnostics);
1863+
Commands.registerCommand('eslint.resetLibraryExecution', () => {
1864+
resetLibraryConfirmations(client, context, updateStatusBarAndDiagnostics);
18971865
}),
1898-
Commands.registerCommand('eslint.confirmExecution', async (params: ConfirmExecutionParams) => {
1899-
disabledLibraries.delete(params.libraryPath);
1900-
await askForLibraryConfirmation(client, context, params, updateStatusBarAndDiagnostics);
1866+
Commands.registerCommand('eslint.manageLibraryExecution', async (params: ConfirmExecutionParams | undefined) => {
1867+
if (params !== undefined) {
1868+
await askForLibraryConfirmation(client, context, params, updateStatusBarAndDiagnostics);
1869+
} else {
1870+
const info = getExecutionInfo(Window.activeTextEditor, false);
1871+
if (info !== undefined) {
1872+
await askForLibraryConfirmation(client, context, info.params, updateStatusBarAndDiagnostics);
1873+
} else {
1874+
Window.showInformationMessage(
1875+
Window.activeTextEditor
1876+
? 'No ESLint library execution information found for the active editor.'
1877+
: 'No ESLint library execution information found.');
1878+
}
1879+
}
19011880
})
19021881
);
19031882
}

package.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"multi-root ready"
2323
],
2424
"engines": {
25-
"vscode": "^1.43.0"
25+
"vscode": "^1.50.0"
2626
},
2727
"activationEvents": [
28-
"*"
28+
"onStartupFinished"
2929
],
3030
"main": "./client/out/extension",
3131
"contributes": {
@@ -37,7 +37,8 @@
3737
"scope": "resource",
3838
"type": "boolean",
3939
"default": true,
40-
"description": "Controls whether eslint is enabled for JavaScript files or not."
40+
"description": "Controls whether eslint is enabled or not.",
41+
"deprecationMessage": "This setting is deprecated. Disable ESLint using the extensions viewlet."
4142
},
4243
"eslint.packageManager": {
4344
"scope": "resource",
@@ -385,16 +386,6 @@
385386
"category": "ESLint",
386387
"command": "eslint.createConfig"
387388
},
388-
{
389-
"title": "Enable ESLint",
390-
"category": "ESLint",
391-
"command": "eslint.enable"
392-
},
393-
{
394-
"title": "Disable ESLint",
395-
"category": "ESLint",
396-
"command": "eslint.disable"
397-
},
398389
{
399390
"title": "Show Output Channel",
400391
"category": "ESLint",
@@ -406,9 +397,14 @@
406397
"command": "eslint.migrateSettings"
407398
},
408399
{
409-
"title": "Reset Library Decisions",
400+
"title": "Reset Library Execution Decisions",
401+
"category": "ESLint",
402+
"command": "eslint.resetLibraryExecution"
403+
},
404+
{
405+
"title": "Manage Library Execution",
410406
"category": "ESLint",
411-
"command": "eslint.manageLibraryConfirmations"
407+
"command": "eslint.manageLibraryExecution"
412408
}
413409
],
414410
"taskDefinitions": [

0 commit comments

Comments
 (0)