Skip to content
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

Correctly resolve tags for function overloads #30253

Merged
merged 6 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace ts.SymbolDisplay {
let printer: Printer;
let documentationFromAlias: SymbolDisplayPart[] | undefined;
let tagsFromAlias: JSDocTagInfo[] | undefined;
let signature: Signature | undefined;

if (location.kind === SyntaxKind.ThisKeyword && !isThisExpression) {
return { displayParts: [keywordPart(SyntaxKind.ThisKeyword)], documentation: [], symbolKind: ScriptElementKind.primitiveType, tags: undefined };
Expand All @@ -147,7 +148,6 @@ namespace ts.SymbolDisplay {
symbolKind = ScriptElementKind.memberVariableElement;
}

let signature: Signature | undefined;
type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol.exportSymbol || symbol, location);

if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) {
Expand Down Expand Up @@ -501,7 +501,7 @@ namespace ts.SymbolDisplay {

if (!documentation) {
documentation = symbol.getDocumentationComment(typeChecker);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add the same code here.

tags = symbol.getJsDocTags();
tags = signature ? signature.getJsDocTags() : symbol.getJsDocTags();
if (documentation.length === 0 && symbolFlags & SymbolFlags.Property) {
// For some special property access expressions like `exports.foo = foo` or `module.exports.foo = foo`
// there documentation comments might be attached to the right hand side symbol of their declarations.
Expand Down
62 changes: 62 additions & 0 deletions tests/cases/fourslash/quickInfoJsDocTagsFunctionOverload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// <reference path='fourslash.ts'/>

// @Filename: quickInfoJsDocTagsFunctionOverload.ts
////declare function /*1*/foo(): void;
////
/////**
//// * @tag Tag text
//// */
////declare function /*2*/foo(x: number): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is a good start.

  1. can you add tests for documentation as well?
  2. can you add a test with the sequences [doc/no-tag, doc/tag], [doc/no-tag, doc/no-tag], [no-doc/no-tag, doc/tag], [no-doc/no-tag, doc/no-tag], [no-doc/no-tag, no-doc/tag]? There are other combinations but those are the ones that come to mind.
  3. I couldn't get this to work in my editor when I played with it locally, although the tests pass. Probably I just set it up wrong, but you might want to make sure it at leasts works in your editor.


goTo.marker("1");
verify.verifyQuickInfoDisplayParts(
"function",
"declare",
{ start: 17, length: 3 },
[
{text:"function",kind:"keyword"},
{text:" ",kind:"space"},
{text:"foo",kind:"functionName"},
{text:"(",kind:"punctuation"},
{text:")",kind:"punctuation"},
{text:":",kind:"punctuation"},
{text:" ",kind:"space"},
{text:"void",kind:"keyword"},
{text:" ",kind:"space"},
{text:"(",kind:"punctuation"},
{text:"+",kind:"operator"},
{text:"1",kind:"numericLiteral"},
{text:" ",kind:"space"},
{text:"overload",kind:"text"},
{text:")",kind:"punctuation"}
],
[]);

goTo.marker("2");
verify.verifyQuickInfoDisplayParts(
"function",
"declare",
{ start: 73, length: 3 },
[
{text:"function",kind:"keyword"},
{text:" ",kind:"space"},
{text:"foo",kind:"functionName"},
{text:"(",kind:"punctuation"},
{text:"x",kind:"parameterName"},
{text:":",kind:"punctuation"},
{text:" ",kind:"space"},
{text:"number",kind:"keyword"},
{text:")",kind:"punctuation"},
{text:":",kind:"punctuation"},
{text:" ",kind:"space"},
{text:"void",kind:"keyword"},
{text:" ",kind:"space"},
{text:"(",kind:"punctuation"},
{text:"+",kind:"operator"},
{text:"1",kind:"numericLiteral"},
{text:" ",kind:"space"},
{text:"overload",kind:"text"},
{text:")",kind:"punctuation"}
],
[],
[{ name: "tag", text: "Tag text" }]);