Skip to content

Commit d8ab098

Browse files
authored
Merge pull request microsoft#10426 from zhengbli/9518
Treat special property access symbol differently when retriving documentation
2 parents a531b87 + a5bb13f commit d8ab098

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/services/services.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4917,6 +4917,28 @@ namespace ts {
49174917

49184918
if (!documentation) {
49194919
documentation = symbol.getDocumentationComment();
4920+
if (documentation.length === 0 && symbol.flags & SymbolFlags.Property) {
4921+
// For some special property access expressions like `experts.foo = foo` or `module.exports.foo = foo`
4922+
// there documentation comments might be attached to the right hand side symbol of their declarations.
4923+
// The pattern of such special property access is that the parent symbol is the symbol of the file.
4924+
if (symbol.parent && forEach(symbol.parent.declarations, declaration => declaration.kind === SyntaxKind.SourceFile)) {
4925+
for (const declaration of symbol.declarations) {
4926+
if (!declaration.parent || declaration.parent.kind !== SyntaxKind.BinaryExpression) {
4927+
continue;
4928+
}
4929+
4930+
const rhsSymbol = program.getTypeChecker().getSymbolAtLocation((<BinaryExpression>declaration.parent).right);
4931+
if (!rhsSymbol) {
4932+
continue;
4933+
}
4934+
4935+
documentation = rhsSymbol.getDocumentationComment();
4936+
if (documentation.length > 0) {
4937+
break;
4938+
}
4939+
}
4940+
}
4941+
}
49204942
}
49214943

49224944
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)