Skip to content

Commit 03dcdda

Browse files
author
zhengbli
committed
Treat special property access symbol differently
... when retriving documentation
1 parent f57b0fb commit 03dcdda

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/services/services.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4913,6 +4913,24 @@ namespace ts {
49134913

49144914
if (!documentation) {
49154915
documentation = symbol.getDocumentationComment();
4916+
if ((!documentation || documentation.length === 0) && symbol.flags & SymbolFlags.Property) {
4917+
// For some special property access expressions like `experts.foo = foo` or `module.exports.foo = foo`
4918+
// there documentation comments might be attached to the right hand side symbol of their declarations.
4919+
// The pattern of such special property access is that the parent symbol is the symbol of the file.
4920+
if (symbol.parent && forEach(symbol.parent.declarations, declaration => declaration.kind === SyntaxKind.SourceFile)) {
4921+
forEach(symbol.declarations, declaration => {
4922+
if (declaration.parent && declaration.parent.kind === SyntaxKind.BinaryExpression) {
4923+
const rhsSymbol = program.getTypeChecker().getSymbolAtLocation((<BinaryExpression>declaration.parent).right);
4924+
if (rhsSymbol) {
4925+
documentation = rhsSymbol.getDocumentationComment();
4926+
if (documentation && documentation.length > 0) {
4927+
return true;
4928+
}
4929+
}
4930+
}
4931+
});
4932+
}
4933+
}
49164934
}
49174935

49184936
return { displayParts, documentation, symbolKind };
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path="../fourslash.ts"/>
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: a.js
5+
//// /**
6+
//// * Modify the parameter
7+
//// * @param {string} p1
8+
//// */
9+
//// var foo = function (p1) { }
10+
//// exports.foo = foo;
11+
//// fo/*1*/
12+
13+
// @Filename: b.ts
14+
//// import a = require("./a");
15+
//// a.fo/*2*/
16+
17+
goTo.marker('1');
18+
verify.completionEntryDetailIs("foo", "var foo: (p1: string) => void", "Modify the parameter");
19+
goTo.marker('2');
20+
verify.completionEntryDetailIs("foo", "(property) a.foo: (p1: string) => void", "Modify the parameter");

0 commit comments

Comments
 (0)