Only show first overload in a series of consecutive overload signatures for navigateTo

This commit is contained in:
Daniel Rosenwasser 2014-10-01 18:51:58 -07:00
parent 29e770b58a
commit 782275924f
4 changed files with 96 additions and 7 deletions

View File

@ -504,17 +504,36 @@ module ts {
if (!this.namedDeclarations) {
var sourceFile = this;
var namedDeclarations: Declaration[] = [];
var isExternalModule = ts.isExternalModule(sourceFile);
// This keeps track of the last encountered function/method/method signature
// so that we may ignore all but the first overload.
var overloadDeclaration: FunctionDeclaration;
forEachChild(sourceFile, function visit(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Method:
var functionDeclaration = <FunctionDeclaration>node;
// We can assume that overloadDeclaration will never be "trampled"
// between consecutive overloads because we never dive into parameter initializers.
if (functionDeclaration.name) {
if (overloadDeclaration &&
functionDeclaration.name.text === overloadDeclaration.name.text &&
node.parent === overloadDeclaration.parent) {
break;
}
namedDeclarations.push(functionDeclaration);
overloadDeclaration = functionDeclaration;
}
break;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
@ -522,9 +541,7 @@ module ts {
if ((<Declaration>node).name) {
namedDeclarations.push(<Declaration>node);
}
forEachChild(node, visit);
break;
// fall through
case SyntaxKind.VariableStatement:
case SyntaxKind.ModuleBlock:
case SyntaxKind.FunctionBlock:
@ -532,10 +549,11 @@ module ts {
break;
case SyntaxKind.Parameter:
// Only consider properties defined as constructor parameters
if (!(node.flags & NodeFlags.AccessibilityModifier)) {
// Only consider properties defined as constructor parameters
break;
}
// fall through
case SyntaxKind.VariableDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.Property:

View File

@ -0,0 +1,30 @@
/// <reference path="fourslash.ts"/>
////function overload(a: string): boolean;
////function overload(b: boolean): boolean;
////function overload(b: number): boolean;
////function overload(f: typeof overload): boolean;
////function overload(x: any, b = (function overload() { return false })): boolean {
//// throw overload;
////}
////
////interface I {
//// interfaceMethodSignature(a: string): boolean;
//// interfaceMethodSignature(b: boolean): boolean;
//// interfaceMethodSignature(b: number): boolean;
//// interfaceMethodSignature(f: I): boolean;
////}
////
////class C {
//// methodOverload(a: string): boolean;
//// methodOverload(b: boolean): boolean;
//// methodOverload(b: number): boolean;
//// methodOverload(f: I): boolean;
//// methodOverload(x: any, b = (function overload() { return false })): boolean {
//// throw C;
//// }
////}
verify.navigationItemsListCount(1, "overload", "exact");
verify.navigationItemsListCount(1, "interfaceMethodSignature", "exact");
verify.navigationItemsListCount(1, "methodOverload", "exact");

View File

@ -0,0 +1,12 @@
/// <reference path="fourslash.ts"/>
////interface I {
//// interfaceMethodSignature(a: string): boolean;
//// interfaceMethodSignature(b: number): boolean;
//// interfaceMethodSignature(f: I): boolean;
////}
////interface I {
//// interfaceMethodSignature(b: boolean): boolean;
////}
verify.navigationItemsListCount(2, "interfaceMethodSignature", "exact");

View File

@ -0,0 +1,29 @@
/// <reference path="fourslash.ts"/>
////function overload1(a: string): boolean;
////function overload1(b: boolean): boolean;
////function overload1(b: number): boolean;
////
////var heyImNotInterruptingAnythingAmI = '?';
////
////function overload1(f: typeof overload): boolean;
////function overload1(x: any, b = (function overload() { return false })): boolean {
//// throw overload;
////}
////function overload2(a: string): boolean;
////function overload2(b: boolean): boolean;
////function overload2(b: number): boolean;
////
////function iJustRuinEverything(x: any, b = (function overload() { return false })): boolean {
//// throw overload;
////}
////
////function overload2(f: typeof overload): boolean;
////function overload2(x: any, b = (function overload() { return false })): boolean {
//// throw overload;
////}
verify.navigationItemsListCount(1, "overload1", "exact");
verify.navigationItemsListCount(2, "overload2", "exact");
verify.navigationItemsListCount(3, "overload", "prefix");