feat: use instant property on diff manager
This commit is contained in:
parent
652f8c4c7b
commit
2f12bbdf25
5 changed files with 41 additions and 23 deletions
|
|
@ -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<DiffLine>]> {
|
||||
// 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)];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ export async function* streamLazyApply(
|
|||
filename: string,
|
||||
newCode: string,
|
||||
llm: ILLM,
|
||||
fastLlm: ILLM,
|
||||
): AsyncGenerator<DiffLine> {
|
||||
const promptFactory = lazyApplyPromptForModel(llm.model, llm.providerName);
|
||||
if (!promptFactory) {
|
||||
|
|
@ -39,7 +38,7 @@ export async function* streamLazyApply(
|
|||
oldCode,
|
||||
linesBefore,
|
||||
linesAfter,
|
||||
fastLlm,
|
||||
llm,
|
||||
)) {
|
||||
yield line;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
23
extensions/vscode/src/apply/utils.ts
Normal file
23
extensions/vscode/src/apply/utils.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { ILLM } from "core";
|
||||
import { Relace } from "core/llm/llms/Relace";
|
||||
|
||||
export const FAST_APPLY_MODELS: Record<
|
||||
ILLM["providerName"],
|
||||
Array<ILLM["model"]>
|
||||
> = {
|
||||
[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
|
||||
);
|
||||
}
|
||||
|
|
@ -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 &&
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue