Skip to content

Commit

Permalink
Sort implement abstract above remove unused
Browse files Browse the repository at this point in the history
Fixes #101486
  • Loading branch information
mjbvz committed Jul 6, 2020
1 parent a8b7c34 commit 4f9ebc3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Expand Up @@ -355,6 +355,7 @@ const preferredFixes = new Map<string, { readonly value: number, readonly thereC
[fixNames.extendsInterfaceBecomesImplements, { value: 1 }],
[fixNames.awaitInSyncFunction, { value: 1 }],
[fixNames.classIncorrectlyImplementsInterface, { value: 3 }],
[fixNames.classDoesntImplementInheritedAbstractMember, { value: 3 }],
[fixNames.unreachableCode, { value: 1 }],
[fixNames.unusedIdentifier, { value: 1 }],
[fixNames.forgottenThisPropertyAccess, { value: 1 }],
Expand Down
22 changes: 20 additions & 2 deletions extensions/typescript-language-features/src/test/quickFix.test.ts
Expand Up @@ -5,7 +5,6 @@

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

test('Should prioritize implement abstract class over remove unused #101486', async () => {
const testDocumentUri = workspaceFile('foo.ts');
const editor = await createTestEditor(testDocumentUri,
`export abstract class Foo { abstract foo(): number; }`,
`class ConcreteFoo extends Foo { }`,
);

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 inherited abstract class`);
assert.strictEqual(fixes![1].title, `Remove unused declaration for: 'ConcreteFoo'`);
});

test('Add all missing imports should come after other add import fixes #98613', async () => {
await createTestEditor(workspaceFile('foo.ts'),
`export const foo = 1;`);
Expand Down Expand Up @@ -152,6 +170,6 @@ suite('TypeScript Quick Fix', () => {


function workspaceFile(fileName: string) {
return vscode.Uri.file(join(vscode.workspace.rootPath!, fileName));
return vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, fileName);
}

Expand Up @@ -8,6 +8,7 @@ export const constructorForDerivedNeedSuperCall = 'constructorForDerivedNeedSupe
export const extendsInterfaceBecomesImplements = 'extendsInterfaceBecomesImplements';
export const awaitInSyncFunction = 'fixAwaitInSyncFunction';
export const classIncorrectlyImplementsInterface = 'fixClassIncorrectlyImplementsInterface';
export const classDoesntImplementInheritedAbstractMember = 'fixClassDoesntImplementInheritedAbstractMember';
export const unreachableCode = 'fixUnreachableCode';
export const unusedIdentifier = 'unusedIdentifier';
export const forgottenThisPropertyAccess = 'forgottenThisPropertyAccess';
Expand Down

0 comments on commit 4f9ebc3

Please sign in to comment.