Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Build tag text correctly for all tags #81

Merged
merged 2 commits into from
Jun 11, 2021
Merged
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
2 changes: 2 additions & 0 deletions src/languageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ function tagToString(tag: ts.JSDocTagInfo): string {
const [paramName, ...rest] = tag.text;
tagLabel += `\`${paramName.text}\``;
if (rest.length > 0) tagLabel += ` — ${rest.map(r => r.text).join(' ')}`;
} else if (Array.isArray(tag.text)) {
tagLabel += ` — ${tag.text.map(r => r.text).join(' ')}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is determined by a user option: UserPreferences.displayPartsForJSDoc
So I think this is close, but it could be either a string or the array and so we probably want to handle that as a separate if?


    export interface JSDocTagInfo {
        /** Name of the JSDoc tag */
        name: string;
        /**
         * Comment text after the JSDoc tag -- the text after the tag name until the next tag or end of comment
         * Display parts when UserPreferences.displayPartsForJSDoc is true, flattened to string otherwise.
         */
        text?: string | SymbolDisplayPart[];
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed a change to accomodate for that. Where does the discrepancy in typescriptServices.d.ts come from though? I don't see the string option there

interface JSDocTagInfo {
        name: string;
        text?: SymbolDisplayPart[];
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, this is likely a bug in the compiler codebase - there are a few types which end up repeated in services vs the compiler. For this example, typescriptServices.d.ts has both:

// 6123
    interface JSDocTagInfo {
        name: string;
        text?: SymbolDisplayPart[];
    }

// 7433
    interface JSDocTagInfo {
        /** Name of the JSDoc tag */
        name: string;
        /**
         * Comment text after the JSDoc tag -- the text after the tag name until the next tag or end of comment
         * Display parts when UserPreferences.displayPartsForJSDoc is true, flattened to string otherwise.
         */
        text?: string | SymbolDisplayPart[];
    }

It compiles fine because of interface merging - I'll make a PR which makes them consistent to the compiler and see what someone closer to the codebase thinks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that makes sense. Thank you for the fast review on this PR!

} else if (tag.text) {
tagLabel += ` — ${tag.text}`;
}
Expand Down