Skip to content

Commit 91b52b2

Browse files
committed
Support enum and module completions
1 parent 5db12f3 commit 91b52b2

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/services/services.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ module ts {
16031603
function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void {
16041604
forEach(symbols, (symbol) => {
16051605
var entry = createCompletionEntry(symbol);
1606-
if (entry) {
1606+
if (entry && !lookUp(session.symbols, entry.name)) {
16071607
session.entries.push(entry);
16081608
session.symbols[entry.name] = symbol;
16091609
}
@@ -1737,6 +1737,11 @@ module ts {
17371737
return (SyntaxKind.FirstPunctuation <= kind && kind <= SyntaxKind.LastPunctuation);
17381738
}
17391739

1740+
function isVisibleWithenDeclaration(symbol: Symbol, containingClass: Declaration): boolean {
1741+
var declaration = symbol.declarations && symbol.declarations[0];
1742+
return !(declaration && declaration.flags & NodeFlags.Private && containingClass !== declaration.parent);
1743+
}
1744+
17401745
synchronizeHostData();
17411746

17421747
filename = TypeScript.switchToForwardSlashes(filename);
@@ -1809,24 +1814,34 @@ module ts {
18091814

18101815
// Right of dot member completion list
18111816
if (isRightOfDot) {
1817+
var symbols: Symbol[] = [];
1818+
var containingClass = getAncestor(mappedNode, SyntaxKind.ClassDeclaration);
1819+
isMemberCompletion = true;
1820+
1821+
1822+
if (mappedNode.kind === SyntaxKind.Identifier || mappedNode.kind === SyntaxKind.QualifiedName || mappedNode.kind === SyntaxKind.PropertyAccess) {
1823+
var symbol = typeInfoResolver.getSymbolInfo(mappedNode);
1824+
if (symbol && symbol.flags & SymbolFlags.HasExports) {
1825+
// Extract module or enum members
1826+
forEachValue(symbol.exports, symbol => {
1827+
if (isVisibleWithenDeclaration(symbol, containingClass)) {
1828+
symbols.push(symbol);
1829+
}
1830+
});
1831+
}
1832+
}
1833+
18121834
var type = typeInfoResolver.getTypeOfNode(mappedNode);
18131835
var apparentType: ApparentType = type && typeInfoResolver.getApparentType(type);
1814-
if (!apparentType) {
1815-
return undefined;
1836+
if (apparentType) {
1837+
// Filter private properties
1838+
forEach(apparentType.getApparentProperties(), symbol => {
1839+
if (isVisibleWithenDeclaration(symbol, containingClass)) {
1840+
symbols.push(symbol);
1841+
}
1842+
});
18161843
}
18171844

1818-
var containingClass = getAncestor(mappedNode, SyntaxKind.ClassDeclaration);
1819-
1820-
var symbols: Symbol[] = [];
1821-
// Filter private properties
1822-
forEach(apparentType.getApparentProperties(), symbol => {
1823-
var declaration = symbol.declarations && symbol.declarations[0];
1824-
if (declaration && declaration.flags & NodeFlags.Private && containingClass !== declaration.parent)
1825-
return;
1826-
1827-
symbols.push(symbol);
1828-
});
1829-
isMemberCompletion = true;
18301845
getCompletionEntriesFromSymbols(symbols, activeCompletionSession);
18311846
}
18321847
else {

0 commit comments

Comments
 (0)