@@ -39,7 +39,7 @@ namespace ts.GoToDefinition {
39
39
return [ sigInfo ] ;
40
40
}
41
41
else {
42
- const defs = getDefinitionFromSymbol ( typeChecker , symbol , node ) || emptyArray ;
42
+ const defs = getDefinitionFromSymbol ( typeChecker , symbol , node , calledDeclaration ) || emptyArray ;
43
43
// For a 'super()' call, put the signature first, else put the variable first.
44
44
return node . kind === SyntaxKind . SuperKeyword ? [ sigInfo , ...defs ] : [ ...defs , sigInfo ] ;
45
45
}
@@ -232,10 +232,11 @@ namespace ts.GoToDefinition {
232
232
}
233
233
}
234
234
235
- function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node ) : DefinitionInfo [ ] | undefined {
235
+ function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node , declarationNode ?: Node ) : DefinitionInfo [ ] | undefined {
236
236
// There are cases when you extend a function by adding properties to it afterwards,
237
- // we want to strip those extra properties
238
- const filteredDeclarations = filter ( symbol . declarations , d => ! isAssignmentDeclaration ( d ) || d === symbol . valueDeclaration ) || undefined ;
237
+ // we want to strip those extra properties.
238
+ // For deduping purposes, we also want to exclude any declarationNodes if provided.
239
+ const filteredDeclarations = filter ( symbol . declarations , d => d !== declarationNode && ( ! isAssignmentDeclaration ( d ) || d === symbol . valueDeclaration ) ) || undefined ;
239
240
return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( filteredDeclarations , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node ) ) ;
240
241
241
242
function getConstructSignatureDefinition ( ) : DefinitionInfo [ ] | undefined {
@@ -258,8 +259,13 @@ namespace ts.GoToDefinition {
258
259
return undefined ;
259
260
}
260
261
const declarations = signatureDeclarations . filter ( selectConstructors ? isConstructorDeclaration : isFunctionLike ) ;
262
+ const declarationsWithBody = declarations . filter ( d => ! ! ( < FunctionLikeDeclaration > d ) . body ) ;
263
+
264
+ // declarations defined on the global scope can be defined on multiple files. Get all of them.
261
265
return declarations . length
262
- ? [ createDefinitionInfo ( find ( declarations , d => ! ! ( < FunctionLikeDeclaration > d ) . body ) || last ( declarations ) , typeChecker , symbol , node ) ]
266
+ ? declarationsWithBody . length !== 0
267
+ ? declarationsWithBody . map ( x => createDefinitionInfo ( x , typeChecker , symbol , node ) )
268
+ : [ createDefinitionInfo ( last ( declarations ) , typeChecker , symbol , node ) ]
263
269
: undefined ;
264
270
}
265
271
}
0 commit comments