feat: check for model before using full file diffs (#7222)
* fix: Excerpts -> Excerpt * fix: test for Excerpt instead of Excerpts * feat: add a public method to update usingFullFIleDiff * feat: use full file diff for mercury only * chore: remove console.log * docs: add jsdocs * refactor: use enums and const
This commit is contained in:
parent
e8dd689aeb
commit
c37c8111f7
5 changed files with 56 additions and 3 deletions
|
|
@ -46,7 +46,7 @@ const NEXT_EDIT_MODEL_TEMPLATES: Record<NEXT_EDIT_MODELS, NextEditTemplate> = {
|
|||
template: `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN}\n{{{recentlyViewedCodeSnippets}}}\n${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE}\n\n${MERCURY_CURRENT_FILE_CONTENT_OPEN}\n{{{currentFileContent}}}\n${MERCURY_CURRENT_FILE_CONTENT_CLOSE}\n\n${MERCURY_EDIT_DIFF_HISTORY_OPEN}\n{{{editDiffHistory}}}\n${MERCURY_EDIT_DIFF_HISTORY_CLOSE}\n`,
|
||||
},
|
||||
instinct: {
|
||||
template: `${INSTINCT_USER_PROMPT_PREFIX}\n\n### Context:\n{{{contextSnippets}}}\n\n### User Edits:\n\n{{{editDiffHistory}}}\n\n### User Excerpts:\n{{{currentFilePath}}}\n\n{{{currentFileContent}}}\`\`\`\n### Response:`,
|
||||
template: `${INSTINCT_USER_PROMPT_PREFIX}\n\n### Context:\n{{{contextSnippets}}}\n\n### User Edits:\n\n{{{editDiffHistory}}}\n\n### User Excerpt:\n{{{currentFilePath}}}\n\n{{{currentFileContent}}}\`\`\`\n### Response:`,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ describe("NextEditPromptEngine", () => {
|
|||
expect(result.prompt.content).toContain(INSTINCT_USER_PROMPT_PREFIX);
|
||||
expect(result.prompt.content).toContain("### Context:");
|
||||
expect(result.prompt.content).toContain("### User Edits:");
|
||||
expect(result.prompt.content).toContain("### User Excerpts:");
|
||||
expect(result.prompt.content).toContain("### User Excerpt:");
|
||||
|
||||
expect(result.userEdits).toBe(instinctCtx.editDiffHistory);
|
||||
expect(result.userExcerpts).toContain(INSTINCT_USER_CURSOR_IS_HERE_TOKEN);
|
||||
|
|
|
|||
|
|
@ -150,6 +150,14 @@ export class SelectionChangeManager {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this class's usingFullFileDiff flag.
|
||||
* @param usingFullFileDiff New value to set.
|
||||
*/
|
||||
public updateUsingFullFileDiff(usingFullFileDiff: boolean) {
|
||||
this.usingFullFileDiff = usingFullFileDiff;
|
||||
}
|
||||
|
||||
public documentChanged(): void {
|
||||
this.isTypingSession = true;
|
||||
this.lastDocumentChangeTime = Date.now();
|
||||
|
|
|
|||
|
|
@ -132,6 +132,15 @@ export class ContinueCompletionProvider
|
|||
return config.selectedModelByRole.rerank ?? undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this class and the prefetch queue's usingFullFileDiff flag.
|
||||
* @param usingFullFileDiff New value to set.
|
||||
*/
|
||||
public updateUsingFullFileDiff(usingFullFileDiff: boolean) {
|
||||
this.usingFullFileDiff = usingFullFileDiff;
|
||||
this.prefetchQueue.initialize(this.usingFullFileDiff);
|
||||
}
|
||||
|
||||
public async provideInlineCompletionItems(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import { VsCodeMessenger } from "./VsCodeMessenger";
|
|||
|
||||
import { getAst } from "core/autocomplete/util/ast";
|
||||
import { modelSupportsNextEdit } from "core/llm/autodetect";
|
||||
import { NEXT_EDIT_MODELS } from "core/llm/constants";
|
||||
import { DocumentHistoryTracker } from "core/nextEdit/DocumentHistoryTracker";
|
||||
import { NextEditProvider } from "core/nextEdit/NextEditProvider";
|
||||
import { isNextEditTest } from "core/nextEdit/utils";
|
||||
|
|
@ -103,6 +104,32 @@ export class VsCodeExtension {
|
|||
this.extensionContext = context;
|
||||
this.windowId = uuidv4();
|
||||
|
||||
// Check if model supports next edit to determine if we should use full file diff.
|
||||
const getUsingFullFileDiff = async () => {
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
const autocompleteModel = config?.selectedModelByRole.autocomplete;
|
||||
|
||||
if (!autocompleteModel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!modelSupportsNextEdit(
|
||||
autocompleteModel.capabilities,
|
||||
autocompleteModel.model,
|
||||
autocompleteModel.title,
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (autocompleteModel.model.includes(NEXT_EDIT_MODELS.INSTINCT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const usingFullFileDiff = true;
|
||||
const selectionManager = SelectionChangeManager.getInstance();
|
||||
selectionManager.initialize(this.ide, usingFullFileDiff);
|
||||
|
|
@ -190,7 +217,11 @@ export class VsCodeExtension {
|
|||
),
|
||||
);
|
||||
|
||||
void this.configHandler.loadConfig().then(({ config }) => {
|
||||
void this.configHandler.loadConfig().then(async ({ config }) => {
|
||||
const shouldUseFullFileDiff = await getUsingFullFileDiff();
|
||||
this.completionProvider.updateUsingFullFileDiff(shouldUseFullFileDiff);
|
||||
selectionManager.updateUsingFullFileDiff(shouldUseFullFileDiff);
|
||||
|
||||
const { verticalDiffCodeLens } = registerAllCodeLensProviders(
|
||||
context,
|
||||
this.verticalDiffManager.fileUriToCodeLens,
|
||||
|
|
@ -203,7 +234,12 @@ export class VsCodeExtension {
|
|||
|
||||
this.configHandler.onConfigUpdate(
|
||||
async ({ config: newConfig, configLoadInterrupted }) => {
|
||||
const shouldUseFullFileDiff = await getUsingFullFileDiff();
|
||||
this.completionProvider.updateUsingFullFileDiff(shouldUseFullFileDiff);
|
||||
selectionManager.updateUsingFullFileDiff(shouldUseFullFileDiff);
|
||||
|
||||
const autocompleteModel = newConfig?.selectedModelByRole.autocomplete;
|
||||
|
||||
if (
|
||||
(autocompleteModel &&
|
||||
modelSupportsNextEdit(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue