mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
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 <293473+sandersn@users.noreply.github.com>
This commit is contained in:
parent
35c1ba67ba
commit
8d78984558
@ -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[];
|
||||
@ -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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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[];
|
||||
}
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
23
tests/cases/fourslash/quickInfoForGetterAndSetter.ts
Normal file
23
tests/cases/fourslash/quickInfoForGetterAndSetter.ts
Normal file
@ -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");
|
||||
Loading…
x
Reference in New Issue
Block a user