MCPcopy Create free account
hub / github.com/continuedev/continue / getRangeInString

Function getRangeInString

core/util/ranges.ts:3–25  ·  view source on GitHub ↗
(content: string, range: Range)

Source from the content-addressed store, hash-verified

1import { Position, Range } from "../index.js";
2
3export 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
27export function intersection(a: Range, b: Range): Range | null {
28 const startLine = Math.max(a.start.line, b.start.line);

Callers 2

ranges.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected