Skip to content

Commit ee0eef5

Browse files
author
Andy
committed
Fix bug: Support this. completions even when isGlobalCompletion is false (#21330)
1 parent 4e95898 commit ee0eef5

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/services/completions.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ namespace ts.Completions {
180180

181181
let insertText: string | undefined;
182182
let replacementSpan: TextSpan | undefined;
183-
if (kind === CompletionKind.Global && origin && origin.type === "this-type") {
183+
if (origin && origin.type === "this-type") {
184184
insertText = needsConvertPropertyAccess ? `this["${name}"]` : `this.${name}`;
185185
}
186186
else if (needsConvertPropertyAccess) {
@@ -683,6 +683,7 @@ namespace ts.Completions {
683683

684684
const enum CompletionKind {
685685
ObjectPropertyDeclaration,
686+
/** Note that sometimes we access completions from global scope, but use "None" instead of this. See isGlobalCompletionScope. */
686687
Global,
687688
PropertyAccess,
688689
MemberLike,
@@ -2112,13 +2113,13 @@ namespace ts.Completions {
21122113
const validIdentiferResult: CompletionEntryDisplayNameForSymbol = { name, needsConvertPropertyAccess: false };
21132114
if (isIdentifierText(name, target)) return validIdentiferResult;
21142115
switch (kind) {
2115-
case CompletionKind.None:
21162116
case CompletionKind.MemberLike:
21172117
return undefined;
21182118
case CompletionKind.ObjectPropertyDeclaration:
21192119
// TODO: GH#18169
21202120
return { name: JSON.stringify(name), needsConvertPropertyAccess: false };
21212121
case CompletionKind.PropertyAccess:
2122+
case CompletionKind.None:
21222123
case CompletionKind.Global:
21232124
// Don't add a completion for a name starting with a space. See https://github.com/Microsoft/TypeScript/pull/20547
21242125
return name.charCodeAt(0) === CharacterCodes.space ? undefined : { name, needsConvertPropertyAccess: true };

tests/cases/fourslash/completionsThisType.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
////class C {
44
//// "foo bar": number;
55
//// xyz() {
6-
//// /**/
6+
//// return (/**/)
77
//// }
88
////}
99
////
1010
////function f(this: { x: number }) { /*f*/ }
1111

1212
goTo.marker("");
1313

14-
verify.completionListContains("xyz", "(method) C.xyz(): void", "", "method", undefined, undefined, {
14+
verify.completionListContains("xyz", "(method) C.xyz(): any", "", "method", undefined, undefined, {
1515
includeInsertTextCompletions: true,
1616
insertText: "this.xyz",
1717
});

0 commit comments

Comments
 (0)