MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getSnippet

Function getSnippet

src/tools/FileEditTool/utils.ts:468–493  ·  view source on GitHub ↗
(
  originalFile: string,
  oldString: string,
  newString: string,
  contextLines: number = 4,
)

Source from the content-addressed store, hash-verified

466 * @returns The snippet and the starting line number
467 */
468export function getSnippet(
469 originalFile: string,
470 oldString: string,
471 newString: string,
472 contextLines: number = 4,
473): { snippet: string; startLine: number } {
474 // Use the original algorithm from FileEditTool.tsx
475 const before = originalFile.split(oldString)[0] ?? ''
476 const replacementLine = before.split(/\r?\n/).length - 1
477 const newFileLines = applyEditToFile(
478 originalFile,
479 oldString,
480 newString,
481 ).split(/\r?\n/)
482
483 // Calculate the start and end line numbers for the snippet
484 const startLine = Math.max(0, replacementLine - contextLines)
485 const endLine =
486 replacementLine + contextLines + newString.split(/\r?\n/).length
487
488 // Get snippet
489 const snippetLines = newFileLines.slice(startLine, endLine)
490 const snippet = snippetLines.join('\n')
491
492 return { snippet, startLine: startLine + 1 }
493}
494
495export function getEditsForPatch(patch: StructuredPatchHunk[]): FileEdit[] {
496 return patch.map(hunk => {

Callers

nothing calls this directly

Calls 2

applyEditToFileFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected