diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index a8f8b32b9..d8ca2226d 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -46,7 +46,7 @@ const NEXT_EDIT_MODEL_TEMPLATES: Record = { 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:`, }, }; diff --git a/core/nextEdit/templating/NextEditPromptEngine.vitest.ts b/core/nextEdit/templating/NextEditPromptEngine.vitest.ts index 0b90ecda3..fd9d7d9e7 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.vitest.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.vitest.ts @@ -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); diff --git a/extensions/vscode/src/activation/SelectionChangeManager.ts b/extensions/vscode/src/activation/SelectionChangeManager.ts index d8851ce52..100a373be 100644 --- a/extensions/vscode/src/activation/SelectionChangeManager.ts +++ b/extensions/vscode/src/activation/SelectionChangeManager.ts @@ -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(); diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index db420924c..f081d2430 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -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, diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index dba2f468b..943562e80 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -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(