Skip to content

Commit 8d78984

Browse files
Kingwlsandersn
andauthored
Add support of contextual quick info (#37451)
* Add support of contextual quick info * Avoid document comment map * Make lint happy Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 35c1ba6 commit 8d78984

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

src/services/services.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ namespace ts {
293293
// symbol has no doc comment, then the empty array will be returned.
294294
documentationComment?: SymbolDisplayPart[];
295295

296+
contextualGetAccessorDocumentationComment?: SymbolDisplayPart[];
297+
contextualSetAccessorDocumentationComment?: SymbolDisplayPart[];
298+
296299
// Undefined is used to indicate the value has not been computed. If, after computing, the
297300
// symbol has no JSDoc tags, then the empty array will be returned.
298301
tags?: JSDocTagInfo[];
@@ -330,6 +333,25 @@ namespace ts {
330333
return this.documentationComment;
331334
}
332335

336+
getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[] {
337+
switch (context?.kind) {
338+
case SyntaxKind.GetAccessor:
339+
if (!this.contextualGetAccessorDocumentationComment) {
340+
this.contextualGetAccessorDocumentationComment = emptyArray;
341+
this.contextualGetAccessorDocumentationComment = getDocumentationComment(filter(this.declarations, isGetAccessor), checker);
342+
}
343+
return this.contextualGetAccessorDocumentationComment;
344+
case SyntaxKind.SetAccessor:
345+
if (!this.contextualSetAccessorDocumentationComment) {
346+
this.contextualSetAccessorDocumentationComment = emptyArray;
347+
this.contextualSetAccessorDocumentationComment = getDocumentationComment(filter(this.declarations, isSetAccessor), checker);
348+
}
349+
return this.contextualSetAccessorDocumentationComment;
350+
default:
351+
return this.getDocumentationComment(checker);
352+
}
353+
}
354+
333355
getJsDocTags(): JSDocTagInfo[] {
334356
if (this.tags === undefined) {
335357
this.tags = JsDoc.getJsDocTagsFromDeclarations(this.declarations);

src/services/symbolDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ namespace ts.SymbolDisplay {
502502
}
503503

504504
if (documentation.length === 0 && !hasMultipleSignatures) {
505-
documentation = symbol.getDocumentationComment(typeChecker);
505+
documentation = symbol.getContextualDocumentationComment(enclosingDeclaration, typeChecker);
506506
}
507507

508508
if (documentation.length === 0 && symbolFlags & SymbolFlags.Property) {

src/services/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ namespace ts {
4141
getName(): string;
4242
getDeclarations(): Declaration[] | undefined;
4343
getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[];
44+
/* @internal */
45+
getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[]
4446
getJsDocTags(): JSDocTagInfo[];
4547
}
4648

tests/cases/fourslash/commentsClassMembers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,22 @@ verify.quickInfos({
248248
1: ["class c1", "This is comment for c1"],
249249
2: ["(property) c1.p1: number", "p1 is property of c1"],
250250
3: ["(method) c1.p2(b: number): number", "sum with property"],
251-
6: ["(property) c1.p3: number", "getter property 1\nsetter property 1"],
251+
6: ["(property) c1.p3: number", "getter property 1"],
252252
"8q": ["(method) c1.p2(b: number): number", "sum with property"],
253-
10: ["(property) c1.p3: number", "getter property 1\nsetter property 1"],
253+
10: ["(property) c1.p3: number", "setter property 1"],
254254
"13q": ["(method) c1.p2(b: number): number", "sum with property"],
255255
14: ["(property) c1.pp1: number", "pp1 is property of c1"],
256256
15: ["(method) c1.pp2(b: number): number", "sum with property"],
257-
18: ["(property) c1.pp3: number", "getter property 2\nsetter property 2"],
257+
18: ["(property) c1.pp3: number", "getter property 2"],
258258
"20q": ["(method) c1.pp2(b: number): number", "sum with property"],
259-
22: ["(property) c1.pp3: number", "getter property 2\nsetter property 2"],
259+
22: ["(property) c1.pp3: number", "setter property 2"],
260260
"25q": ["(method) c1.pp2(b: number): number", "sum with property"],
261261
26: ["constructor c1(): c1", "Constructor method"],
262262
27: ["(property) c1.s1: number", "s1 is static property of c1"],
263263
28: ["(method) c1.s2(b: number): number", "static sum with property"],
264-
32: ["(property) c1.s3: number", "static getter property\nsetter property 3"],
264+
32: ["(property) c1.s3: number", "static getter property"],
265265
"35q": ["(method) c1.s2(b: number): number", "static sum with property"],
266-
37: ["(property) c1.s3: number", "static getter property\nsetter property 3"],
266+
37: ["(property) c1.s3: number", "setter property 3"],
267267
"42q": ["(method) c1.s2(b: number): number", "static sum with property"],
268268
43: "(property) c1.nc_p1: number",
269269
44: "(method) c1.nc_p2(b: number): number",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
//// class Test {
4+
//// constructor() {
5+
//// this.value;
6+
//// }
7+
////
8+
//// /** Getter text */
9+
//// get val/*1*/ue() {
10+
//// return this.value;
11+
//// }
12+
////
13+
//// /** Setter text */
14+
//// set val/*2*/ue(value) {
15+
//// this.value = value;
16+
//// }
17+
//// }
18+
19+
goTo.marker("1");
20+
verify.quickInfoIs("(property) Test.value: any", "Getter text");
21+
22+
goTo.marker("2");
23+
verify.quickInfoIs("(property) Test.value: any", "Setter text");

0 commit comments

Comments
 (0)