(content: string, range: Range)
| 1 | import { Position, Range } from "../index.js"; |
| 2 | |
| 3 | export function getRangeInString(content: string, range: Range): string { |
| 4 | const lines = content.split("\n"); |
| 5 | |
| 6 | if (range.start.line === range.end.line) { |
| 7 | return ( |
| 8 | lines[range.start.line]?.substring( |
| 9 | range.start.character, |
| 10 | range.end.character, |
| 11 | ) ?? "" |
| 12 | ); |
| 13 | } |
| 14 | |
| 15 | const firstLine = |
| 16 | lines[range.start.line]?.substring( |
| 17 | range.start.character, |
| 18 | lines[range.start.line].length, |
| 19 | ) ?? ""; |
| 20 | const middleLines = lines.slice(range.start.line + 1, range.end.line); |
| 21 | const lastLine = |
| 22 | lines[range.end.line]?.substring(0, range.end.character) ?? ""; |
| 23 | |
| 24 | return [firstLine, ...middleLines, lastLine].join("\n"); |
| 25 | } |
| 26 | |
| 27 | export function intersection(a: Range, b: Range): Range | null { |
| 28 | const startLine = Math.max(a.start.line, b.start.line); |
no outgoing calls
no test coverage detected