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

Function applyEdits

src/extraction/languages/pascal-preparse.ts:964–979  ·  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

962 * come in any order and overlap.
963 */
964function applyEdits(s: string, ranges: readonly number[], words: ReadonlyArray<readonly [number, number, string]>): string {
965 if (ranges.length === 0 && words.length === 0) return s;
966 const edits: Array<readonly [number, number, string]> = words.slice();
967 for (let r = 0; r < ranges.length; r += 2) edits.push([ranges[r]!, ranges[r + 1]!, '']);
968 edits.sort((a, b) => a[0] - b[0]);
969 let out = '';
970 let last = 0;
971 for (const [start, to, word] of edits) {
972 const from = Math.max(start, last);
973 if (to <= from) continue;
974 const written = from === start && word.length <= to - from ? word : '';
975 out += s.slice(last, from) + written + s.slice(from + written.length, to).replace(/[^\r\n]/g, ' ');
976 last = to;
977 }
978 return out + s.slice(last);
979}
980
981/** The start of the `class` word before index `i`, past whitespace, or -1. */
982function 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