Skip to content

Commit 02cf0b6

Browse files
authored
fix(52879): No autocompletions after the typeof keyword inside JSDoc comments. (#52973)
1 parent 868331f commit 02cf0b6

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-3
lines changed

src/services/completions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,8 +3005,7 @@ function getCompletionData(
30053005

30063006
// Since this is qualified name check it's a type node location
30073007
const isImportType = isLiteralImportTypeNode(node);
3008-
const isTypeLocation = insideJsDocTagTypeExpression
3009-
|| (isImportType && !(node as ImportTypeNode).isTypeOf)
3008+
const isTypeLocation = (isImportType && !(node as ImportTypeNode).isTypeOf)
30103009
|| isPartOfTypeNode(node.parent)
30113010
|| isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker);
30123011
const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node);
@@ -3029,7 +3028,7 @@ function getCompletionData(
30293028
: isRhsOfImportDeclaration ?
30303029
// Any kind is allowed when dotting off namespace in internal import equals declaration
30313030
symbol => isValidTypeAccess(symbol) || isValidValueAccess(symbol) :
3032-
isTypeLocation ? isValidTypeAccess : isValidValueAccess;
3031+
isTypeLocation || insideJsDocTagTypeExpression ? isValidTypeAccess : isValidValueAccess;
30333032
for (const exportedSymbol of exportedSymbols) {
30343033
if (isValidAccess(exportedSymbol)) {
30353034
symbols.push(exportedSymbol);
@@ -3038,6 +3037,7 @@ function getCompletionData(
30383037

30393038
// If the module is merged with a value, we must get the type of the class and add its propertes (for inherited static methods).
30403039
if (!isTypeLocation &&
3040+
!insideJsDocTagTypeExpression &&
30413041
symbol.declarations &&
30423042
symbol.declarations.some(d => d.kind !== SyntaxKind.SourceFile && d.kind !== SyntaxKind.ModuleDeclaration && d.kind !== SyntaxKind.EnumDeclaration)) {
30433043
let type = typeChecker.getTypeOfSymbolAtLocation(symbol, node).getNonOptionalType();
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
=== /a.js ===
2+
// const foo = {
3+
// bar: {
4+
// baz: 42,
5+
// }
6+
// }
7+
// /** @typedef { typeof foo. } Foo */
8+
// ^
9+
// | ----------------------------------------------------------------------
10+
// | (property) bar: {
11+
// | baz: number;
12+
// | }
13+
// | (warning) baz
14+
// | (warning) foo
15+
// | (warning) Foo
16+
// | ----------------------------------------------------------------------
17+
18+
[
19+
{
20+
"marker": {
21+
"fileName": "/a.js",
22+
"position": 76,
23+
"name": ""
24+
},
25+
"item": {
26+
"flags": 0,
27+
"isGlobalCompletion": false,
28+
"isMemberCompletion": true,
29+
"isNewIdentifierLocation": false,
30+
"entries": [
31+
{
32+
"name": "bar",
33+
"kind": "property",
34+
"kindModifiers": "",
35+
"sortText": "11",
36+
"displayParts": [
37+
{
38+
"text": "(",
39+
"kind": "punctuation"
40+
},
41+
{
42+
"text": "property",
43+
"kind": "text"
44+
},
45+
{
46+
"text": ")",
47+
"kind": "punctuation"
48+
},
49+
{
50+
"text": " ",
51+
"kind": "space"
52+
},
53+
{
54+
"text": "bar",
55+
"kind": "propertyName"
56+
},
57+
{
58+
"text": ":",
59+
"kind": "punctuation"
60+
},
61+
{
62+
"text": " ",
63+
"kind": "space"
64+
},
65+
{
66+
"text": "{",
67+
"kind": "punctuation"
68+
},
69+
{
70+
"text": "\n",
71+
"kind": "lineBreak"
72+
},
73+
{
74+
"text": " ",
75+
"kind": "space"
76+
},
77+
{
78+
"text": "baz",
79+
"kind": "propertyName"
80+
},
81+
{
82+
"text": ":",
83+
"kind": "punctuation"
84+
},
85+
{
86+
"text": " ",
87+
"kind": "space"
88+
},
89+
{
90+
"text": "number",
91+
"kind": "keyword"
92+
},
93+
{
94+
"text": ";",
95+
"kind": "punctuation"
96+
},
97+
{
98+
"text": "\n",
99+
"kind": "lineBreak"
100+
},
101+
{
102+
"text": "}",
103+
"kind": "punctuation"
104+
}
105+
],
106+
"documentation": []
107+
},
108+
{
109+
"name": "baz",
110+
"kind": "warning",
111+
"kindModifiers": "",
112+
"sortText": "18",
113+
"isFromUncheckedFile": true
114+
},
115+
{
116+
"name": "foo",
117+
"kind": "warning",
118+
"kindModifiers": "",
119+
"sortText": "18",
120+
"isFromUncheckedFile": true
121+
},
122+
{
123+
"name": "Foo",
124+
"kind": "warning",
125+
"kindModifiers": "",
126+
"sortText": "18",
127+
"isFromUncheckedFile": true
128+
}
129+
]
130+
}
131+
}
132+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowJs: true
4+
// @filename: /a.js
5+
////const foo = {
6+
//// bar: {
7+
//// baz: 42,
8+
//// }
9+
////}
10+
/////** @typedef { typeof foo./**/ } Foo */
11+
12+
verify.baselineCompletions();

0 commit comments

Comments
 (0)