Skip to content

Commit 4f9ebc3

Browse files
committed
Sort implement abstract above remove unused
Fixes microsoft#101486
1 parent a8b7c34 commit 4f9ebc3

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ const preferredFixes = new Map<string, { readonly value: number, readonly thereC
355355
[fixNames.extendsInterfaceBecomesImplements, { value: 1 }],
356356
[fixNames.awaitInSyncFunction, { value: 1 }],
357357
[fixNames.classIncorrectlyImplementsInterface, { value: 3 }],
358+
[fixNames.classDoesntImplementInheritedAbstractMember, { value: 3 }],
358359
[fixNames.unreachableCode, { value: 1 }],
359360
[fixNames.unusedIdentifier, { value: 1 }],
360361
[fixNames.forgottenThisPropertyAccess, { value: 1 }],

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as assert from 'assert';
77
import 'mocha';
8-
import { join } from 'path';
98
import * as vscode from 'vscode';
109
import { disposeAll } from '../utils/dispose';
1110
import { createTestEditor, joinLines, wait } from './testUtils';
@@ -123,6 +122,25 @@ suite('TypeScript Quick Fix', () => {
123122
assert.strictEqual(fixes![1].title, `Remove unused declaration for: 'Foo'`);
124123
});
125124

125+
test('Should prioritize implement abstract class over remove unused #101486', async () => {
126+
const testDocumentUri = workspaceFile('foo.ts');
127+
const editor = await createTestEditor(testDocumentUri,
128+
`export abstract class Foo { abstract foo(): number; }`,
129+
`class ConcreteFoo extends Foo { }`,
130+
);
131+
132+
await wait(3000);
133+
134+
const fixes = await vscode.commands.executeCommand<vscode.CodeAction[]>('vscode.executeCodeActionProvider',
135+
testDocumentUri,
136+
editor.document.lineAt(1).range
137+
);
138+
139+
assert.strictEqual(fixes?.length, 2);
140+
assert.strictEqual(fixes![0].title, `Implement inherited abstract class`);
141+
assert.strictEqual(fixes![1].title, `Remove unused declaration for: 'ConcreteFoo'`);
142+
});
143+
126144
test('Add all missing imports should come after other add import fixes #98613', async () => {
127145
await createTestEditor(workspaceFile('foo.ts'),
128146
`export const foo = 1;`);
@@ -152,6 +170,6 @@ suite('TypeScript Quick Fix', () => {
152170

153171

154172
function workspaceFile(fileName: string) {
155-
return vscode.Uri.file(join(vscode.workspace.rootPath!, fileName));
173+
return vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, fileName);
156174
}
157175

extensions/typescript-language-features/src/utils/fixNames.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const constructorForDerivedNeedSuperCall = 'constructorForDerivedNeedSupe
88
export const extendsInterfaceBecomesImplements = 'extendsInterfaceBecomesImplements';
99
export const awaitInSyncFunction = 'fixAwaitInSyncFunction';
1010
export const classIncorrectlyImplementsInterface = 'fixClassIncorrectlyImplementsInterface';
11+
export const classDoesntImplementInheritedAbstractMember = 'fixClassDoesntImplementInheritedAbstractMember';
1112
export const unreachableCode = 'fixUnreachableCode';
1213
export const unusedIdentifier = 'unusedIdentifier';
1314
export const forgottenThisPropertyAccess = 'forgottenThisPropertyAccess';

0 commit comments

Comments
 (0)