Skip to content

Commit d1bd164

Browse files
Merge pull request microsoft#2641 from Microsoft/jsSigHelp
Give signature help for arbitrary functions called in .js files (even off of <dot>).
2 parents db492f1 + 8e757c0 commit d1bd164

12 files changed

Lines changed: 486 additions & 404 deletions

src/services/navigateTo.ts

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ module ts.NavigateTo {
1010
forEach(program.getSourceFiles(), sourceFile => {
1111
cancellationToken.throwIfCancellationRequested();
1212

13-
let declarations = sourceFile.getNamedDeclarations();
14-
for (let declaration of declarations) {
15-
var name = getDeclarationName(declaration);
16-
if (name !== undefined) {
17-
13+
let nameToDeclarations = sourceFile.getNamedDeclarations();
14+
for (let name in nameToDeclarations) {
15+
let declarations = getProperty(nameToDeclarations, name);
16+
if (declarations) {
1817
// First do a quick check to see if the name of the declaration matches the
1918
// last portion of the (possibly) dotted name they're searching for.
2019
let matches = patternMatcher.getMatchesForLastSegmentOfPattern(name);
@@ -23,24 +22,26 @@ module ts.NavigateTo {
2322
continue;
2423
}
2524

26-
// It was a match! If the pattern has dots in it, then also see if the
27-
// declaration container matches as well.
28-
if (patternMatcher.patternContainsDots) {
29-
let containers = getContainers(declaration);
30-
if (!containers) {
31-
return undefined;
32-
}
25+
for (let declaration of declarations) {
26+
// It was a match! If the pattern has dots in it, then also see if the
27+
// declaration container matches as well.
28+
if (patternMatcher.patternContainsDots) {
29+
let containers = getContainers(declaration);
30+
if (!containers) {
31+
return undefined;
32+
}
3333

34-
matches = patternMatcher.getMatches(containers, name);
34+
matches = patternMatcher.getMatches(containers, name);
3535

36-
if (!matches) {
37-
continue;
36+
if (!matches) {
37+
continue;
38+
}
3839
}
39-
}
4040

41-
let fileName = sourceFile.fileName;
42-
let matchKind = bestMatchKind(matches);
43-
rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration });
41+
let fileName = sourceFile.fileName;
42+
let matchKind = bestMatchKind(matches);
43+
rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration });
44+
}
4445
}
4546
}
4647
});
@@ -67,30 +68,14 @@ module ts.NavigateTo {
6768
return true;
6869
}
6970

70-
function getDeclarationName(declaration: Declaration): string {
71-
let result = getTextOfIdentifierOrLiteral(declaration.name);
72-
if (result !== undefined) {
73-
return result;
74-
}
75-
76-
if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
77-
let expr = (<ComputedPropertyName>declaration.name).expression;
78-
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
79-
return (<PropertyAccessExpression>expr).name.text;
80-
}
81-
82-
return getTextOfIdentifierOrLiteral(expr);
83-
}
84-
85-
return undefined;
86-
}
87-
8871
function getTextOfIdentifierOrLiteral(node: Node) {
89-
if (node.kind === SyntaxKind.Identifier ||
90-
node.kind === SyntaxKind.StringLiteral ||
91-
node.kind === SyntaxKind.NumericLiteral) {
72+
if (node) {
73+
if (node.kind === SyntaxKind.Identifier ||
74+
node.kind === SyntaxKind.StringLiteral ||
75+
node.kind === SyntaxKind.NumericLiteral) {
9276

93-
return (<Identifier | LiteralExpression>node).text;
77+
return (<Identifier | LiteralExpression>node).text;
78+
}
9479
}
9580

9681
return undefined;

src/services/outliningElementsCollector.ts

Lines changed: 179 additions & 179 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)