From 0bfc4b5c1abc57ebff467ea32a006ed6af606cef Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 20 Jul 2018 16:51:35 -0700 Subject: [PATCH] Ensure fixSpelling and importFixes still trigger on "Did you mean the instance/static member ..." (#25847) --- src/services/codefixes/fixSpelling.ts | 2 ++ src/services/codefixes/importFixes.ts | 2 ++ .../codeFixForgottenThisPropertyAccess01.ts | 12 ++++++++++++ tests/cases/fourslash/fourslash.ts | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index bbdfe2acad789..5dd57b6c45408 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -4,6 +4,8 @@ namespace ts.codefix { const errorCodes = [ Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code, Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2.code, ]; registerCodeFix({ diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index a745ef02fd422..a6c1b722907ee 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -4,6 +4,8 @@ namespace ts.codefix { const errorCodes: ReadonlyArray = [ Diagnostics.Cannot_find_name_0.code, Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, Diagnostics.Cannot_find_namespace_0.code, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code, diff --git a/tests/cases/fourslash/codeFixForgottenThisPropertyAccess01.ts b/tests/cases/fourslash/codeFixForgottenThisPropertyAccess01.ts index 15e23c8924e9e..8c241ff303293 100644 --- a/tests/cases/fourslash/codeFixForgottenThisPropertyAccess01.ts +++ b/tests/cases/fourslash/codeFixForgottenThisPropertyAccess01.ts @@ -1,5 +1,10 @@ /// +// @Filename: /a.ts +////export const foo = 0; + +// @Filename: /b.ts +////const fooo = 0; ////class C { //// foo: number; //// constructor() {[| @@ -7,7 +12,14 @@ //// |]} ////} +goTo.file("/b.ts"); +verify.codeFixAvailable([ + { description: `Import 'foo' from module "./a"` }, + { description: "Change spelling to 'fooo'" }, + { description: "Add 'this.' to unresolved variable" }, +]); verify.codeFix({ + index: 2, description: "Add 'this.' to unresolved variable", newRangeContent: ` this.foo = 10; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 5585b49ee7185..32b484fe36ac2 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -608,7 +608,7 @@ declare namespace FourSlashInterface { export interface VerifyCodeFixAvailableOptions { readonly description: string; readonly actions?: ReadonlyArray<{ readonly type: string, readonly data: {} }>; - readonly commands?: ReadonlyArray<{}?; + readonly commands?: ReadonlyArray<{}>; } interface VerifyNavigateToOptions {