Skip to content

Commit 98a5e5c

Browse files
author
Andy
authored
Prioritize spelling fix over add-missing-member fix (microsoft#23268)
1 parent 998bead commit 98a5e5c

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

src/services/codefixes/fixes.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
// Fixes higher in this list will be first in the array returned by `getCodeFixesAtPosition`.
2+
13
/// <reference path="addMissingInvocationForDecorator.ts" />
24
/// <reference path="annotateWithTypeFromJSDoc.ts" />
35
/// <reference path="convertFunctionToEs6Class.ts" />
46
/// <reference path="convertToEs6Module.ts" />
57
/// <reference path="correctQualifiedNameToIndexedAccessType.ts" />
68
/// <reference path="fixClassIncorrectlyImplementsInterface.ts" />
7-
/// <reference path="fixAddMissingMember.ts" />
9+
/// <reference path="importFixes.ts" />
810
/// <reference path="fixSpelling.ts" />
11+
/// <reference path="fixAddMissingMember.ts" />
912
/// <reference path="fixCannotFindModule.ts" />
1013
/// <reference path="fixClassDoesntImplementInheritedAbstractMember.ts" />
1114
/// <reference path="fixClassSuperMustPrecedeThisAccess.ts" />
@@ -15,7 +18,6 @@
1518
/// <reference path='fixUnusedIdentifier.ts' />
1619
/// <reference path='fixJSDocTypes.ts' />
1720
/// <reference path='fixAwaitInSyncFunction.ts' />
18-
/// <reference path='importFixes.ts' />
1921
/// <reference path='disableJsDiagnostics.ts' />
2022
/// <reference path='helpers.ts' />
2123
/// <reference path='inferFromUsage.ts' />

tests/cases/fourslash/codeFixSpelling3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ verify.rangeAfterCodeFix(`class C {
1212
doStuff() {
1313
this.state;
1414
}
15-
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2);
15+
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Tests that the import fix is returned first.
4+
5+
// @Filename: /a.ts
6+
////export const foo = 0;
7+
8+
// @Filename: /b.ts
9+
////const foof = 0;
10+
////foo;
11+
12+
goTo.file("/b.ts");
13+
verify.codeFixAvailable([
14+
{ description: `Import 'foo' from module "./a"` },
15+
{ description: "Change spelling to 'foof'" },
16+
]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Tests that the spelling fix is returned first.
4+
5+
////class C {
6+
//// foof: number;
7+
//// method() {
8+
//// this.foo = 10;
9+
//// }
10+
////}
11+
12+
verify.codeFixAvailable([
13+
{ description: "Change spelling to 'foof'" },
14+
{ description: "Declare property \'foo\'" },
15+
{ description: "Add index signature for property 'foo'" },
16+
]);

tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ verify.codeFix({
4848

4949
verify.codeFix({
5050
description: "Declare static property 'prop2'",
51-
index: 0,
51+
index: 1, // fix at index 0 is to change the spelling to 'prop1'
5252
newRangeContent: `
5353
static prop2: string;
5454
static prop1: number;

0 commit comments

Comments
 (0)