From 2f12bbdf25b1ff189a88d37bfba4f3bfe7f2f3bc Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 11 Apr 2025 12:32:55 -0700 Subject: [PATCH] feat: use `instant` property on diff manager --- core/edit/lazy/applyCodeBlock.ts | 30 +++++++++---------- core/edit/lazy/streamLazyApply.ts | 3 +- extensions/vscode/src/apply/ApplyManager.ts | 6 +--- extensions/vscode/src/apply/utils.ts | 23 ++++++++++++++ .../vscode/src/diff/vertical/manager.ts | 2 ++ 5 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 extensions/vscode/src/apply/utils.ts diff --git a/core/edit/lazy/applyCodeBlock.ts b/core/edit/lazy/applyCodeBlock.ts index f30751d70..d2323aca3 100644 --- a/core/edit/lazy/applyCodeBlock.ts +++ b/core/edit/lazy/applyCodeBlock.ts @@ -3,9 +3,8 @@ import { generateLines } from "../../diff/util"; import { supportedLanguages } from "../../util/treeSitter"; import { getUriFileExtension } from "../../util/uri"; -import { deterministicApplyLazyEdit } from "./deterministic"; import { streamLazyApply } from "./streamLazyApply"; -import { isUnifiedDiffFormat, applyUnifiedDiff } from "./unifiedDiffApply"; +import { applyUnifiedDiff, isUnifiedDiffFormat } from "./unifiedDiffApply"; function canUseInstantApply(filename: string) { const fileExtension = getUriFileExtension(filename); @@ -17,22 +16,21 @@ export async function applyCodeBlock( newFile: string, filename: string, llm: ILLM, - fastLlm: ILLM, ): Promise<[boolean, AsyncGenerator]> { // This was buggy, removed for now, maybe forever - if (false && canUseInstantApply(filename)) { - const diffLines = await deterministicApplyLazyEdit( - oldFile, - newFile, - filename, - ); + // if (canUseInstantApply(filename)) { + // const diffLines = await deterministicApplyLazyEdit( + // oldFile, + // newFile, + // filename, + // ); - // Fall back to LLM method if we couldn't apply deterministically - if (diffLines !== undefined) { - const diffGenerator = generateLines(diffLines!); - return [true, diffGenerator]; - } - } + // // Fall back to LLM method if we couldn't apply deterministically + // if (diffLines !== undefined) { + // const diffGenerator = generateLines(diffLines!); + // return [true, diffGenerator]; + // } + // } // If the code block is a diff if (isUnifiedDiffFormat(newFile)) { @@ -45,5 +43,5 @@ export async function applyCodeBlock( } } - return [false, streamLazyApply(oldFile, filename, newFile, llm, fastLlm)]; + return [false, streamLazyApply(oldFile, filename, newFile, llm)]; } diff --git a/core/edit/lazy/streamLazyApply.ts b/core/edit/lazy/streamLazyApply.ts index 982e263e8..ce7af0ef7 100644 --- a/core/edit/lazy/streamLazyApply.ts +++ b/core/edit/lazy/streamLazyApply.ts @@ -16,7 +16,6 @@ export async function* streamLazyApply( filename: string, newCode: string, llm: ILLM, - fastLlm: ILLM, ): AsyncGenerator { const promptFactory = lazyApplyPromptForModel(llm.model, llm.providerName); if (!promptFactory) { @@ -39,7 +38,7 @@ export async function* streamLazyApply( oldCode, linesBefore, linesAfter, - fastLlm, + llm, )) { yield line; } diff --git a/extensions/vscode/src/apply/ApplyManager.ts b/extensions/vscode/src/apply/ApplyManager.ts index 9a5a470f4..2bf829a3c 100644 --- a/extensions/vscode/src/apply/ApplyManager.ts +++ b/extensions/vscode/src/apply/ApplyManager.ts @@ -1,5 +1,4 @@ import { ConfigHandler } from "core/config/ConfigHandler"; -import { getModelByRole } from "core/config/util"; import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock"; import { getUriPathBasename } from "core/util/uri"; import * as vscode from "vscode"; @@ -16,7 +15,7 @@ export interface ApplyToFileOptions { } /** - * Handles applying text/code to files in VS Code, including diff generation and streaming + * Handles applying text/code to files including diff generation and streaming */ export class ApplyManager { constructor( @@ -106,14 +105,11 @@ export class ApplyManager { return; } - const fastLlm = getModelByRole(config, "repoMapFileSelection") ?? llm; - const [instant, diffLines] = await applyCodeBlock( editor.document.getText(), text, getUriPathBasename(editor.document.uri.toString()), llm, - fastLlm, ); if (instant) { diff --git a/extensions/vscode/src/apply/utils.ts b/extensions/vscode/src/apply/utils.ts new file mode 100644 index 000000000..e0f9979e1 --- /dev/null +++ b/extensions/vscode/src/apply/utils.ts @@ -0,0 +1,23 @@ +import { ILLM } from "core"; +import { Relace } from "core/llm/llms/Relace"; + +export const FAST_APPLY_MODELS: Record< + ILLM["providerName"], + Array +> = { + [Relace.providerName]: ["Fast-Apply"], +}; + +/** + * Checks against model names, which can include proxy prefixes + * such as `continuedev/hub` + * @param llm + * @returns + */ +export function isFastApplyModel(llm: ILLM): boolean { + const fastModelsForProvider = FAST_APPLY_MODELS[llm.providerName]; + return ( + fastModelsForProvider?.some((fastModel) => llm.model.includes(fastModel)) ?? + false + ); +} diff --git a/extensions/vscode/src/diff/vertical/manager.ts b/extensions/vscode/src/diff/vertical/manager.ts index 48741a142..f5496fe2f 100644 --- a/extensions/vscode/src/diff/vertical/manager.ts +++ b/extensions/vscode/src/diff/vertical/manager.ts @@ -6,6 +6,7 @@ import { getMarkdownLanguageTagForFile } from "core/util"; import * as URI from "uri-js"; import * as vscode from "vscode"; +import { isFastApplyModel } from "../../apply/utils"; import EditDecorationManager from "../../quickEdit/EditDecorationManager"; import { handleLLMError } from "../../util/errorHandling"; import { VsCodeWebviewProtocol } from "../../webviewProtocol"; @@ -345,6 +346,7 @@ export class VerticalDiffManager { startLine, endLine, { + instant: isFastApplyModel(llm), input, onStatusUpdate: (status, numDiffs, fileContent) => streamId &&