MCPcopy Index your code
hub / github.com/continuedev/continue / findHunkInSource

Function findHunkInSource

core/edit/lazy/unifiedDiffApply.ts:136–160  ·  view source on GitHub ↗

* Searches for an occurrence of the block of lines (the “before” block) in sourceLines, * starting at startIndex. Comparison is done by checking if the lines are exactly equal, * or if their trimmed versions are equal. * * Returns the index in sourceLines where the block begins, or -1 if no matc

(
  sourceLines: string[],
  hunkBeforeLines: string[],
  startIndex: number,
)

Source from the content-addressed store, hash-verified

134 * Returns the index in sourceLines where the block begins, or -1 if no match is found.
135 */
136function findHunkInSource(
137 sourceLines: string[],
138 hunkBeforeLines: string[],
139 startIndex: number,
140): number {
141 for (
142 let i = startIndex;
143 i <= sourceLines.length - hunkBeforeLines.length;
144 i++
145 ) {
146 let match = true;
147 for (let j = 0; j < hunkBeforeLines.length; j++) {
148 const sl = sourceLines[i + j];
149 const hl = hunkBeforeLines[j];
150 if (!linesMatch(sl, hl)) {
151 match = false;
152 break;
153 }
154 }
155 if (match) {
156 return i;
157 }
158 }
159 return -1;
160}
161
162/**
163 * Returns true if the two lines are either exactly equal or equal after trimming whitespace and tabs.

Callers 1

applyUnifiedDiffFunction · 0.85

Calls 1

linesMatchFunction · 0.70

Tested by

no test coverage detected