@@ -3455,7 +3455,49 @@ module ts {
3455
3455
} ;
3456
3456
}
3457
3457
3458
- function getDefinitionInfos ( node : Node , symbol : Symbol ) : DefinitionInfo [ ] {
3458
+ /// Goto definition
3459
+ function getDefinitionAtPosition ( fileName : string , position : number ) : DefinitionInfo [ ] {
3460
+ synchronizeHostData ( ) ;
3461
+
3462
+ let sourceFile = getValidSourceFile ( fileName ) ;
3463
+
3464
+ let node = getTouchingPropertyName ( sourceFile , position ) ;
3465
+ if ( ! node ) {
3466
+ return undefined ;
3467
+ }
3468
+
3469
+ // Labels
3470
+ if ( isJumpStatementTarget ( node ) ) {
3471
+ let labelName = ( < Identifier > node ) . text ;
3472
+ let label = getTargetLabel ( ( < BreakOrContinueStatement > node . parent ) , ( < Identifier > node ) . text ) ;
3473
+ return label ? [ createDefinitionInfo ( label , ScriptElementKind . label , labelName , /*containerName*/ undefined ) ] : undefined ;
3474
+ }
3475
+
3476
+ /// Triple slash reference comments
3477
+ let comment = forEach ( sourceFile . referencedFiles , r => ( r . pos <= position && position < r . end ) ? r : undefined ) ;
3478
+ if ( comment ) {
3479
+ let referenceFile = tryResolveScriptReference ( program , sourceFile , comment ) ;
3480
+ if ( referenceFile ) {
3481
+ return [ {
3482
+ fileName : referenceFile . fileName ,
3483
+ textSpan : createTextSpanFromBounds ( 0 , 0 ) ,
3484
+ kind : ScriptElementKind . scriptElement ,
3485
+ name : comment . fileName ,
3486
+ containerName : undefined ,
3487
+ containerKind : undefined
3488
+ } ] ;
3489
+ }
3490
+ return undefined ;
3491
+ }
3492
+
3493
+ let symbol = typeInfoResolver . getSymbolAtLocation ( node ) ;
3494
+
3495
+ // Could not find a symbol e.g. node is string or number keyword,
3496
+ // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
3497
+ if ( ! symbol ) {
3498
+ return undefined ;
3499
+ }
3500
+
3459
3501
// If this is an alias, and the request came at the declaration location
3460
3502
// get the aliased symbol instead. This allows for goto def on an import e.g.
3461
3503
// import {A, B} from "mod";
@@ -3549,52 +3591,6 @@ module ts {
3549
3591
}
3550
3592
}
3551
3593
3552
- /// Goto definition
3553
- function getDefinitionAtPosition ( fileName : string , position : number ) : DefinitionInfo [ ] {
3554
- synchronizeHostData ( ) ;
3555
-
3556
- let sourceFile = getValidSourceFile ( fileName ) ;
3557
-
3558
- let node = getTouchingPropertyName ( sourceFile , position ) ;
3559
- if ( ! node ) {
3560
- return undefined ;
3561
- }
3562
-
3563
- // Labels
3564
- if ( isJumpStatementTarget ( node ) ) {
3565
- let labelName = ( < Identifier > node ) . text ;
3566
- let label = getTargetLabel ( ( < BreakOrContinueStatement > node . parent ) , ( < Identifier > node ) . text ) ;
3567
- return label ? [ createDefinitionInfo ( label , ScriptElementKind . label , labelName , /*containerName*/ undefined ) ] : undefined ;
3568
- }
3569
-
3570
- /// Triple slash reference comments
3571
- let comment = forEach ( sourceFile . referencedFiles , r => ( r . pos <= position && position < r . end ) ? r : undefined ) ;
3572
- if ( comment ) {
3573
- let referenceFile = tryResolveScriptReference ( program , sourceFile , comment ) ;
3574
- if ( referenceFile ) {
3575
- return [ {
3576
- fileName : referenceFile . fileName ,
3577
- textSpan : createTextSpanFromBounds ( 0 , 0 ) ,
3578
- kind : ScriptElementKind . scriptElement ,
3579
- name : comment . fileName ,
3580
- containerName : undefined ,
3581
- containerKind : undefined
3582
- } ] ;
3583
- }
3584
- return undefined ;
3585
- }
3586
-
3587
- let symbol = typeInfoResolver . getSymbolAtLocation ( node ) ;
3588
-
3589
- // Could not find a symbol e.g. node is string or number keyword,
3590
- // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
3591
- if ( ! symbol ) {
3592
- return undefined ;
3593
- }
3594
-
3595
- return getDefinitionInfos ( node , symbol ) ;
3596
- }
3597
-
3598
3594
/// References and Occurrences
3599
3595
function getOccurrencesAtPosition ( fileName : string , position : number ) : ReferenceEntry [ ] {
3600
3596
synchronizeHostData ( ) ;
@@ -4149,20 +4145,23 @@ module ts {
4149
4145
}
4150
4146
4151
4147
function findRenameLocations ( fileName : string , position : number , findInStrings : boolean , findInComments : boolean ) : RenameLocation [ ] {
4152
- var referenceSymbols = findReferencesWorker ( fileName , position , findInStrings , findInComments ) ;
4153
- return convertReferences ( referenceSymbols ) ;
4148
+ var referencedSymbols = findReferencedSymbols ( fileName , position , findInStrings , findInComments ) ;
4149
+ return convertReferences ( referencedSymbols ) ;
4154
4150
}
4155
4151
4156
4152
function getReferencesAtPosition ( fileName : string , position : number ) : ReferenceEntry [ ] {
4157
- var referenceSymbols = findReferencesWorker ( fileName , position , /*findInStrings:*/ false , /*findInComments:*/ false ) ;
4158
- return convertReferences ( referenceSymbols ) ;
4153
+ var referencedSymbols = findReferencedSymbols ( fileName , position , /*findInStrings:*/ false , /*findInComments:*/ false ) ;
4154
+ return convertReferences ( referencedSymbols ) ;
4159
4155
}
4160
4156
4161
- function findReferences ( fileName : string , position : number ) : ReferencedSymbol [ ] {
4162
- return filter ( findReferencesWorker ( fileName , position , /*findInStrings:*/ false , /*findInComments:*/ false ) , rs => ! ! rs . definition ) ;
4157
+ function findReferences ( fileName : string , position : number ) : ReferencedSymbol [ ] {
4158
+ var referencedSymbols = findReferencedSymbols ( fileName , position , /*findInStrings:*/ false , /*findInComments:*/ false ) ;
4159
+
4160
+ // Only include referenced symbols that have a valid definition.
4161
+ return filter ( referencedSymbols , rs => ! ! rs . definition ) ;
4163
4162
}
4164
4163
4165
- function findReferencesWorker ( fileName : string , position : number , findInStrings : boolean , findInComments : boolean ) : ReferencedSymbol [ ] {
4164
+ function findReferencedSymbols ( fileName : string , position : number , findInStrings : boolean , findInComments : boolean ) : ReferencedSymbol [ ] {
4166
4165
synchronizeHostData ( ) ;
4167
4166
4168
4167
let sourceFile = getValidSourceFile ( fileName ) ;
@@ -4265,6 +4264,24 @@ module ts {
4265
4264
4266
4265
return result ;
4267
4266
4267
+ function getDefinition ( symbol : Symbol ) : DefinitionInfo {
4268
+ let info = getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol , node . getSourceFile ( ) , getContainerNode ( node ) , typeInfoResolver , node ) ;
4269
+ let name = map ( info . displayParts , p => p . text ) . join ( "" ) ;
4270
+ let declarations = symbol . declarations ;
4271
+ if ( ! declarations || declarations . length === 0 ) {
4272
+ return undefined ;
4273
+ }
4274
+
4275
+ return {
4276
+ containerKind : "" ,
4277
+ containerName : "" ,
4278
+ name,
4279
+ kind : info . symbolKind ,
4280
+ fileName : declarations [ 0 ] . getSourceFile ( ) . fileName ,
4281
+ textSpan : createTextSpan ( declarations [ 0 ] . getStart ( ) , 0 )
4282
+ } ;
4283
+ }
4284
+
4268
4285
function isImportOrExportSpecifierName ( location : Node ) : boolean {
4269
4286
return location . parent &&
4270
4287
( location . parent . kind === SyntaxKind . ImportSpecifier || location . parent . kind === SyntaxKind . ExportSpecifier ) &&
@@ -4513,6 +4530,11 @@ module ts {
4513
4530
// for.
4514
4531
if ( ( findInStrings && isInString ( position ) ) ||
4515
4532
( findInComments && isInComment ( position ) ) ) {
4533
+
4534
+ // In the case where we're looking inside comments/strings, we don't have
4535
+ // an actual definition. So just use 'undefined' here. Features like
4536
+ // 'Rename' won't care (as they ignore the definitions), and features like
4537
+ // 'FindReferences' will just filter out these results.
4516
4538
result . push ( {
4517
4539
definition : undefined ,
4518
4540
references : [ {
@@ -4563,7 +4585,7 @@ module ts {
4563
4585
symbolToIndex [ symbolId ] = index ;
4564
4586
4565
4587
result . push ( {
4566
- definition : getDefinitionInfos ( node , symbol ) [ 0 ] ,
4588
+ definition : getDefinition ( symbol ) ,
4567
4589
references : [ ]
4568
4590
} ) ;
4569
4591
}
@@ -4644,8 +4666,7 @@ module ts {
4644
4666
}
4645
4667
} ) ;
4646
4668
4647
- var definitions = getDefinitionInfos ( superKeyword , searchSpaceNode . symbol ) ;
4648
- var definition = definitions [ 0 ] ;
4669
+ var definition = getDefinition ( searchSpaceNode . symbol ) ;
4649
4670
return [ { definition, references } ] ;
4650
4671
}
4651
4672
0 commit comments