Skip to content

Commit 7ed1ba7

Browse files
committed
only push values to array if unique
1 parent d82255e commit 7ed1ba7

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/services/services.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,20 +579,24 @@ namespace ts {
579579
function getDocumentationComment(declarations: readonly Declaration[] | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[] {
580580
if (!declarations) return emptyArray;
581581

582-
const docsSet = new Set<string>();
583-
JsDoc.getJsDocCommentsFromDeclarations(declarations).forEach(value => docsSet.add(value.text));
584-
if (checker && (docsSet.size === 0 || declarations.some(hasJSDocInheritDocTag))) {
582+
let doc = JsDoc.getJsDocCommentsFromDeclarations(declarations);
583+
if (checker && (doc.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
585584
forEachUnique(declarations, declaration => {
586-
const inheritedDocs = findBaseOfDeclaration(checker, declaration, symbol => {
587-
return symbol.getDocumentationComment(checker)
588-
});
589-
// TODO: GH#16312 Return a ReadonlyArray, avoid copying
590-
if (inheritedDocs) inheritedDocs.forEach(value => docsSet.add(value.text))
585+
const inheritedDocs = findBaseOfDeclaration(checker, declaration, symbol => symbol.getDocumentationComment(checker));
586+
// TODO: GH#16312 Return a ReadonlyArray, avoid copying inheritedDocs
587+
if (inheritedDocs) {
588+
if (doc.length === 0) doc = inheritedDocs.slice();
589+
else {
590+
for (const docValue of doc) {
591+
if (docValue.text !== "\n" && !inheritedDocs.some(value => value.text === docValue.text)) {
592+
inheritedDocs.push(lineBreakPart(), docValue);
593+
}
594+
}
595+
doc = inheritedDocs;
596+
};
597+
};
591598
});
592599
}
593-
let doc: SymbolDisplayPart[] = [];
594-
docsSet.forEach(value => doc.push({text: value, kind: "text"}))
595-
if (doc.length > 1) doc = doc.map((e, i) => i < doc.length - 1 && e.text !== "" ? [e, lineBreakPart()] : [e]).reduce((a, b) => a.concat(b))
596600
return doc;
597601
}
598602

0 commit comments

Comments
 (0)