MCPcopy
hub / github.com/srcbookdev/srcbook / mapCMLocationToTsServer

Function mapCMLocationToTsServer

packages/web/src/components/cells/util.ts:8–25  ·  view source on GitHub ↗
(
  code: string,
  cmPosition: number,
)

Source from the content-addressed store, hash-verified

6}
7
8export 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}

Callers 3

onGetDefinitionContentsFunction · 0.90
mountFunction · 0.90
getCompletionsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected