Skip to content

Commit 15ef3f3

Browse files
committed
comments
1 parent 62426f0 commit 15ef3f3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/ts-autocomplete/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ type AutoCompletion = {
7676

7777
function mapCompletions(completions: ts.CompletionInfo): AutoCompletion[] {
7878
return completions.entries.map((entry) => {
79-
//console.log(entry.symbol?.getDeclarations());
79+
// entry.symbol is included because we specify includeSymbol when calling
80+
// getCompletionsAtPosition
8081
const declarations = entry.symbol?.getDeclarations();
8182
let type = 'any';
82-
if (declarations?.[0]) {
83-
const decl = declarations[0];
83+
const decl = declarations?.[0];
84+
if (decl) {
85+
// decl's children are things like ['a', ':', 'string'] or ['bb', ':',
86+
// '(p1: number) => void']. So the one at position 2 (zero indexed) is the
87+
// type.
8488
type = decl.getChildAt(2)?.getFullText()?.trim() ?? 'any';
8589
}
8690

0 commit comments

Comments
 (0)