( content: string, offset: number, )
| 73 | } |
| 74 | |
| 75 | export function offsetToPosition( |
| 76 | content: string, |
| 77 | offset: number, |
| 78 | ): {line: number; character: number} { |
| 79 | offset = Math.min(content.length, Math.max(0, offset)); // Clamp offset to content length |
| 80 | const lineStarts = getLineStarts(content); |
| 81 | let low = 0; |
| 82 | let high = lineStarts.length - 1; |
| 83 | while (low <= high) { |
| 84 | const mid = (low + high) >>> 1; // Use bitwise shift |
| 85 | if (lineStarts[mid] <= offset) { |
| 86 | low = mid + 1; |
| 87 | } else { |
| 88 | high = mid - 1; |
| 89 | } |
| 90 | } |
| 91 | const line = high; |
| 92 | const lineStart = lineStarts[line]; |
| 93 | return { |
| 94 | line, |
| 95 | character: offset - lineStart, |
| 96 | }; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Determines whether a declaration metadata requires inline handling due to not being exported |
no test coverage detected