Skip to content

Commit 86ccd20

Browse files
authored
fix(52212): No member completions, and irrelevant value completions, when class property initializer has no semicolon (#52213)
1 parent 41e4139 commit 86ccd20

7 files changed

+746
-8
lines changed

src/services/completions.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,7 +4829,7 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
48294829
return cls;
48304830
}
48314831
break;
4832-
case SyntaxKind.Identifier: {
4832+
case SyntaxKind.Identifier: {
48334833
const originalKeywordKind = identifierToKeywordKind(location as Identifier);
48344834
if (originalKeywordKind) {
48354835
return undefined;
@@ -4868,16 +4868,17 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
48684868
case SyntaxKind.CommaToken: // class c {getValue(): number, | }
48694869
return tryCast(contextToken.parent, isObjectTypeDeclaration);
48704870
default:
4871-
if (!isFromObjectTypeDeclaration(contextToken)) {
4872-
// class c extends React.Component { a: () => 1\n| }
4873-
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) {
4871+
if (isObjectTypeDeclaration(location)) {
4872+
// class C extends React.Component { a: () => 1\n| }
4873+
// class C { prop = ""\n | }
4874+
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line) {
48744875
return location;
48754876
}
4876-
return undefined;
4877+
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
4878+
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown))
4879+
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
48774880
}
4878-
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
4879-
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown))
4880-
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
4881+
return undefined;
48814882
}
48824883
}
48834884

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/completionsClassMembers1.ts",
5+
"position": 93,
6+
"name": ""
7+
},
8+
"completionList": {
9+
"flags": 0,
10+
"isGlobalCompletion": false,
11+
"isMemberCompletion": true,
12+
"isNewIdentifierLocation": true,
13+
"entries": [
14+
{
15+
"name": "method",
16+
"kind": "method",
17+
"kindModifiers": "",
18+
"sortText": "11",
19+
"displayParts": [
20+
{
21+
"text": "(",
22+
"kind": "punctuation"
23+
},
24+
{
25+
"text": "method",
26+
"kind": "text"
27+
},
28+
{
29+
"text": ")",
30+
"kind": "punctuation"
31+
},
32+
{
33+
"text": " ",
34+
"kind": "space"
35+
},
36+
{
37+
"text": "I",
38+
"kind": "interfaceName"
39+
},
40+
{
41+
"text": ".",
42+
"kind": "punctuation"
43+
},
44+
{
45+
"text": "method",
46+
"kind": "methodName"
47+
},
48+
{
49+
"text": "(",
50+
"kind": "punctuation"
51+
},
52+
{
53+
"text": ")",
54+
"kind": "punctuation"
55+
},
56+
{
57+
"text": ":",
58+
"kind": "punctuation"
59+
},
60+
{
61+
"text": " ",
62+
"kind": "space"
63+
},
64+
{
65+
"text": "void",
66+
"kind": "keyword"
67+
}
68+
],
69+
"documentation": []
70+
},
71+
{
72+
"name": "abstract",
73+
"kind": "keyword",
74+
"kindModifiers": "",
75+
"sortText": "15",
76+
"displayParts": [
77+
{
78+
"text": "abstract",
79+
"kind": "keyword"
80+
}
81+
]
82+
},
83+
{
84+
"name": "accessor",
85+
"kind": "keyword",
86+
"kindModifiers": "",
87+
"sortText": "15",
88+
"displayParts": [
89+
{
90+
"text": "accessor",
91+
"kind": "keyword"
92+
}
93+
]
94+
},
95+
{
96+
"name": "async",
97+
"kind": "keyword",
98+
"kindModifiers": "",
99+
"sortText": "15",
100+
"displayParts": [
101+
{
102+
"text": "async",
103+
"kind": "keyword"
104+
}
105+
]
106+
},
107+
{
108+
"name": "constructor",
109+
"kind": "keyword",
110+
"kindModifiers": "",
111+
"sortText": "15",
112+
"displayParts": [
113+
{
114+
"text": "constructor",
115+
"kind": "keyword"
116+
}
117+
]
118+
},
119+
{
120+
"name": "declare",
121+
"kind": "keyword",
122+
"kindModifiers": "",
123+
"sortText": "15",
124+
"displayParts": [
125+
{
126+
"text": "declare",
127+
"kind": "keyword"
128+
}
129+
]
130+
},
131+
{
132+
"name": "get",
133+
"kind": "keyword",
134+
"kindModifiers": "",
135+
"sortText": "15",
136+
"displayParts": [
137+
{
138+
"text": "get",
139+
"kind": "keyword"
140+
}
141+
]
142+
},
143+
{
144+
"name": "override",
145+
"kind": "keyword",
146+
"kindModifiers": "",
147+
"sortText": "15",
148+
"displayParts": [
149+
{
150+
"text": "override",
151+
"kind": "keyword"
152+
}
153+
]
154+
},
155+
{
156+
"name": "private",
157+
"kind": "keyword",
158+
"kindModifiers": "",
159+
"sortText": "15",
160+
"displayParts": [
161+
{
162+
"text": "private",
163+
"kind": "keyword"
164+
}
165+
]
166+
},
167+
{
168+
"name": "protected",
169+
"kind": "keyword",
170+
"kindModifiers": "",
171+
"sortText": "15",
172+
"displayParts": [
173+
{
174+
"text": "protected",
175+
"kind": "keyword"
176+
}
177+
]
178+
},
179+
{
180+
"name": "public",
181+
"kind": "keyword",
182+
"kindModifiers": "",
183+
"sortText": "15",
184+
"displayParts": [
185+
{
186+
"text": "public",
187+
"kind": "keyword"
188+
}
189+
]
190+
},
191+
{
192+
"name": "readonly",
193+
"kind": "keyword",
194+
"kindModifiers": "",
195+
"sortText": "15",
196+
"displayParts": [
197+
{
198+
"text": "readonly",
199+
"kind": "keyword"
200+
}
201+
]
202+
},
203+
{
204+
"name": "set",
205+
"kind": "keyword",
206+
"kindModifiers": "",
207+
"sortText": "15",
208+
"displayParts": [
209+
{
210+
"text": "set",
211+
"kind": "keyword"
212+
}
213+
]
214+
},
215+
{
216+
"name": "static",
217+
"kind": "keyword",
218+
"kindModifiers": "",
219+
"sortText": "15",
220+
"displayParts": [
221+
{
222+
"text": "static",
223+
"kind": "keyword"
224+
}
225+
]
226+
}
227+
]
228+
}
229+
}
230+
]

0 commit comments

Comments
 (0)