@@ -50,16 +50,7 @@ namespace ts.GoToDefinition {
50
50
// assignment. This case and others are handled by the following code.
51
51
if ( node . parent . kind === SyntaxKind . ShorthandPropertyAssignment ) {
52
52
const shorthandSymbol = typeChecker . getShorthandAssignmentValueSymbol ( symbol . valueDeclaration ) ;
53
- if ( ! shorthandSymbol ) {
54
- return [ ] ;
55
- }
56
-
57
- const shorthandDeclarations = shorthandSymbol . getDeclarations ( ) ;
58
- const shorthandSymbolKind = SymbolDisplay . getSymbolKind ( typeChecker , shorthandSymbol , node ) ;
59
- const shorthandSymbolName = typeChecker . symbolToString ( shorthandSymbol ) ;
60
- const shorthandContainerName = typeChecker . symbolToString ( symbol . parent , node ) ;
61
- return map ( shorthandDeclarations ,
62
- declaration => createDefinitionInfo ( declaration , shorthandSymbolKind , shorthandSymbolName , shorthandContainerName ) ) ;
53
+ return shorthandSymbol ? shorthandSymbol . declarations . map ( decl => createDefinitionInfo ( decl , typeChecker , shorthandSymbol , node ) ) : [ ] ;
63
54
}
64
55
65
56
// If the node is the name of a BindingElement within an ObjectBindingPattern instead of just returning the
@@ -191,8 +182,7 @@ namespace ts.GoToDefinition {
191
182
}
192
183
193
184
function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node ) : DefinitionInfo [ ] {
194
- const { symbolName, symbolKind, containerName } = getSymbolInfo ( typeChecker , symbol , node ) ;
195
- return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( symbol . declarations , declaration => createDefinitionInfo ( declaration , symbolKind , symbolName , containerName ) ) ;
185
+ return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( symbol . declarations , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node ) ) ;
196
186
197
187
function getConstructSignatureDefinition ( ) : DefinitionInfo [ ] | undefined {
198
188
// Applicable only if we are in a new expression, or we are on a constructor declaration
@@ -215,7 +205,7 @@ namespace ts.GoToDefinition {
215
205
}
216
206
const declarations = signatureDeclarations . filter ( selectConstructors ? isConstructorDeclaration : isSignatureDeclaration ) ;
217
207
return declarations . length
218
- ? [ createDefinitionInfo ( find ( declarations , d => ! ! ( < FunctionLikeDeclaration > d ) . body ) || last ( declarations ) , symbolKind , symbolName , containerName ) ]
208
+ ? [ createDefinitionInfo ( find ( declarations , d => ! ! ( < FunctionLikeDeclaration > d ) . body ) || last ( declarations ) , typeChecker , symbol , node ) ]
219
209
: undefined ;
220
210
}
221
211
}
@@ -234,12 +224,16 @@ namespace ts.GoToDefinition {
234
224
}
235
225
236
226
/** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
237
- function createDefinitionInfo ( node : Declaration , symbolKind : ScriptElementKind , symbolName : string , containerName : string ) : DefinitionInfo {
238
- return createDefinitionInfoFromName ( getNameOfDeclaration ( node ) || node , symbolKind , symbolName , containerName ) ;
227
+ function createDefinitionInfo ( declaration : Declaration , checker : TypeChecker , symbol : Symbol , node : Node ) : DefinitionInfo {
228
+ const symbolName = checker . symbolToString ( symbol ) ; // Do not get scoped name, just the name of the symbol
229
+ const symbolKind = SymbolDisplay . getSymbolKind ( checker , symbol , node ) ;
230
+ const containerName = symbol . parent ? checker . symbolToString ( symbol . parent , node ) : "" ;
231
+ return createDefinitionInfoFromName ( declaration , symbolKind , symbolName , containerName ) ;
239
232
}
240
233
241
234
/** Creates a DefinitionInfo directly from the name of a declaration. */
242
- function createDefinitionInfoFromName ( name : Node , symbolKind : ScriptElementKind , symbolName : string , containerName : string ) : DefinitionInfo {
235
+ function createDefinitionInfoFromName ( declaration : Declaration , symbolKind : ScriptElementKind , symbolName : string , containerName : string ) : DefinitionInfo {
236
+ const name = getNameOfDeclaration ( declaration ) || declaration ;
243
237
const sourceFile = name . getSourceFile ( ) ;
244
238
return {
245
239
fileName : sourceFile . fileName ,
@@ -251,26 +245,12 @@ namespace ts.GoToDefinition {
251
245
} ;
252
246
}
253
247
254
- function getSymbolInfo ( typeChecker : TypeChecker , symbol : Symbol , node : Node ) {
255
- return {
256
- symbolName : typeChecker . symbolToString ( symbol ) , // Do not get scoped name, just the name of the symbol
257
- symbolKind : SymbolDisplay . getSymbolKind ( typeChecker , symbol , node ) ,
258
- containerName : symbol . parent ? typeChecker . symbolToString ( symbol . parent , node ) : ""
259
- } ;
260
- }
261
-
262
248
function createDefinitionFromSignatureDeclaration ( typeChecker : TypeChecker , decl : SignatureDeclaration ) : DefinitionInfo {
263
- const { symbolName, symbolKind, containerName } = getSymbolInfo ( typeChecker , decl . symbol , decl ) ;
264
- return createDefinitionInfo ( decl , symbolKind , symbolName , containerName ) ;
249
+ return createDefinitionInfo ( decl , typeChecker , decl . symbol , decl ) ;
265
250
}
266
251
267
252
export function findReferenceInPosition ( refs : ReadonlyArray < FileReference > , pos : number ) : FileReference | undefined {
268
- for ( const ref of refs ) {
269
- if ( ref . pos <= pos && pos <= ref . end ) {
270
- return ref ;
271
- }
272
- }
273
- return undefined ;
253
+ return find ( refs , ref => ref . pos <= pos && pos <= ref . end ) ;
274
254
}
275
255
276
256
function getDefinitionInfoForFileReference ( name : string , targetFileName : string ) : DefinitionInfo {
0 commit comments