Skip to content

Commit 212efd5

Browse files
author
Andy
authored
In quick info, show all jsdoc tags (microsoft#19357)
1 parent 5d469cf commit 212efd5

File tree

10 files changed

+362
-63
lines changed

10 files changed

+362
-63
lines changed

src/services/jsDoc.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,44 @@ namespace ts.JsDoc {
6565
return documentationComment;
6666
}
6767

68-
export function getJsDocTagsFromDeclarations(declarations?: Declaration[]) {
68+
export function getJsDocTagsFromDeclarations(declarations?: Declaration[]): JSDocTagInfo[] {
6969
// Only collect doc comments from duplicate declarations once.
7070
const tags: JSDocTagInfo[] = [];
7171
forEachUnique(declarations, declaration => {
7272
for (const tag of getJSDocTags(declaration)) {
73-
if (tag.kind === SyntaxKind.JSDocTag) {
74-
tags.push({ name: tag.tagName.text, text: tag.comment });
75-
}
73+
tags.push({ name: tag.tagName.text, text: getCommentText(tag) });
7674
}
7775
});
7876
return tags;
7977
}
8078

79+
function getCommentText(tag: JSDocTag): string {
80+
const { comment } = tag;
81+
switch (tag.kind) {
82+
case SyntaxKind.JSDocAugmentsTag:
83+
return withNode((tag as JSDocAugmentsTag).class);
84+
case SyntaxKind.JSDocTemplateTag:
85+
return withList((tag as JSDocTemplateTag).typeParameters);
86+
case SyntaxKind.JSDocTypeTag:
87+
return withNode((tag as JSDocTypeTag).typeExpression);
88+
case SyntaxKind.JSDocTypedefTag:
89+
case SyntaxKind.JSDocPropertyTag:
90+
case SyntaxKind.JSDocParameterTag:
91+
const { name } = tag as JSDocTypedefTag | JSDocPropertyTag | JSDocParameterTag;
92+
return name ? withNode(name) : comment;
93+
default:
94+
return comment;
95+
}
96+
97+
function withNode(node: Node) {
98+
return `${node.getText()} ${comment}`;
99+
}
100+
101+
function withList(list: NodeArray<Node>): string {
102+
return `${list.map(x => x.getText())} ${comment}`;
103+
}
104+
}
105+
81106
/**
82107
* Iterates through 'array' by index and performs the callback on each element of array until the callback
83108
* returns a truthy value, then returns that value.

src/services/symbolDisplay.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ namespace ts.SymbolDisplay {
9090
: ScriptElementKindModifier.none;
9191
}
9292

93+
interface SymbolDisplayPartsDocumentationAndSymbolKind {
94+
displayParts: SymbolDisplayPart[];
95+
documentation: SymbolDisplayPart[];
96+
symbolKind: ScriptElementKind;
97+
tags: JSDocTagInfo[];
98+
}
99+
93100
// TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location
94101
export function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker: TypeChecker, symbol: Symbol, sourceFile: SourceFile, enclosingDeclaration: Node,
95-
location: Node, semanticMeaning = getMeaningFromLocation(location)) {
102+
location: Node, semanticMeaning = getMeaningFromLocation(location)): SymbolDisplayPartsDocumentationAndSymbolKind {
96103

97104
const displayParts: SymbolDisplayPart[] = [];
98105
let documentation: SymbolDisplayPart[];

tests/baselines/reference/jsDocTags.baseline

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
{
33
"marker": {
44
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
5-
"position": 981
5+
"position": 977
66
},
77
"quickInfo": {
88
"kind": "constructor",
99
"kindModifiers": "",
1010
"textSpan": {
11-
"start": 981,
11+
"start": 977,
1212
"length": 3
1313
},
1414
"displayParts": [
@@ -78,19 +78,19 @@
7878
{
7979
"marker": {
8080
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
81-
"position": 985
81+
"position": 981
8282
}
8383
},
8484
{
8585
"marker": {
8686
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
87-
"position": 989
87+
"position": 985
8888
},
8989
"quickInfo": {
9090
"kind": "class",
9191
"kindModifiers": "",
9292
"textSpan": {
93-
"start": 989,
93+
"start": 985,
9494
"length": 3
9595
},
9696
"displayParts": [
@@ -124,13 +124,13 @@
124124
{
125125
"marker": {
126126
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
127-
"position": 993
127+
"position": 989
128128
},
129129
"quickInfo": {
130130
"kind": "method",
131131
"kindModifiers": "static",
132132
"textSpan": {
133-
"start": 993,
133+
"start": 989,
134134
"length": 7
135135
},
136136
"displayParts": [
@@ -200,19 +200,19 @@
200200
{
201201
"marker": {
202202
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
203-
"position": 1001
203+
"position": 997
204204
}
205205
},
206206
{
207207
"marker": {
208208
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
209-
"position": 1008
209+
"position": 1004
210210
},
211211
"quickInfo": {
212212
"kind": "method",
213213
"kindModifiers": "",
214214
"textSpan": {
215-
"start": 1008,
215+
"start": 1004,
216216
"length": 7
217217
},
218218
"displayParts": [
@@ -277,19 +277,19 @@
277277
{
278278
"marker": {
279279
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
280-
"position": 1016
280+
"position": 1012
281281
}
282282
},
283283
{
284284
"marker": {
285285
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
286-
"position": 1023
286+
"position": 1019
287287
},
288288
"quickInfo": {
289289
"kind": "method",
290290
"kindModifiers": "",
291291
"textSpan": {
292-
"start": 1023,
292+
"start": 1019,
293293
"length": 7
294294
},
295295
"displayParts": [
@@ -343,25 +343,30 @@
343343
}
344344
],
345345
"documentation": [],
346-
"tags": []
346+
"tags": [
347+
{
348+
"name": "returns",
349+
"text": "a value"
350+
}
351+
]
347352
}
348353
},
349354
{
350355
"marker": {
351356
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
352-
"position": 1031
357+
"position": 1027
353358
}
354359
},
355360
{
356361
"marker": {
357362
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
358-
"position": 1038
363+
"position": 1034
359364
},
360365
"quickInfo": {
361366
"kind": "method",
362367
"kindModifiers": "",
363368
"textSpan": {
364-
"start": 1038,
369+
"start": 1034,
365370
"length": 7
366371
},
367372
"displayParts": [
@@ -432,6 +437,14 @@
432437
],
433438
"documentation": [],
434439
"tags": [
440+
{
441+
"name": "param",
442+
"text": "foo A value."
443+
},
444+
{
445+
"name": "returns",
446+
"text": "Another value"
447+
},
435448
{
436449
"name": "mytag",
437450
"text": ""
@@ -442,13 +455,13 @@
442455
{
443456
"marker": {
444457
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
445-
"position": 1053
458+
"position": 1049
446459
},
447460
"quickInfo": {
448461
"kind": "property",
449462
"kindModifiers": "",
450463
"textSpan": {
451-
"start": 1053,
464+
"start": 1049,
452465
"length": 9
453466
},
454467
"displayParts": [
@@ -505,13 +518,13 @@
505518
{
506519
"marker": {
507520
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
508-
"position": 1068
521+
"position": 1064
509522
},
510523
"quickInfo": {
511524
"kind": "property",
512525
"kindModifiers": "",
513526
"textSpan": {
514-
"start": 1068,
527+
"start": 1064,
515528
"length": 9
516529
},
517530
"displayParts": [
@@ -580,13 +593,13 @@
580593
{
581594
"marker": {
582595
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
583-
"position": 1083
596+
"position": 1079
584597
},
585598
"quickInfo": {
586599
"kind": "method",
587600
"kindModifiers": "",
588601
"textSpan": {
589-
"start": 1083,
602+
"start": 1079,
590603
"length": 7
591604
},
592605
"displayParts": [
@@ -651,13 +664,13 @@
651664
{
652665
"marker": {
653666
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
654-
"position": 1104
667+
"position": 1100
655668
},
656669
"quickInfo": {
657670
"kind": "",
658671
"kindModifiers": "",
659672
"textSpan": {
660-
"start": 1098,
673+
"start": 1094,
661674
"length": 6
662675
},
663676
"displayParts": [

0 commit comments

Comments
 (0)