( code: string, cmPosition: number, )
| 6 | } |
| 7 | |
| 8 | export function mapCMLocationToTsServer( |
| 9 | code: string, |
| 10 | cmPosition: number, |
| 11 | ): { line: number; offset: number } { |
| 12 | const lines = code.split('\n'); |
| 13 | let remainingPosition = cmPosition; |
| 14 | let lineIndex = 0; |
| 15 | |
| 16 | while (lineIndex < lines.length && remainingPosition > (lines[lineIndex]?.length ?? 0)) { |
| 17 | remainingPosition -= (lines[lineIndex]?.length ?? 0) + 1; // +1 for newline character |
| 18 | lineIndex++; |
| 19 | } |
| 20 | |
| 21 | return { |
| 22 | line: lineIndex + 1, |
| 23 | offset: remainingPosition, |
| 24 | }; |
| 25 | } |
no outgoing calls
no test coverage detected