Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4913,6 +4913,28 @@ namespace ts {

if (!documentation) {
documentation = symbol.getDocumentationComment();
if (documentation.length === 0 && symbol.flags & SymbolFlags.Property) {
// For some special property access expressions like `experts.foo = foo` or `module.exports.foo = foo`
// there documentation comments might be attached to the right hand side symbol of their declarations.
// The pattern of such special property access is that the parent symbol is the symbol of the file.
if (symbol.parent && forEach(symbol.parent.declarations, declaration => declaration.kind === SyntaxKind.SourceFile)) {
for (const declaration of symbol.declarations) {
if (!declaration.parent || declaration.parent.kind !== SyntaxKind.BinaryExpression) {
continue;
}

const rhsSymbol = program.getTypeChecker().getSymbolAtLocation((<BinaryExpression>declaration.parent).right);
if (!rhsSymbol) {
continue;
}

documentation = rhsSymbol.getDocumentationComment();
if (documentation.length > 0) {
break;
}
}
}
}
}

return { displayParts, documentation, symbolKind };
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/fourslash/server/completionEntryDetailAcrossFiles01.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="../fourslash.ts"/>

// @allowNonTsExtensions: true
// @Filename: a.js
//// /**
//// * Modify the parameter
//// * @param {string} p1
//// */
//// var foo = function (p1) { }
//// exports.foo = foo;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also add test for module.exports.foo case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vladima Sure, added at #10458

//// fo/*1*/

// @Filename: b.ts
//// import a = require("./a");
//// a.fo/*2*/

goTo.marker('1');
verify.completionEntryDetailIs("foo", "var foo: (p1: string) => void", "Modify the parameter");
goTo.marker('2');
verify.completionEntryDetailIs("foo", "(property) a.foo: (p1: string) => void", "Modify the parameter");