Skip to content

Commit cc7bfc0

Browse files
author
Andy
authored
Support testing jsdoc tags of completions (#26962)
1 parent 932e14e commit cc7bfc0

File tree

41 files changed

+562
-1063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+562
-1063
lines changed

src/harness/fourslash.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,8 @@ namespace FourSlash {
908908
}
909909

910910
private verifyCompletionEntry(actual: ts.CompletionEntry, expected: FourSlashInterface.ExpectedCompletionEntry) {
911-
const { insertText, replacementSpan, hasAction, isRecommended, kind, text, documentation, source, sourceDisplay } = typeof expected === "string"
912-
? { insertText: undefined, replacementSpan: undefined, hasAction: undefined, isRecommended: undefined, kind: undefined, text: undefined, documentation: undefined, source: undefined, sourceDisplay: undefined }
911+
const { insertText, replacementSpan, hasAction, isRecommended, kind, text, documentation, tags, source, sourceDisplay } = typeof expected === "string"
912+
? { insertText: undefined, replacementSpan: undefined, hasAction: undefined, isRecommended: undefined, kind: undefined, text: undefined, documentation: undefined, tags: undefined, source: undefined, sourceDisplay: undefined }
913913
: expected;
914914

915915
if (actual.insertText !== insertText) {
@@ -929,17 +929,18 @@ namespace FourSlash {
929929
assert.equal(actual.isRecommended, isRecommended);
930930
assert.equal(actual.source, source);
931931

932-
if (text) {
932+
if (text !== undefined) {
933933
const actualDetails = this.getCompletionEntryDetails(actual.name, actual.source)!;
934934
assert.equal(ts.displayPartsToString(actualDetails.displayParts), text);
935935
assert.equal(ts.displayPartsToString(actualDetails.documentation), documentation || "");
936936
// TODO: GH#23587
937937
// assert.equal(actualDetails.kind, actual.kind);
938938
assert.equal(actualDetails.kindModifiers, actual.kindModifiers);
939939
assert.equal(actualDetails.source && ts.displayPartsToString(actualDetails.source), sourceDisplay);
940+
assert.deepEqual(actualDetails.tags, tags);
940941
}
941942
else {
942-
assert(documentation === undefined && sourceDisplay === undefined, "If specifying completion details, should specify 'text'");
943+
assert(documentation === undefined && tags === undefined && sourceDisplay === undefined, "If specifying completion details, should specify 'text'");
943944
}
944945
}
945946

@@ -1363,7 +1364,7 @@ Actual: ${stringify(fullActual)}`);
13631364
public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: TextSpan,
13641365
displayParts: ts.SymbolDisplayPart[],
13651366
documentation: ts.SymbolDisplayPart[],
1366-
tags: ts.JSDocTagInfo[]
1367+
tags: ts.JSDocTagInfo[] | undefined
13671368
) {
13681369

13691370
const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition)!;
@@ -1372,11 +1373,16 @@ Actual: ${stringify(fullActual)}`);
13721373
assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan"));
13731374
assert.equal(TestState.getDisplayPartsJson(actualQuickInfo.displayParts), TestState.getDisplayPartsJson(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts"));
13741375
assert.equal(TestState.getDisplayPartsJson(actualQuickInfo.documentation), TestState.getDisplayPartsJson(documentation), this.messageAtLastKnownMarker("QuickInfo documentation"));
1375-
assert.equal(actualQuickInfo.tags!.length, tags.length, this.messageAtLastKnownMarker("QuickInfo tags"));
1376-
ts.zipWith(tags, actualQuickInfo.tags!, (expectedTag, actualTag) => {
1377-
assert.equal(expectedTag.name, actualTag.name);
1378-
assert.equal(expectedTag.text, actualTag.text, this.messageAtLastKnownMarker("QuickInfo tag " + actualTag.name));
1379-
});
1376+
if (!actualQuickInfo.tags || !tags) {
1377+
assert.equal(actualQuickInfo.tags, tags, this.messageAtLastKnownMarker("QuickInfo tags"));
1378+
}
1379+
else {
1380+
assert.equal(actualQuickInfo.tags.length, tags.length, this.messageAtLastKnownMarker("QuickInfo tags"));
1381+
ts.zipWith(tags, actualQuickInfo.tags, (expectedTag, actualTag) => {
1382+
assert.equal(expectedTag.name, actualTag.name);
1383+
assert.equal(expectedTag.text, actualTag.text, this.messageAtLastKnownMarker("QuickInfo tag " + actualTag.name));
1384+
});
1385+
}
13801386
}
13811387

13821388
public verifyRangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }) {
@@ -4802,6 +4808,7 @@ namespace FourSlashInterface {
48024808
readonly text: string;
48034809
readonly documentation: string;
48044810
readonly sourceDisplay?: string;
4811+
readonly tags?: ReadonlyArray<ts.JSDocTagInfo>;
48054812
};
48064813
export interface CompletionsAtOptions extends Partial<ts.UserPreferences> {
48074814
triggerCharacter?: ts.CompletionsTriggerCharacter;

src/services/jsDoc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace ts.JsDoc {
208208
kindModifiers: "",
209209
displayParts: [textPart(name)],
210210
documentation: emptyArray,
211-
tags: emptyArray,
211+
tags: undefined,
212212
codeActions: undefined,
213213
};
214214
}
@@ -242,7 +242,7 @@ namespace ts.JsDoc {
242242
kindModifiers: "",
243243
displayParts: [textPart(name)],
244244
documentation: emptyArray,
245-
tags: emptyArray,
245+
tags: undefined,
246246
codeActions: undefined,
247247
};
248248
}

src/services/symbolDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ namespace ts.SymbolDisplay {
534534
tags = tagsFromAlias;
535535
}
536536

537-
return { displayParts, documentation, symbolKind, tags: tags! };
537+
return { displayParts, documentation, symbolKind, tags: tags!.length === 0 ? undefined : tags };
538538

539539
function getPrinter() {
540540
if (!printer) {

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,7 @@ namespace ts.projectSystem {
32043204
{ text: "number", kind: "keyword" }
32053205
],
32063206
documentation: [],
3207-
tags: []
3207+
tags: undefined,
32083208
});
32093209
});
32103210

