mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Make sure implement interface is prioritized over remove unused
Fixes #94212
This commit is contained in:
parent
85a336c885
commit
c3b1725a2d
|
@ -344,7 +344,7 @@ const preferredFixes = new Map<string, { readonly value: number, readonly thereC
|
|||
[fixNames.constructorForDerivedNeedSuperCall, { value: 1 }],
|
||||
[fixNames.extendsInterfaceBecomesImplements, { value: 1 }],
|
||||
[fixNames.awaitInSyncFunction, { value: 1 }],
|
||||
[fixNames.classIncorrectlyImplementsInterface, { value: 1 }],
|
||||
[fixNames.classIncorrectlyImplementsInterface, { value: 3 }],
|
||||
[fixNames.unreachableCode, { value: 1 }],
|
||||
[fixNames.unusedIdentifier, { value: 1 }],
|
||||
[fixNames.forgottenThisPropertyAccess, { value: 1 }],
|
||||
|
@ -378,6 +378,8 @@ function isPreferredFix(
|
|||
const otherFixPriority = preferredFixes.get(otherAction.tsAction.fixName);
|
||||
if (!otherFixPriority || otherFixPriority.value < fixPriority.value) {
|
||||
return true;
|
||||
} else if (otherFixPriority.value > fixPriority.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fixPriority.thereCanOnlyBeOne && action.tsAction.fixName === otherAction.tsAction.fixName) {
|
||||
|
|
|
@ -104,6 +104,24 @@ suite('TypeScript Quick Fix', () => {
|
|||
const ignoreFixes = fixes?.filter(x => x.title === 'Ignore this error message');
|
||||
assert.strictEqual(ignoreFixes?.length, 1);
|
||||
});
|
||||
|
||||
test('Should prioritize implement interface over remove unused #94212', async () => {
|
||||
const testDocumentUri = workspaceFile('foo.ts');
|
||||
const editor = await createTestEditor(testDocumentUri,
|
||||
`export interface IFoo { value: string; }`,
|
||||
`class Foo implements IFoo { }`);
|
||||
|
||||
await wait(3000);
|
||||
|
||||
const fixes = await vscode.commands.executeCommand<vscode.CodeAction[]>('vscode.executeCodeActionProvider',
|
||||
testDocumentUri,
|
||||
editor.document.lineAt(1).range
|
||||
);
|
||||
|
||||
assert.strictEqual(fixes?.length, 2);
|
||||
assert.strictEqual(fixes![0].title, `Implement interface 'IFoo'`);
|
||||
assert.strictEqual(fixes![1].title, `Remove unused declaration for: 'Foo'`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue