MCPcopy
hub / github.com/continuedev/continue / applyCodeBlock

Function applyCodeBlock

core/edit/lazy/applyCodeBlock.ts:14–63  ·  view source on GitHub ↗
(
  oldFile: string,
  newLazyFile: string,
  filename: string,
  llm: ILLM,
  abortController: AbortController,
)

Source from the content-addressed store, hash-verified

12}
13
14export async function applyCodeBlock(
15 oldFile: string,
16 newLazyFile: string,
17 filename: string,
18 llm: ILLM,
19 abortController: AbortController,
20): Promise<{
21 isInstantApply: boolean;
22 diffLinesGenerator: AsyncGenerator<DiffLine>;
23}> {
24 if (canUseInstantApply(filename)) {
25 const diffLines = await deterministicApplyLazyEdit({
26 oldFile,
27 newLazyFile,
28 filename,
29 onlyFullFileRewrite: true,
30 });
31
32 if (diffLines !== undefined) {
33 return {
34 isInstantApply: true,
35 diffLinesGenerator: generateLines(diffLines!),
36 };
37 }
38 }
39
40 // If the code block is a diff
41 if (isUnifiedDiffFormat(newLazyFile)) {
42 try {
43 const diffLines = applyUnifiedDiff(oldFile, newLazyFile);
44 return {
45 isInstantApply: true,
46 diffLinesGenerator: generateLines(diffLines!),
47 };
48 } catch (e) {
49 console.error("Failed to apply unified diff", e);
50 }
51 }
52
53 return {
54 isInstantApply: false,
55 diffLinesGenerator: streamLazyApply(
56 oldFile,
57 filename,
58 newLazyFile,
59 llm,
60 abortController,
61 ),
62 };
63}

Callers 1

Calls 7

generateLinesFunction · 0.90
isUnifiedDiffFormatFunction · 0.90
applyUnifiedDiffFunction · 0.90
streamLazyApplyFunction · 0.90
canUseInstantApplyFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected