From 98a5e5cc0d28cc67a2a963361b0e4acd6499cac4 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 9 Apr 2018 13:23:11 -0700 Subject: [PATCH] Prioritize spelling fix over add-missing-member fix (#23268) --- src/services/codefixes/fixes.ts | 6 ++++-- tests/cases/fourslash/codeFixSpelling3.ts | 2 +- tests/cases/fourslash/codeFixSpellingVsImport.ts | 16 ++++++++++++++++ .../fourslash/codeFixSpellingVsMissingMember.ts | 16 ++++++++++++++++ .../fourslash/codeFixUndeclaredInStaticMethod.ts | 2 +- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/codeFixSpellingVsImport.ts create mode 100644 tests/cases/fourslash/codeFixSpellingVsMissingMember.ts diff --git a/src/services/codefixes/fixes.ts b/src/services/codefixes/fixes.ts index 50a0afd3925..e16a7d2d8bf 100644 --- a/src/services/codefixes/fixes.ts +++ b/src/services/codefixes/fixes.ts @@ -1,11 +1,14 @@ +// Fixes higher in this list will be first in the array returned by `getCodeFixesAtPosition`. + /// /// /// /// /// /// -/// +/// /// +/// /// /// /// @@ -15,7 +18,6 @@ /// /// /// -/// /// /// /// diff --git a/tests/cases/fourslash/codeFixSpelling3.ts b/tests/cases/fourslash/codeFixSpelling3.ts index 4294e6e44df..6abb8b80e96 100644 --- a/tests/cases/fourslash/codeFixSpelling3.ts +++ b/tests/cases/fourslash/codeFixSpelling3.ts @@ -12,4 +12,4 @@ verify.rangeAfterCodeFix(`class C { doStuff() { this.state; } -}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2); +}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0); diff --git a/tests/cases/fourslash/codeFixSpellingVsImport.ts b/tests/cases/fourslash/codeFixSpellingVsImport.ts new file mode 100644 index 00000000000..20374a19253 --- /dev/null +++ b/tests/cases/fourslash/codeFixSpellingVsImport.ts @@ -0,0 +1,16 @@ +/// + +// Tests that the import fix is returned first. + +// @Filename: /a.ts +////export const foo = 0; + +// @Filename: /b.ts +////const foof = 0; +////foo; + +goTo.file("/b.ts"); +verify.codeFixAvailable([ + { description: `Import 'foo' from module "./a"` }, + { description: "Change spelling to 'foof'" }, +]); diff --git a/tests/cases/fourslash/codeFixSpellingVsMissingMember.ts b/tests/cases/fourslash/codeFixSpellingVsMissingMember.ts new file mode 100644 index 00000000000..71fd41d5c7c --- /dev/null +++ b/tests/cases/fourslash/codeFixSpellingVsMissingMember.ts @@ -0,0 +1,16 @@ +/// + +// Tests that the spelling fix is returned first. + +////class C { +//// foof: number; +//// method() { +//// this.foo = 10; +//// } +////} + +verify.codeFixAvailable([ + { description: "Change spelling to 'foof'" }, + { description: "Declare property \'foo\'" }, + { description: "Add index signature for property 'foo'" }, +]); diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts index 0bd4ac3a879..cabf3a2d444 100644 --- a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -48,7 +48,7 @@ verify.codeFix({ verify.codeFix({ description: "Declare static property 'prop2'", - index: 0, + index: 1, // fix at index 0 is to change the spelling to 'prop1' newRangeContent: ` static prop2: string; static prop1: number;