diff --git a/src/services/completions.ts b/src/services/completions.ts index 5d20343fff4..5767469c196 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -4094,6 +4094,10 @@ namespace ts.Completions { } break; case SyntaxKind.Identifier: { + const originalKeywordKind = (location as Identifier).originalKeywordKind; + if (originalKeywordKind && isKeyword(originalKeywordKind)) { + return undefined; + } // class c { public prop = c| } if (isPropertyDeclaration(location.parent) && location.parent.initializer === location) { return undefined; diff --git a/tests/cases/fourslash/completionsAfterKeywordsInBlock.ts b/tests/cases/fourslash/completionsAfterKeywordsInBlock.ts new file mode 100644 index 00000000000..674a5b498c6 --- /dev/null +++ b/tests/cases/fourslash/completionsAfterKeywordsInBlock.ts @@ -0,0 +1,50 @@ +/// + +////class C1 { +//// method(map: Map, key: string, defaultValue: string) { +//// try { +//// return map.get(key)!; +//// } +//// catch { +//// return default/*1*/ +//// } +//// } +////} +////class C2 { +//// method(map: Map, key: string, defaultValue: string) { +//// if (map.has(key)) { +//// return map.get(key)!; +//// } +//// else { +//// return default/*2*/ +//// } +//// } +////} +////class C3 { +//// method(map: Map, key: string, returnValue: string) { +//// try { +//// return map.get(key)!; +//// } +//// catch { +//// return return/*3*/ +//// } +//// } +////} +////class C4 { +//// method(map: Map, key: string, returnValue: string) { +//// if (map.has(key)) { +//// return map.get(key)!; +//// } +//// else { +//// return return/*4*/ +//// } +//// } +////} + +verify.completions({ + marker: ["1", "2"], + includes: [{ name: "defaultValue", sortText: completion.SortText.LocationPriority }] +}, { + marker: ["3", "4"], + includes: [{ name: "returnValue", sortText: completion.SortText.LocationPriority }] +});