Skip to content

Commit c3b1725

Browse files
committed
Make sure implement interface is prioritized over remove unused
Fixes microsoft#94212
1 parent 85a336c commit c3b1725

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

extensions/typescript-language-features/src/features/quickFix.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ const preferredFixes = new Map<string, { readonly value: number, readonly thereC
344344
[fixNames.constructorForDerivedNeedSuperCall, { value: 1 }],
345345
[fixNames.extendsInterfaceBecomesImplements, { value: 1 }],
346346
[fixNames.awaitInSyncFunction, { value: 1 }],
347-
[fixNames.classIncorrectlyImplementsInterface, { value: 1 }],
347+
[fixNames.classIncorrectlyImplementsInterface, { value: 3 }],
348348
[fixNames.unreachableCode, { value: 1 }],
349349
[fixNames.unusedIdentifier, { value: 1 }],
350350
[fixNames.forgottenThisPropertyAccess, { value: 1 }],
@@ -378,6 +378,8 @@ function isPreferredFix(
378378
const otherFixPriority = preferredFixes.get(otherAction.tsAction.fixName);
379379
if (!otherFixPriority || otherFixPriority.value < fixPriority.value) {
380380
return true;
381+
} else if (otherFixPriority.value > fixPriority.value) {
382+
return false;
381383
}
382384

383385
if (fixPriority.thereCanOnlyBeOne && action.tsAction.fixName === otherAction.tsAction.fixName) {

extensions/typescript-language-features/src/test/quickFix.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ suite('TypeScript Quick Fix', () => {
104104
const ignoreFixes = fixes?.filter(x => x.title === 'Ignore this error message');
105105
assert.strictEqual(ignoreFixes?.length, 1);
106106
});
107+
108+
test('Should prioritize implement interface over remove unused #94212', async () => {
109+
const testDocumentUri = workspaceFile('foo.ts');
110+
const editor = await createTestEditor(testDocumentUri,
111+
`export interface IFoo { value: string; }`,
112+
`class Foo implements IFoo { }`);
113+
114+
await wait(3000);
115+
116+
const fixes = await vscode.commands.executeCommand<vscode.CodeAction[]>('vscode.executeCodeActionProvider',
117+
testDocumentUri,
118+
editor.document.lineAt(1).range
119+
);
120+
121+
assert.strictEqual(fixes?.length, 2);
122+
assert.strictEqual(fixes![0].title, `Implement interface 'IFoo'`);
123+
assert.strictEqual(fixes![1].title, `Remove unused declaration for: 'Foo'`);
124+
});
107125
});
108126

109127

0 commit comments

Comments
 (0)