@@ -9501,7 +9501,7 @@ export function Test2() {
95019501
kindModifiers: ScriptElementKindModifier.exportedModifier,
95029502
name: "foo",
95039503
source: [{ text: "./a", kind: "text" }],
9504-
tags: emptyArray,
9504+
tags: undefined,
95059505
};
95069506
assert.deepEqual<ReadonlyArray<protocol.CompletionEntryDetails> | undefined>(detailsResponse, [
95079507
{
@@ -9583,7 +9583,7 @@ declare class TestLib {
95839583

95849584
constructor() {
95859585
var l = new TestLib();
9586-
9586+
95879587
}
95889588

95899589
public test2() {

tests/baselines/reference/jsDocTypedef1.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@
100100
"kind": "keyword"
101101
}
102102
],
103-
"documentation": [],
104-
"tags": []
103+
"documentation": []
105104
}
106105
}
107106
]

tests/baselines/reference/quickInfoDisplayPartsArrowFunctionExpression.baseline

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@
7373
"kind": "keyword"
7474
}
7575
],
76-
"documentation": [],
77-
"tags": []
76+
"documentation": []
7877
}
7978
},
8079
{
@@ -123,8 +122,7 @@
123122
"kind": "keyword"
124123
}
125124
],
126-
"documentation": [],
127-
"tags": []
125+
"documentation": []
128126
}
129127
},
130128
{
@@ -225,8 +223,7 @@
225223
"kind": "keyword"
226224
}
227225
],
228-
"documentation": [],
229-
"tags": []
226+
"documentation": []
230227
}
231228
},
232229
{
@@ -275,8 +272,7 @@
275272
"kind": "keyword"
276273
}
277274
],
278-
"documentation": [],
279-
"tags": []
275+
"documentation": []
280276
}
281277
},
282278
{
@@ -325,8 +321,7 @@
325321
"kind": "keyword"
326322
}
327323
],
328-
"documentation": [],
329-
"tags": []
324+
"documentation": []
330325
}
331326
},
332327
{
@@ -403,8 +398,7 @@
403398
"kind": "keyword"
404399
}
405400
],
406-
"documentation": [],
407-
"tags": []
401+
"documentation": []
408402
}
409403
},
410404
{
@@ -453,8 +447,7 @@
453447
"kind": "keyword"
454448
}
455449
],
456-
"documentation": [],
457-
"tags": []
450+
"documentation": []
458451
}
459452
},
460453
{
@@ -515,8 +508,7 @@
515508
"kind": "keyword"
516509
}
517510
],
518-
"documentation": [],
519-
"tags": []
511+
"documentation": []
520512
}
521513
}
522514
]

tests/baselines/reference/quickInfoDisplayPartsClass.baseline

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"kind": "className"
2626
}
2727
],
28-
"documentation": [],
29-
"tags": []
28+
"documentation": []
3029
}
3130
},
3231
{
@@ -67,8 +66,7 @@
6766
"kind": "className"
6867
}
6968
],
70-
"documentation": [],
71-
"tags": []
69+
"documentation": []
7270
}
7371
},
7472
{
@@ -117,8 +115,7 @@
117115
"kind": "className"
118116
}
119117
],
120-
"documentation": [],
121-
"tags": []
118+
"documentation": []
122119
}
123120
},
124121
{
@@ -167,8 +164,7 @@
167164
"kind": "className"
168165
}
169166
],
170-
"documentation": [],
171-
"tags": []
167+
"documentation": []
172168
}
173169
},
174170
{
@@ -197,8 +193,7 @@
197193
"kind": "className"
198194
}
199195
],
200-
"documentation": [],
201-
"tags": []
196+
"documentation": []
202197
}
203198
}
204199
]

0 commit comments

Comments
 (0)