Skip to content

Commit 8ddead5

Browse files
authored
fix(32941): include Template tag constraint to QuickInfo response (#47567)
1 parent 3328feb commit 8ddead5

13 files changed

+889
-10
lines changed

src/services/jsDoc.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,27 @@ namespace ts.JsDoc {
169169
case SyntaxKind.JSDocAugmentsTag:
170170
return withNode((tag as JSDocAugmentsTag).class);
171171
case SyntaxKind.JSDocTemplateTag:
172-
return addComment((tag as JSDocTemplateTag).typeParameters.map(tp => tp.getText()).join(", "));
172+
const templateTag = tag as JSDocTemplateTag;
173+
const displayParts: SymbolDisplayPart[] = [];
174+
if (templateTag.constraint) {
175+
displayParts.push(textPart(templateTag.constraint.getText()));
176+
}
177+
if (length(templateTag.typeParameters)) {
178+
if (length(displayParts)) {
179+
displayParts.push(spacePart());
180+
}
181+
const lastTypeParameter = templateTag.typeParameters[templateTag.typeParameters.length - 1];
182+
forEach(templateTag.typeParameters, tp => {
183+
displayParts.push(namePart(tp.getText()));
184+
if (lastTypeParameter !== tp) {
185+
displayParts.push(...[punctuationPart(SyntaxKind.CommaToken), spacePart()]);
186+
}
187+
});
188+
}
189+
if (comment) {
190+
displayParts.push(...[spacePart(), ...getDisplayPartsFromComment(comment, checker)]);
191+
}
192+
return displayParts;
173193
case SyntaxKind.JSDocTypeTag:
174194
return withNode((tag as JSDocTypeTag).typeExpression);
175195
case SyntaxKind.JSDocTypedefTag:

tests/baselines/reference/jsdocReturnsTag.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"text": [
118118
{
119119
"text": "T",
120-
"kind": "text"
120+
"kind": "typeParameterName"
121121
}
122122
]
123123
},
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoJsDocTags10.js",
5+
"position": 80,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "const",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 80,
13+
"length": 3
14+
},
15+
"displayParts": [
16+
{
17+
"text": "const",
18+
"kind": "keyword"
19+
},
20+
{
21+
"text": " ",
22+
"kind": "space"
23+
},
24+
{
25+
"text": "foo",
26+
"kind": "localName"
27+
},
28+
{
29+
"text": ":",
30+
"kind": "punctuation"
31+
},
32+
{
33+
"text": " ",
34+
"kind": "space"
35+
},
36+
{
37+
"text": "<",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": "T1",
42+
"kind": "typeParameterName"
43+
},
44+
{
45+
"text": ",",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "T2",
54+
"kind": "typeParameterName"
55+
},
56+
{
57+
"text": ">",
58+
"kind": "punctuation"
59+
},
60+
{
61+
"text": "(",
62+
"kind": "punctuation"
63+
},
64+
{
65+
"text": "a",
66+
"kind": "parameterName"
67+
},
68+
{
69+
"text": ":",
70+
"kind": "punctuation"
71+
},
72+
{
73+
"text": " ",
74+
"kind": "space"
75+
},
76+
{
77+
"text": "T1",
78+
"kind": "typeParameterName"
79+
},
80+
{
81+
"text": ",",
82+
"kind": "punctuation"
83+
},
84+
{
85+
"text": " ",
86+
"kind": "space"
87+
},
88+
{
89+
"text": "b",
90+
"kind": "parameterName"
91+
},
92+
{
93+
"text": ":",
94+
"kind": "punctuation"
95+
},
96+
{
97+
"text": " ",
98+
"kind": "space"
99+
},
100+
{
101+
"text": "any",
102+
"kind": "keyword"
103+
},
104+
{
105+
"text": ")",
106+
"kind": "punctuation"
107+
},
108+
{
109+
"text": " ",
110+
"kind": "space"
111+
},
112+
{
113+
"text": "=>",
114+
"kind": "punctuation"
115+
},
116+
{
117+
"text": " ",
118+
"kind": "space"
119+
},
120+
{
121+
"text": "void",
122+
"kind": "keyword"
123+
}
124+
],
125+
"documentation": [],
126+
"tags": [
127+
{
128+
"name": "param",
129+
"text": [
130+
{
131+
"text": "a",
132+
"kind": "text"
133+
}
134+
]
135+
},
136+
{
137+
"name": "param",
138+
"text": [
139+
{
140+
"text": "a",
141+
"kind": "text"
142+
}
143+
]
144+
},
145+
{
146+
"name": "template",
147+
"text": [
148+
{
149+
"text": "T1",
150+
"kind": "typeParameterName"
151+
},
152+
{
153+
"text": ",",
154+
"kind": "punctuation"
155+
},
156+
{
157+
"text": " ",
158+
"kind": "space"
159+
},
160+
{
161+
"text": "T2",
162+
"kind": "typeParameterName"
163+
},
164+
{
165+
"text": " ",
166+
"kind": "space"
167+
},
168+
{
169+
"text": "Comment Text",
170+
"kind": "text"
171+
}
172+
]
173+
}
174+
]
175+
}
176+
}
177+
]

0 commit comments

Comments
 (0)