Skip to content

Commit c37c811

Browse files
authored
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
1 parent e8dd689 commit c37c811

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

core/nextEdit/templating/NextEditPromptEngine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const NEXT_EDIT_MODEL_TEMPLATES: Record<NEXT_EDIT_MODELS, NextEditTemplate> = {
4646
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`,
4747
},
4848
instinct: {
49-
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:`,
49+
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:`,
5050
},
5151
};
5252

core/nextEdit/templating/NextEditPromptEngine.vitest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("NextEditPromptEngine", () => {
106106
expect(result.prompt.content).toContain(INSTINCT_USER_PROMPT_PREFIX);
107107
expect(result.prompt.content).toContain("### Context:");
108108
expect(result.prompt.content).toContain("### User Edits:");
109-
expect(result.prompt.content).toContain("### User Excerpts:");
109+
expect(result.prompt.content).toContain("### User Excerpt:");
110110

111111
expect(result.userEdits).toBe(instinctCtx.editDiffHistory);
112112
expect(result.userExcerpts).toContain(INSTINCT_USER_CURSOR_IS_HERE_TOKEN);

extensions/vscode/src/activation/SelectionChangeManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ export class SelectionChangeManager {
150150
);
151151
}
152152

153+
/**
154+
* Updates this class's usingFullFileDiff flag.
155+
* @param usingFullFileDiff New value to set.
156+
*/
157+
public updateUsingFullFileDiff(usingFullFileDiff: boolean) {
158+
this.usingFullFileDiff = usingFullFileDiff;
159+
}
160+
153161
public documentChanged(): void {
154162
this.isTypingSession = true;
155163
this.lastDocumentChangeTime = Date.now();

extensions/vscode/src/autocomplete/completionProvider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ export class ContinueCompletionProvider
132132
return config.selectedModelByRole.rerank ?? undefined;
133133
}
134134

135+
/**
136+
* Updates this class and the prefetch queue's usingFullFileDiff flag.
137+
* @param usingFullFileDiff New value to set.
138+
*/
139+
public updateUsingFullFileDiff(usingFullFileDiff: boolean) {
140+
this.usingFullFileDiff = usingFullFileDiff;
141+
this.prefetchQueue.initialize(this.usingFullFileDiff);
142+
}
143+
135144
public async provideInlineCompletionItems(
136145
document: vscode.TextDocument,
137146
position: vscode.Position,

extensions/vscode/src/extension/VsCodeExtension.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { VsCodeMessenger } from "./VsCodeMessenger";
4444

4545
import { getAst } from "core/autocomplete/util/ast";
4646
import { modelSupportsNextEdit } from "core/llm/autodetect";
47+
import { NEXT_EDIT_MODELS } from "core/llm/constants";
4748
import { DocumentHistoryTracker } from "core/nextEdit/DocumentHistoryTracker";
4849
import { NextEditProvider } from "core/nextEdit/NextEditProvider";
4950
import { isNextEditTest } from "core/nextEdit/utils";
@@ -103,6 +104,32 @@ export class VsCodeExtension {
103104
this.extensionContext = context;
104105
this.windowId = uuidv4();
105106

107+
// Check if model supports next edit to determine if we should use full file diff.
108+
const getUsingFullFileDiff = async () => {
109+
const { config } = await this.configHandler.loadConfig();
110+
const autocompleteModel = config?.selectedModelByRole.autocomplete;
111+
112+
if (!autocompleteModel) {
113+
return false;
114+
}
115+
116+
if (
117+
!modelSupportsNextEdit(
118+
autocompleteModel.capabilities,
119+
autocompleteModel.model,
120+
autocompleteModel.title,
121+
)
122+
) {
123+
return false;
124+
}
125+
126+
if (autocompleteModel.model.includes(NEXT_EDIT_MODELS.INSTINCT)) {
127+
return false;
128+
}
129+
130+
return true;
131+
};
132+
106133
const usingFullFileDiff = true;
107134
const selectionManager = SelectionChangeManager.getInstance();
108135
selectionManager.initialize(this.ide, usingFullFileDiff);
@@ -190,7 +217,11 @@ export class VsCodeExtension {
190217
),
191218
);
192219

193-
void this.configHandler.loadConfig().then(({ config }) => {
220+
void this.configHandler.loadConfig().then(async ({ config }) => {
221+
const shouldUseFullFileDiff = await getUsingFullFileDiff();
222+
this.completionProvider.updateUsingFullFileDiff(shouldUseFullFileDiff);
223+
selectionManager.updateUsingFullFileDiff(shouldUseFullFileDiff);
224+
194225
const { verticalDiffCodeLens } = registerAllCodeLensProviders(
195226
context,
196227
this.verticalDiffManager.fileUriToCodeLens,
@@ -203,7 +234,12 @@ export class VsCodeExtension {
203234

204235
this.configHandler.onConfigUpdate(
205236
async ({ config: newConfig, configLoadInterrupted }) => {
237+
const shouldUseFullFileDiff = await getUsingFullFileDiff();
238+
this.completionProvider.updateUsingFullFileDiff(shouldUseFullFileDiff);
239+
selectionManager.updateUsingFullFileDiff(shouldUseFullFileDiff);
240+
206241
const autocompleteModel = newConfig?.selectedModelByRole.autocomplete;
242+
207243
if (
208244
(autocompleteModel &&
209245
modelSupportsNextEdit(

0 commit comments

Comments
 (0)