Skip to content

Commit e9ccd70

Browse files
committed
fix(32941): include Template tag constraint to QuickInfo response
1 parent 0019c01 commit e9ccd70

9 files changed

+396
-6
lines changed

src/services/jsDoc.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,22 @@ 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+
displayParts.push(namePart(map(templateTag.typeParameters, tp => tp.getText()).join(", ")));
182+
}
183+
if (comment) {
184+
displayParts.push(spacePart());
185+
displayParts.push(...getDisplayPartsFromComment(comment, checker));
186+
}
187+
return displayParts;
173188
case SyntaxKind.JSDocTypeTag:
174189
return withNode((tag as JSDocTypeTag).typeExpression);
175190
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: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoJsDocTags7.js",
5+
"position": 116,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "const",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 116,
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": "t",
42+
"kind": "parameterName"
43+
},
44+
{
45+
"text": ":",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "T",
54+
"kind": "typeParameterName"
55+
},
56+
{
57+
"text": ")",
58+
"kind": "punctuation"
59+
},
60+
{
61+
"text": " ",
62+
"kind": "space"
63+
},
64+
{
65+
"text": "=>",
66+
"kind": "punctuation"
67+
},
68+
{
69+
"text": " ",
70+
"kind": "space"
71+
},
72+
{
73+
"text": "number",
74+
"kind": "keyword"
75+
}
76+
],
77+
"documentation": [],
78+
"tags": [
79+
{
80+
"name": "type",
81+
"text": [
82+
{
83+
"text": "{(t: T) => number}",
84+
"kind": "text"
85+
}
86+
]
87+
},
88+
{
89+
"name": "template",
90+
"text": [
91+
{
92+
"text": "T",
93+
"kind": "typeParameterName"
94+
}
95+
]
96+
}
97+
]
98+
}
99+
}
100+
]
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoJsDocTags7.js",
5+
"position": 122,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "const",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 122,
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": "t",
42+
"kind": "parameterName"
43+
},
44+
{
45+
"text": ":",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "T",
54+
"kind": "typeParameterName"
55+
},
56+
{
57+
"text": ")",
58+
"kind": "punctuation"
59+
},
60+
{
61+
"text": " ",
62+
"kind": "space"
63+
},
64+
{
65+
"text": "=>",
66+
"kind": "punctuation"
67+
},
68+
{
69+
"text": " ",
70+
"kind": "space"
71+
},
72+
{
73+
"text": "number",
74+
"kind": "keyword"
75+
}
76+
],
77+
"documentation": [],
78+
"tags": [
79+
{
80+
"name": "type",
81+
"text": [
82+
{
83+
"text": "{(t: T) => number}",
84+
"kind": "text"
85+
}
86+
]
87+
},
88+
{
89+
"name": "template",
90+
"text": [
91+
{
92+
"text": "{Foo}",
93+
"kind": "text"
94+
},
95+
{
96+
"text": " ",
97+
"kind": "space"
98+
},
99+
{
100+
"text": "T",
101+
"kind": "typeParameterName"
102+
}
103+
]
104+
}
105+
]
106+
}
107+
}
108+
]
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoJsDocTags7.js",
5+
"position": 135,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "const",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 135,
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": "t",
42+
"kind": "parameterName"
43+
},
44+
{
45+
"text": ":",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "T",
54+
"kind": "typeParameterName"
55+
},
56+
{
57+
"text": ")",
58+
"kind": "punctuation"
59+
},
60+
{
61+
"text": " ",
62+
"kind": "space"
63+
},
64+
{
65+
"text": "=>",
66+
"kind": "punctuation"
67+
},
68+
{
69+
"text": " ",
70+
"kind": "space"
71+
},
72+
{
73+
"text": "number",
74+
"kind": "keyword"
75+
}
76+
],
77+
"documentation": [],
78+
"tags": [
79+
{
80+
"name": "type",
81+
"text": [
82+
{
83+
"text": "{(t: T) => number}",
84+
"kind": "text"
85+
}
86+
]
87+
},
88+
{
89+
"name": "template",
90+
"text": [
91+
{
92+
"text": "{Foo}",
93+
"kind": "text"
94+
},
95+
{
96+
"text": " ",
97+
"kind": "space"
98+
},
99+
{
100+
"text": "T",
101+
"kind": "typeParameterName"
102+
},
103+
{
104+
"text": " ",
105+
"kind": "space"
106+
},
107+
{
108+
"text": "Comment Text",
109+
"kind": "text"
110+
}
111+
]
112+
}
113+
]
114+
}
115+
}
116+
]

tests/baselines/reference/signatureHelpTypeArguments2.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"text": [
214214
{
215215
"text": "W",
216-
"kind": "text"
216+
"kind": "typeParameterName"
217217
}
218218
]
219219
},
@@ -494,7 +494,7 @@
494494
"text": [
495495
{
496496
"text": "W",
497-
"kind": "text"
497+
"kind": "typeParameterName"
498498
}
499499
]
500500
},
@@ -775,7 +775,7 @@
775775
"text": [
776776
{
777777
"text": "W",
778-
"kind": "text"
778+
"kind": "typeParameterName"
779779
}
780780
]
781781
},
@@ -1056,7 +1056,7 @@
10561056
"text": [
10571057
{
10581058
"text": "W",
1059-
"kind": "text"
1059+
"kind": "typeParameterName"
10601060
}
10611061
]
10621062
},

0 commit comments

Comments
 (0)