Skip to content

Add support of contextual quick info #37451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ namespace ts {
// symbol has no doc comment, then the empty array will be returned.
documentationComment?: SymbolDisplayPart[];

contextualGetAccessorDocumentationComment?: SymbolDisplayPart[];
contextualSetAccessorDocumentationComment?: SymbolDisplayPart[];

// Undefined is used to indicate the value has not been computed. If, after computing, the
// symbol has no JSDoc tags, then the empty array will be returned.
tags?: JSDocTagInfo[];
Expand Down Expand Up @@ -330,6 +333,25 @@ namespace ts {
return this.documentationComment;
}

getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[] {
switch (context?.kind) {
case SyntaxKind.GetAccessor:
if (!this.contextualGetAccessorDocumentationComment) {
this.contextualGetAccessorDocumentationComment = emptyArray;
this.contextualGetAccessorDocumentationComment = getDocumentationComment(filter(this.declarations, isGetAccessor), checker);
}
return this.contextualGetAccessorDocumentationComment;
case SyntaxKind.SetAccessor:
if (!this.contextualSetAccessorDocumentationComment) {
this.contextualSetAccessorDocumentationComment = emptyArray;
this.contextualSetAccessorDocumentationComment = getDocumentationComment(filter(this.declarations, isSetAccessor), checker);
}
return this.contextualSetAccessorDocumentationComment;
default:
return this.getDocumentationComment(checker);
}
}

getJsDocTags(): JSDocTagInfo[] {
if (this.tags === undefined) {
this.tags = JsDoc.getJsDocTagsFromDeclarations(this.declarations);
Expand Down
2 changes: 1 addition & 1 deletion src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ namespace ts.SymbolDisplay {
}

if (documentation.length === 0 && !hasMultipleSignatures) {
documentation = symbol.getDocumentationComment(typeChecker);
documentation = symbol.getContextualDocumentationComment(enclosingDeclaration, typeChecker);
}

if (documentation.length === 0 && symbolFlags & SymbolFlags.Property) {
Expand Down
2 changes: 2 additions & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace ts {
getName(): string;
getDeclarations(): Declaration[] | undefined;
getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[];
/* @internal */
getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[]
getJsDocTags(): JSDocTagInfo[];
}

Expand Down
12 changes: 6 additions & 6 deletions tests/cases/fourslash/commentsClassMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,22 @@ verify.quickInfos({
1: ["class c1", "This is comment for c1"],
2: ["(property) c1.p1: number", "p1 is property of c1"],
3: ["(method) c1.p2(b: number): number", "sum with property"],
6: ["(property) c1.p3: number", "getter property 1\nsetter property 1"],
6: ["(property) c1.p3: number", "getter property 1"],
"8q": ["(method) c1.p2(b: number): number", "sum with property"],
10: ["(property) c1.p3: number", "getter property 1\nsetter property 1"],
10: ["(property) c1.p3: number", "setter property 1"],
"13q": ["(method) c1.p2(b: number): number", "sum with property"],
14: ["(property) c1.pp1: number", "pp1 is property of c1"],
15: ["(method) c1.pp2(b: number): number", "sum with property"],
18: ["(property) c1.pp3: number", "getter property 2\nsetter property 2"],
18: ["(property) c1.pp3: number", "getter property 2"],
"20q": ["(method) c1.pp2(b: number): number", "sum with property"],
22: ["(property) c1.pp3: number", "getter property 2\nsetter property 2"],
22: ["(property) c1.pp3: number", "setter property 2"],
"25q": ["(method) c1.pp2(b: number): number", "sum with property"],
26: ["constructor c1(): c1", "Constructor method"],
27: ["(property) c1.s1: number", "s1 is static property of c1"],
28: ["(method) c1.s2(b: number): number", "static sum with property"],
32: ["(property) c1.s3: number", "static getter property\nsetter property 3"],
32: ["(property) c1.s3: number", "static getter property"],
"35q": ["(method) c1.s2(b: number): number", "static sum with property"],
37: ["(property) c1.s3: number", "static getter property\nsetter property 3"],
37: ["(property) c1.s3: number", "setter property 3"],
"42q": ["(method) c1.s2(b: number): number", "static sum with property"],
43: "(property) c1.nc_p1: number",
44: "(method) c1.nc_p2(b: number): number",
Expand Down
23 changes: 23 additions & 0 deletions tests/cases/fourslash/quickInfoForGetterAndSetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path='fourslash.ts'/>

//// class Test {
//// constructor() {
//// this.value;
//// }
////
//// /** Getter text */
//// get val/*1*/ue() {
//// return this.value;
//// }
////
//// /** Setter text */
//// set val/*2*/ue(value) {
//// this.value = value;
//// }
//// }

goTo.marker("1");
verify.quickInfoIs("(property) Test.value: any", "Getter text");

goTo.marker("2");
verify.quickInfoIs("(property) Test.value: any", "Setter text");