File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
packages/typescript-plugin/src Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,13 @@ export function decorateGetDefinition(
2323 return def ;
2424 }
2525
26- const textSpan = snapshotManager
26+ let textSpan = snapshotManager
2727 . get ( def . fileName )
2828 ?. getOriginalTextSpan ( def . textSpan ) ;
2929 if ( ! textSpan ) {
30- return undefined ;
30+ // Unmapped positions are for example the default export.
31+ // Fall back to the start of the file to at least go to the correct file.
32+ textSpan = { start : 0 , length : 1 } ;
3133 }
3234 return {
3335 ...def ,
Original file line number Diff line number Diff line change @@ -78,7 +78,12 @@ export class SourceMapper {
7878 }
7979
8080 const closestMatch = binarySearch ( lineMap , position . character , 0 ) ;
81- const { 2 : line , 3 : character } = lineMap [ closestMatch ] ;
81+ const match = lineMap [ closestMatch ] ;
82+ if ( ! match ) {
83+ return { line : - 1 , character : - 1 } ;
84+ }
85+
86+ const { 2 : line , 3 : character } = match ;
8287 return { line, character } ;
8388 }
8489
@@ -90,7 +95,12 @@ export class SourceMapper {
9095 }
9196
9297 const closestMatch = binarySearch ( lineMap , position . character , 0 ) ;
93- const { 1 : line , 2 : character } = lineMap [ closestMatch ] ;
98+ const match = lineMap [ closestMatch ] ;
99+ if ( ! match ) {
100+ return { line : - 1 , character : - 1 } ;
101+ }
102+
103+ const { 1 : line , 2 : character } = match ;
94104 return { line, character } ;
95105 }
96106
You can’t perform that action at this time.
0 commit comments