( oldFile: string, newLazyFile: string, filename: string, llm: ILLM, abortController: AbortController, )
| 12 | } |
| 13 | |
| 14 | export 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 | } |
no test coverage detected