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:
Wenlu Wang
2020-05-07 06:05:31 +08:00
committed by GitHub
parent 35c1ba67ba
commit 8d78984558
5 changed files with 54 additions and 7 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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[];
}