Skip to content

Commit 7822759

Browse files
Only show first overload in a series of consecutive overload signatures for navigateTo
1 parent 29e770b commit 7822759

File tree

4 files changed

+96
-7
lines changed

4 files changed

+96
-7
lines changed

src/services/services.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,38 +504,56 @@ module ts {
504504
if (!this.namedDeclarations) {
505505
var sourceFile = this;
506506
var namedDeclarations: Declaration[] = [];
507-
var isExternalModule = ts.isExternalModule(sourceFile);
507+
508+
// This keeps track of the last encountered function/method/method signature
509+
// so that we may ignore all but the first overload.
510+
var overloadDeclaration: FunctionDeclaration;
508511

509512
forEachChild(sourceFile, function visit(node: Node): boolean {
510513
switch (node.kind) {
514+
case SyntaxKind.FunctionDeclaration:
515+
case SyntaxKind.Method:
516+
var functionDeclaration = <FunctionDeclaration>node;
517+
518+
// We can assume that overloadDeclaration will never be "trampled"
519+
// between consecutive overloads because we never dive into parameter initializers.
520+
if (functionDeclaration.name) {
521+
if (overloadDeclaration &&
522+
functionDeclaration.name.text === overloadDeclaration.name.text &&
523+
node.parent === overloadDeclaration.parent) {
524+
break;
525+
}
526+
527+
namedDeclarations.push(functionDeclaration);
528+
overloadDeclaration = functionDeclaration;
529+
}
530+
break;
531+
511532
case SyntaxKind.ClassDeclaration:
512533
case SyntaxKind.InterfaceDeclaration:
513534
case SyntaxKind.EnumDeclaration:
514535
case SyntaxKind.ModuleDeclaration:
515536
case SyntaxKind.ImportDeclaration:
516-
case SyntaxKind.Method:
517-
case SyntaxKind.FunctionDeclaration:
518537
case SyntaxKind.Constructor:
519538
case SyntaxKind.GetAccessor:
520539
case SyntaxKind.SetAccessor:
521540
case SyntaxKind.TypeLiteral:
522541
if ((<Declaration>node).name) {
523542
namedDeclarations.push(<Declaration>node);
524543
}
525-
forEachChild(node, visit);
526-
break;
527-
544+
// fall through
528545
case SyntaxKind.VariableStatement:
529546
case SyntaxKind.ModuleBlock:
530547
case SyntaxKind.FunctionBlock:
531548
forEachChild(node, visit);
532549
break;
533550

534551
case SyntaxKind.Parameter:
552+
// Only consider properties defined as constructor parameters
535553
if (!(node.flags & NodeFlags.AccessibilityModifier)) {
536-
// Only consider properties defined as constructor parameters
537554
break;
538555
}
556+
// fall through
539557
case SyntaxKind.VariableDeclaration:
540558
case SyntaxKind.EnumMember:
541559
case SyntaxKind.Property:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////function overload(a: string): boolean;
4+
////function overload(b: boolean): boolean;
5+
////function overload(b: number): boolean;
6+
////function overload(f: typeof overload): boolean;
7+
////function overload(x: any, b = (function overload() { return false })): boolean {
8+
//// throw overload;
9+
////}
10+
////
11+
////interface I {
12+
//// interfaceMethodSignature(a: string): boolean;
13+
//// interfaceMethodSignature(b: boolean): boolean;
14+
//// interfaceMethodSignature(b: number): boolean;
15+
//// interfaceMethodSignature(f: I): boolean;
16+
////}
17+
////
18+
////class C {
19+
//// methodOverload(a: string): boolean;
20+
//// methodOverload(b: boolean): boolean;
21+
//// methodOverload(b: number): boolean;
22+
//// methodOverload(f: I): boolean;
23+
//// methodOverload(x: any, b = (function overload() { return false })): boolean {
24+
//// throw C;
25+
//// }
26+
////}
27+
28+
verify.navigationItemsListCount(1, "overload", "exact");
29+
verify.navigationItemsListCount(1, "interfaceMethodSignature", "exact");
30+
verify.navigationItemsListCount(1, "methodOverload", "exact");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////interface I {
4+
//// interfaceMethodSignature(a: string): boolean;
5+
//// interfaceMethodSignature(b: number): boolean;
6+
//// interfaceMethodSignature(f: I): boolean;
7+
////}
8+
////interface I {
9+
//// interfaceMethodSignature(b: boolean): boolean;
10+
////}
11+
12+
verify.navigationItemsListCount(2, "interfaceMethodSignature", "exact");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////function overload1(a: string): boolean;
4+
////function overload1(b: boolean): boolean;
5+
////function overload1(b: number): boolean;
6+
////
7+
////var heyImNotInterruptingAnythingAmI = '?';
8+
////
9+
////function overload1(f: typeof overload): boolean;
10+
////function overload1(x: any, b = (function overload() { return false })): boolean {
11+
//// throw overload;
12+
////}
13+
14+
////function overload2(a: string): boolean;
15+
////function overload2(b: boolean): boolean;
16+
////function overload2(b: number): boolean;
17+
////
18+
////function iJustRuinEverything(x: any, b = (function overload() { return false })): boolean {
19+
//// throw overload;
20+
////}
21+
////
22+
////function overload2(f: typeof overload): boolean;
23+
////function overload2(x: any, b = (function overload() { return false })): boolean {
24+
//// throw overload;
25+
////}
26+
27+
verify.navigationItemsListCount(1, "overload1", "exact");
28+
verify.navigationItemsListCount(2, "overload2", "exact");
29+
verify.navigationItemsListCount(3, "overload", "prefix");

0 commit comments

Comments
 (0)