Skip to content

Commit 0d5abd8

Browse files
authored
feat(27601): include JSDoc comments for destructuring arguments (#46886)
1 parent 46d1cb1 commit 0d5abd8

7 files changed

+342
-0
lines changed

src/services/symbolDisplay.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,19 @@ namespace ts.SymbolDisplay {
584584
}
585585
}
586586

587+
if (documentation.length === 0 && isIdentifier(location) && symbol.valueDeclaration && isBindingElement(symbol.valueDeclaration)) {
588+
const declaration = symbol.valueDeclaration;
589+
const parent = declaration.parent;
590+
if (isIdentifier(declaration.name) && isObjectBindingPattern(parent)) {
591+
const name = getTextOfIdentifierOrLiteral(declaration.name);
592+
const objectType = typeChecker.getTypeAtLocation(parent);
593+
documentation = firstDefined(objectType.isUnion() ? objectType.types : [objectType], t => {
594+
const prop = t.getProperty(name);
595+
return prop ? prop.getDocumentationComment(typeChecker) : undefined;
596+
}) || emptyArray;
597+
}
598+
}
599+
587600
if (tags.length === 0 && !hasMultipleSignatures) {
588601
tags = symbol.getContextualJsDocTags(enclosingDeclaration, typeChecker);
589602
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName03.ts",
5+
"position": 122,
6+
"name": "1"
7+
},
8+
"quickInfo": {
9+
"kind": "parameter",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 119,
13+
"length": 3
14+
},
15+
"displayParts": [
16+
{
17+
"text": "(",
18+
"kind": "punctuation"
19+
},
20+
{
21+
"text": "parameter",
22+
"kind": "text"
23+
},
24+
{
25+
"text": ")",
26+
"kind": "punctuation"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "foo",
34+
"kind": "parameterName"
35+
},
36+
{
37+
"text": ":",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": " ",
42+
"kind": "space"
43+
},
44+
{
45+
"text": "string",
46+
"kind": "keyword"
47+
}
48+
],
49+
"documentation": [
50+
{
51+
"text": "A description of foo",
52+
"kind": "text"
53+
}
54+
]
55+
}
56+
}
57+
]
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName04.ts",
5+
"position": 193,
6+
"name": "1"
7+
},
8+
"quickInfo": {
9+
"kind": "parameter",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 192,
13+
"length": 1
14+
},
15+
"displayParts": [
16+
{
17+
"text": "(",
18+
"kind": "punctuation"
19+
},
20+
{
21+
"text": "parameter",
22+
"kind": "text"
23+
},
24+
{
25+
"text": ")",
26+
"kind": "punctuation"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "a",
34+
"kind": "parameterName"
35+
},
36+
{
37+
"text": ":",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": " ",
42+
"kind": "space"
43+
},
44+
{
45+
"text": "{",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": "\n",
50+
"kind": "lineBreak"
51+
},
52+
{
53+
"text": " ",
54+
"kind": "space"
55+
},
56+
{
57+
"text": "b",
58+
"kind": "propertyName"
59+
},
60+
{
61+
"text": ":",
62+
"kind": "punctuation"
63+
},
64+
{
65+
"text": " ",
66+
"kind": "space"
67+
},
68+
{
69+
"text": "string",
70+
"kind": "keyword"
71+
},
72+
{
73+
"text": ";",
74+
"kind": "punctuation"
75+
},
76+
{
77+
"text": "\n",
78+
"kind": "lineBreak"
79+
},
80+
{
81+
"text": "}",
82+
"kind": "punctuation"
83+
}
84+
],
85+
"documentation": [
86+
{
87+
"text": "A description of 'a'",
88+
"kind": "text"
89+
}
90+
]
91+
}
92+
},
93+
{
94+
"marker": {
95+
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName04.ts",
96+
"position": 200,
97+
"name": "2"
98+
},
99+
"quickInfo": {
100+
"kind": "parameter",
101+
"kindModifiers": "",
102+
"textSpan": {
103+
"start": 199,
104+
"length": 1
105+
},
106+
"displayParts": [
107+
{
108+
"text": "(",
109+
"kind": "punctuation"
110+
},
111+
{
112+
"text": "parameter",
113+
"kind": "text"
114+
},
115+
{
116+
"text": ")",
117+
"kind": "punctuation"
118+
},
119+
{
120+
"text": " ",
121+
"kind": "space"
122+
},
123+
{
124+
"text": "b",
125+
"kind": "parameterName"
126+
},
127+
{
128+
"text": ":",
129+
"kind": "punctuation"
130+
},
131+
{
132+
"text": " ",
133+
"kind": "space"
134+
},
135+
{
136+
"text": "string",
137+
"kind": "keyword"
138+
}
139+
],
140+
"documentation": [
141+
{
142+
"text": "A description of 'b'",
143+
"kind": "text"
144+
}
145+
]
146+
}
147+
}
148+
]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName05.ts",
5+
"position": 137,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "parameter",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 136,
13+
"length": 1
14+
},
15+
"displayParts": [
16+
{
17+
"text": "(",
18+
"kind": "punctuation"
19+
},
20+
{
21+
"text": "parameter",
22+
"kind": "text"
23+
},
24+
{
25+
"text": ")",
26+
"kind": "punctuation"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "a",
34+
"kind": "parameterName"
35+
},
36+
{
37+
"text": ":",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": " ",
42+
"kind": "space"
43+
},
44+
{
45+
"text": "string",
46+
"kind": "keyword"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "|",
54+
"kind": "punctuation"
55+
},
56+
{
57+
"text": " ",
58+
"kind": "space"
59+
},
60+
{
61+
"text": "number",
62+
"kind": "keyword"
63+
}
64+
],
65+
"documentation": [
66+
{
67+
"text": "A description of a",
68+
"kind": "text"
69+
}
70+
]
71+
}
72+
}
73+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface Options {
4+
//// /**
5+
//// * A description of foo
6+
//// */
7+
//// foo: string;
8+
////}
9+
////
10+
////function f({ foo }: Options) {
11+
//// foo/*1*/;
12+
////}
13+
14+
verify.baselineQuickInfo();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface Options {
4+
//// /**
5+
//// * A description of 'a'
6+
//// */
7+
//// a: {
8+
//// /**
9+
//// * A description of 'b'
10+
//// */
11+
//// b: string;
12+
//// }
13+
////}
14+
////
15+
////function f({ a, a: { b } }: Options) {
16+
//// a/*1*/;
17+
//// b/*2*/;
18+
////}
19+
20+
verify.baselineQuickInfo();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface A {
4+
//// /**
5+
//// * A description of a
6+
//// */
7+
//// a: number;
8+
////}
9+
////interface B {
10+
//// a: string;
11+
////}
12+
////
13+
////function f({ a }: A | B) {
14+
//// a/**/;
15+
////}
16+
17+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)