MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / applyEdits

Function applyEdits

src/extraction/languages/pascal-preparse.ts:1034–1049  ·  view source on GitHub ↗

* `s` with every `[from, to)` range in `ranges` blanked to spaces, newlines kept, and every `[from, to, word]` in * `words` (which overlap neither each other nor a range) written over by its word, padded with spaces. Ranges may * come in any order and overlap.

(s: string, ranges: readonly number[], words: ReadonlyArray<readonly [number, number, string]>)

Source from the content-addressed store, hash-verified

1032 * come in any order and overlap.
1033 */
1034function applyEdits(s: string, ranges: readonly number[], words: ReadonlyArray<readonly [number, number, string]>): string {
1035 if (ranges.length === 0 && words.length === 0) return s;
1036 const edits: Array<readonly [number, number, string]> = words.slice();
1037 for (let r = 0; r < ranges.length; r += 2) edits.push([ranges[r]!, ranges[r + 1]!, '']);
1038 edits.sort((a, b) => a[0] - b[0]);
1039 let out = '';
1040 let last = 0;
1041 for (const [start, to, word] of edits) {
1042 const from = Math.max(start, last);
1043 if (to <= from) continue;
1044 const written = from === start && word.length <= to - from ? word : '';
1045 out += s.slice(last, from) + written + s.slice(from + written.length, to).replace(/[^\r\n]/g, ' ');
1046 last = to;
1047 }
1048 return out + s.slice(last);
1049}
1050
1051/** The start of the `class` word before index `i`, past whitespace, or -1. */
1052function classBefore(s: string, i: number): number {

Callers 8

preParsePascalFunction · 0.85
editJsonFunction · 0.85
writeMcpEntryFunction · 0.85
removeMcpEntryAtFunction · 0.85
writeMcpEntryFunction · 0.85
removeMcpEntryFunction · 0.85
writeMcpEntryFunction · 0.85
removeMcpEntryFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected