@@ -2088,7 +2088,7 @@ module ts {
2088
2088
}
2089
2089
2090
2090
// TODO: this is a hack for now, we need a proper walking mechanism to verify that we have the correct node
2091
- var mappedNode = getNodeAtPosition ( sourceFile , TypeScript . end ( node ) - 1 ) ;
2091
+ var mappedNode = getExactTokenAtPosition ( sourceFile , TypeScript . end ( node ) - 1 , /*includeItemAtEndPosition*/ undefined ) ;
2092
2092
if ( isPunctuation ( mappedNode . kind ) ) {
2093
2093
mappedNode = mappedNode . parent ;
2094
2094
}
@@ -2325,7 +2325,7 @@ module ts {
2325
2325
2326
2326
fileName = TypeScript . switchToForwardSlashes ( fileName ) ;
2327
2327
var sourceFile = getSourceFile ( fileName ) ;
2328
- var node = getNodeAtPosition ( sourceFile , position ) ;
2328
+ var node = getExactTokenAtPosition ( sourceFile , position , /*includeItemAtEndPosition*/ undefined ) ;
2329
2329
if ( ! node ) {
2330
2330
return undefined ;
2331
2331
}
@@ -2434,7 +2434,7 @@ module ts {
2434
2434
2435
2435
fileName = TypeScript . switchToForwardSlashes ( fileName ) ;
2436
2436
var sourceFile = getSourceFile ( fileName ) ;
2437
- var node = getNodeAtPosition ( sourceFile , position ) ;
2437
+ var node = getExactTokenAtPosition ( sourceFile , position , /*includeItemAtEndPosition*/ undefined ) ;
2438
2438
if ( ! node ) {
2439
2439
return undefined ;
2440
2440
}
@@ -2512,12 +2512,25 @@ module ts {
2512
2512
return false ;
2513
2513
}
2514
2514
2515
+ function isValidGotoDefinitionTarget ( n : Node ) : boolean {
2516
+ switch ( n . kind ) {
2517
+ case SyntaxKind . Identifier :
2518
+ case SyntaxKind . SuperKeyword :
2519
+ case SyntaxKind . ThisKeyword :
2520
+ case SyntaxKind . NumericLiteral :
2521
+ case SyntaxKind . StringLiteral :
2522
+ return true ;
2523
+ default :
2524
+ return false ;
2525
+ }
2526
+ }
2527
+
2515
2528
synchronizeHostData ( ) ;
2516
2529
2517
2530
filename = TypeScript . switchToForwardSlashes ( filename ) ;
2518
2531
var sourceFile = getSourceFile ( filename ) ;
2519
2532
2520
- var node = getNodeAtPosition ( sourceFile , position ) ;
2533
+ var node = getExactTokenAtPosition ( sourceFile , position , isValidGotoDefinitionTarget ) ;
2521
2534
if ( ! node ) {
2522
2535
return undefined ;
2523
2536
}
@@ -2581,7 +2594,7 @@ module ts {
2581
2594
filename = TypeScript . switchToForwardSlashes ( filename ) ;
2582
2595
var sourceFile = getSourceFile ( filename ) ;
2583
2596
2584
- var node = getNodeAtPosition ( sourceFile , position ) ;
2597
+ var node = getExactTokenAtPosition ( sourceFile , position , isValidFindOccurencesTarget ) ;
2585
2598
if ( ! node ) {
2586
2599
return undefined ;
2587
2600
}
@@ -2647,6 +2660,32 @@ module ts {
2647
2660
2648
2661
return undefined ;
2649
2662
2663
+ function isValidFindOccurencesTarget ( n : Node ) : boolean {
2664
+ switch ( n . kind ) {
2665
+ case SyntaxKind . Identifier :
2666
+ case SyntaxKind . SuperKeyword :
2667
+ case SyntaxKind . ThisKeyword :
2668
+ case SyntaxKind . IfKeyword :
2669
+ case SyntaxKind . ElseKeyword :
2670
+ case SyntaxKind . ReturnKeyword :
2671
+ case SyntaxKind . TryKeyword :
2672
+ case SyntaxKind . CatchKeyword :
2673
+ case SyntaxKind . FinallyKeyword :
2674
+ case SyntaxKind . SwitchKeyword :
2675
+ case SyntaxKind . CaseKeyword :
2676
+ case SyntaxKind . DefaultKeyword :
2677
+ case SyntaxKind . BreakKeyword :
2678
+ case SyntaxKind . ContinueKeyword :
2679
+ case SyntaxKind . ForKeyword :
2680
+ case SyntaxKind . WhileKeyword :
2681
+ case SyntaxKind . DoKeyword :
2682
+ case SyntaxKind . Constructor :
2683
+ return true ;
2684
+ default :
2685
+ return false ;
2686
+ }
2687
+ }
2688
+
2650
2689
function getIfElseOccurrences ( ifStatement : IfStatement ) : ReferenceEntry [ ] {
2651
2690
var keywords : Node [ ] = [ ] ;
2652
2691
@@ -2903,7 +2942,7 @@ module ts {
2903
2942
filename = TypeScript . switchToForwardSlashes ( filename ) ;
2904
2943
var sourceFile = getSourceFile ( filename ) ;
2905
2944
2906
- var node = getNodeAtPosition ( sourceFile , position ) ;
2945
+ var node = getExactTokenAtPosition ( sourceFile , position , /*includeItemAtEndPosition*/ undefined ) ;
2907
2946
if ( ! node ) {
2908
2947
return undefined ;
2909
2948
}
@@ -3086,7 +3125,7 @@ module ts {
3086
3125
forEach ( possiblePositions , position => {
3087
3126
cancellationToken . throwIfCancellationRequested ( ) ;
3088
3127
3089
- var node = getNodeAtPosition ( sourceFile , position ) ;
3128
+ var node = getExactTokenAtPosition ( sourceFile , position , /*includeItemAtEndPosition*/ undefined ) ;
3090
3129
if ( ! node || node . getWidth ( ) !== labelName . length ) {
3091
3130
return ;
3092
3131
}
@@ -3142,7 +3181,7 @@ module ts {
3142
3181
forEach ( possiblePositions , position => {
3143
3182
cancellationToken . throwIfCancellationRequested ( ) ;
3144
3183
3145
- var referenceLocation = getNodeAtPosition ( sourceFile , position ) ;
3184
+ var referenceLocation = getExactTokenAtPosition ( sourceFile , position , /*includeItemAtEndPosition*/ undefined ) ;
3146
3185
if ( ! isValidReferencePosition ( referenceLocation , searchText ) ) {
3147
3186
return ;
3148
3187
}
@@ -3194,7 +3233,7 @@ module ts {
3194
3233
forEach ( possiblePositions , position => {
3195
3234
cancellationToken . throwIfCancellationRequested ( ) ;
3196
3235
3197
- var node = getNodeAtPosition ( sourceFile , position ) ;
3236
+ var node = getExactTokenAtPosition ( sourceFile , position , n => n . kind === SyntaxKind . SuperKeyword ) ;
3198
3237
3199
3238
if ( ! node || node . kind !== SyntaxKind . SuperKeyword ) {
3200
3239
return ;
@@ -3260,7 +3299,7 @@ module ts {
3260
3299
forEach ( possiblePositions , position => {
3261
3300
cancellationToken . throwIfCancellationRequested ( ) ;
3262
3301
3263
- var node = getNodeAtPosition ( sourceFile , position ) ;
3302
+ var node = getExactTokenAtPosition ( sourceFile , position , n => n . kind === SyntaxKind . ThisKeyword ) ;
3264
3303
if ( ! node || node . kind !== SyntaxKind . ThisKeyword ) {
3265
3304
return ;
3266
3305
}
@@ -4022,7 +4061,7 @@ module ts {
4022
4061
var sourceFile = getCurrentSourceFile ( filename ) ;
4023
4062
var result : TypeScript . TextSpan [ ] = [ ] ;
4024
4063
4025
- var token = getTokenAtPosition ( sourceFile , position ) ;
4064
+ var token = getTokenContainingPosition ( sourceFile , position ) ;
4026
4065
4027
4066
if ( token . getStart ( sourceFile ) === position ) {
4028
4067
var matchKind = getMatchingTokenKind ( token ) ;
@@ -4178,7 +4217,7 @@ module ts {
4178
4217
4179
4218
// OK, we have found a match in the file. This is only an acceptable match if
4180
4219
// it is contained within a comment.
4181
- var token = getTokenAtPosition ( sourceFile , matchPosition ) ;
4220
+ var token = getTokenContainingPosition ( sourceFile , matchPosition ) ;
4182
4221
4183
4222
if ( token . getStart ( ) <= matchPosition && matchPosition < token . getEnd ( ) ) {
4184
4223
// match was within the token itself. Not in the comment. Keep searching
@@ -4306,7 +4345,7 @@ module ts {
4306
4345
fileName = TypeScript . switchToForwardSlashes ( fileName ) ;
4307
4346
var sourceFile = getSourceFile ( fileName ) ;
4308
4347
4309
- var node = getNodeAtPosition ( sourceFile , position ) ;
4348
+ var node = getExactTokenAtPosition ( sourceFile , position , n => n . kind === SyntaxKind . Identifier ) ;
4310
4349
4311
4350
// Can only rename an identifier.
4312
4351
if ( node && node . kind === SyntaxKind . Identifier ) {
0 commit comments