parent
72e6925981
commit
541b9eb7a6
|
@ -132,6 +132,7 @@ class VsCodeCodeAction extends vscode.CodeAction {
|
||||||
public readonly tsAction: Proto.CodeFixAction,
|
public readonly tsAction: Proto.CodeFixAction,
|
||||||
title: string,
|
title: string,
|
||||||
kind: vscode.CodeActionKind,
|
kind: vscode.CodeActionKind,
|
||||||
|
public readonly isFixAll: boolean,
|
||||||
) {
|
) {
|
||||||
super(title, kind);
|
super(title, kind);
|
||||||
}
|
}
|
||||||
|
@ -232,9 +233,8 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
const allActions = Array.from(results.values);
|
const allActions = Array.from(results.values);
|
||||||
const allTsActions = allActions.map(x => x.tsAction);
|
|
||||||
for (const action of allActions) {
|
for (const action of allActions) {
|
||||||
action.isPreferred = isPreferredFix(action.tsAction, allTsActions);
|
action.isPreferred = isPreferredFix(action, allActions);
|
||||||
}
|
}
|
||||||
return allActions;
|
return allActions;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||||
diagnostic: vscode.Diagnostic,
|
diagnostic: vscode.Diagnostic,
|
||||||
tsAction: Proto.CodeFixAction
|
tsAction: Proto.CodeFixAction
|
||||||
): VsCodeCodeAction {
|
): VsCodeCodeAction {
|
||||||
const codeAction = new VsCodeCodeAction(tsAction, tsAction.description, vscode.CodeActionKind.QuickFix);
|
const codeAction = new VsCodeCodeAction(tsAction, tsAction.description, vscode.CodeActionKind.QuickFix, false);
|
||||||
codeAction.edit = getEditForCodeAction(this.client, tsAction);
|
codeAction.edit = getEditForCodeAction(this.client, tsAction);
|
||||||
codeAction.diagnostics = [diagnostic];
|
codeAction.diagnostics = [diagnostic];
|
||||||
codeAction.command = {
|
codeAction.command = {
|
||||||
|
@ -313,7 +313,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||||
const action = new VsCodeCodeAction(
|
const action = new VsCodeCodeAction(
|
||||||
tsAction,
|
tsAction,
|
||||||
tsAction.fixAllDescription || localize('fixAllInFileLabel', '{0} (Fix all in file)', tsAction.description),
|
tsAction.fixAllDescription || localize('fixAllInFileLabel', '{0} (Fix all in file)', tsAction.description),
|
||||||
vscode.CodeActionKind.QuickFix);
|
vscode.CodeActionKind.QuickFix, true);
|
||||||
action.diagnostics = [diagnostic];
|
action.diagnostics = [diagnostic];
|
||||||
action.command = {
|
action.command = {
|
||||||
command: ApplyFixAllCodeAction.ID,
|
command: ApplyFixAllCodeAction.ID,
|
||||||
|
@ -347,18 +347,23 @@ const preferredFixes = new Map<string, /* priorty */number>([
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function isPreferredFix(
|
function isPreferredFix(
|
||||||
tsAction: Proto.CodeFixAction,
|
action: VsCodeCodeAction,
|
||||||
allActions: readonly Proto.CodeFixAction[]
|
allActions: readonly VsCodeCodeAction[]
|
||||||
): boolean {
|
): boolean {
|
||||||
const priority = preferredFixes.get(tsAction.fixName);
|
if (action.isFixAll) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const priority = preferredFixes.get(action.tsAction.fixName);
|
||||||
if (typeof priority === 'undefined') {
|
if (typeof priority === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return allActions.every(otherAction => {
|
return allActions.every(otherAction => {
|
||||||
if (otherAction === tsAction) {
|
if (otherAction.tsAction === action.tsAction) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const otherPriority = preferredFixes.get(otherAction.fixName);
|
const otherPriority = preferredFixes.get(otherAction.tsAction.fixName);
|
||||||
if (typeof otherPriority === 'undefined') {
|
if (typeof otherPriority === 'undefined') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import * as assert from 'assert';
|
||||||
|
import 'mocha';
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import { disposeAll } from '../utils/dispose';
|
||||||
|
import { createTestEditor, joinLines, wait } from './testUtils';
|
||||||
|
|
||||||
|
const testDocumentUri = vscode.Uri.parse('untitled:test.ts');
|
||||||
|
|
||||||
|
|
||||||
|
suite('TypeScript Quick Fix', () => {
|
||||||
|
|
||||||
|
const _disposables: vscode.Disposable[] = [];
|
||||||
|
|
||||||
|
teardown(async () => {
|
||||||
|
disposeAll(_disposables);
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Fix all should not be marked as preferred #97866', async () => {
|
||||||
|
const editor = await createTestEditor(testDocumentUri,
|
||||||
|
`export const _ = 1;`,
|
||||||
|
`const a$0 = 1;`,
|
||||||
|
`const b = 2;`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await wait(2000);
|
||||||
|
|
||||||
|
await vscode.commands.executeCommand('editor.action.autoFix');
|
||||||
|
|
||||||
|
await wait(500);
|
||||||
|
|
||||||
|
assert.strictEqual(editor.document.getText(), joinLines(
|
||||||
|
`export const _ = 1;`,
|
||||||
|
`const b = 2;`,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue