Skip to content

Commit f83ce9b

Browse files
authored
fix(49566): Implicit this.property completions not returned while writing property (#49574)
* fix(49566): show this.prop completions in class scoped property declaration * remove duplicate default value
1 parent 44d6b51 commit f83ce9b

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

Diff for: src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,9 @@ namespace ts {
672672
return moduleSpecifier && resolveExternalModuleName(moduleSpecifier, moduleSpecifier, /*ignoreErrors*/ true);
673673
},
674674
resolveExternalModuleSymbol,
675-
tryGetThisTypeAt: (nodeIn, includeGlobalThis) => {
675+
tryGetThisTypeAt: (nodeIn, includeGlobalThis, container) => {
676676
const node = getParseTreeNode(nodeIn);
677-
return node && tryGetThisTypeAt(node, includeGlobalThis);
677+
return node && tryGetThisTypeAt(node, includeGlobalThis, container);
678678
},
679679
getTypeArgumentConstraint: nodeIn => {
680680
const node = getParseTreeNode(nodeIn, isTypeNode);

Diff for: src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4597,7 +4597,7 @@ namespace ts {
45974597
*/
45984598
/* @internal */ resolveExternalModuleSymbol(symbol: Symbol): Symbol;
45994599
/** @param node A location where we might consider accessing `this`. Not necessarily a ThisExpression. */
4600-
/* @internal */ tryGetThisTypeAt(node: Node, includeGlobalThis?: boolean): Type | undefined;
4600+
/* @internal */ tryGetThisTypeAt(node: Node, includeGlobalThis?: boolean, container?: Node): Type | undefined;
46014601
/* @internal */ getTypeArgumentConstraint(node: TypeNode): Type | undefined;
46024602

46034603
/**

Diff for: src/services/completions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ namespace ts.Completions {
26162616

26172617
// Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
26182618
if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== SyntaxKind.SourceFile) {
2619-
const thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
2619+
const thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false, isClassLike(scopeNode.parent) ? scopeNode : undefined);
26202620
if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
26212621
for (const symbol of getPropertiesForCompletion(thisType, typeChecker)) {
26222622
symbolToOriginInfoMap[symbols.length] = { kind: SymbolOriginInfoKind.ThisType };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class Foo {
4+
//// private _prop = 1;
5+
//// public a = [|_/*1*/|]
6+
////
7+
//// foo() {
8+
//// [|_/*2*/|]
9+
//// }
10+
////}
11+
12+
verify.completions({
13+
marker: ["1", "2"],
14+
includes: [
15+
{
16+
name: "_prop",
17+
insertText: "this._prop",
18+
kind: "property",
19+
sortText: completion.SortText.SuggestedClassMembers,
20+
source: completion.CompletionSource.ThisProperty,
21+
text: "(property) Foo._prop: number",
22+
kindModifiers: "private"
23+
},
24+
],
25+
preferences: {
26+
includeInsertTextCompletions: true
27+
}
28+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class Foo {
4+
//// private static _prop = 1;
5+
//// public static a = [|_/*1*/|]
6+
////
7+
//// static foo() {
8+
//// [|_/*2*/|]
9+
//// }
10+
////}
11+
12+
verify.completions({
13+
marker: ["2"],
14+
includes: [
15+
{
16+
name: "_prop",
17+
insertText: "this._prop",
18+
kind: "property",
19+
sortText: completion.SortText.SuggestedClassMembers,
20+
source: completion.CompletionSource.ThisProperty,
21+
text: "(property) Foo._prop: number",
22+
kindModifiers: "private,static"
23+
},
24+
],
25+
preferences: {
26+
includeInsertTextCompletions: true
27+
}
28+
});

0 commit comments

Comments
 (0)