refactor: pass window range as well

This commit is contained in:
Jacob Kim 2025-08-08 12:29:37 -07:00
parent 7106c9dd15
commit fc08da2c29
3 changed files with 27 additions and 4 deletions

View file

@ -559,11 +559,30 @@ export class NextEditProvider {
currentFilePath: helper.filepath,
};
} else if (modelName.includes("model-1")) {
// Calculate the window around the cursor position (25 lines above and below).
const windowStart = Math.max(0, helper.pos.line - 25);
const windowEnd = Math.min(
helper.fileLines.length - 1,
helper.pos.line + 25,
);
// The editable region is defined as: cursor line - 1 to cursor line + 5 (inclusive).
const actualEditableStart = Math.max(0, helper.pos.line - 1);
const actualEditableEnd = Math.min(
helper.fileLines.length - 1,
helper.pos.line + 5,
);
// Ensure editable region boundaries are within the window.
const adjustedEditableStart = Math.max(windowStart, actualEditableStart);
const adjustedEditableEnd = Math.min(windowEnd, actualEditableEnd);
ctx = {
contextSnippets: this.autocompleteContext,
currentFileContent: helper.fileContents,
editableRegionStartLine,
editableRegionEndLine,
windowStart,
windowEnd,
adjustedEditableStart,
adjustedEditableEnd,
editDiffHistory: this.diffContext,
currentFilePath: helper.filepath,
languageShorthand: helper.lang.name,

View file

@ -132,6 +132,8 @@ export async function renderPrompt(
contextSnippets: contextSnippetsBlock(ctx.contextSnippets),
currentFileContent: model1CurrentFileContentBlock(
ctx.currentFileContent,
ctx.windowStart,
ctx.windowEnd,
ctx.editableRegionStartLine,
ctx.editableRegionEndLine,
helper.pos,

View file

@ -39,6 +39,8 @@ export function contextSnippetsBlock(contextSnippets: string) {
export function currentFileContentBlock(
currentFileContent: string,
windowStart: number,
windowEnd: number,
editableRegionStartLine: number,
editableRegionEndLine: number,
cursorPosition: Position,
@ -52,14 +54,14 @@ export function currentFileContentBlock(
);
const instrumentedLines = [
...insertedCursorLines.slice(0, editableRegionStartLine),
...insertedCursorLines.slice(windowStart, editableRegionStartLine),
MODEL_1_EDITABLE_REGION_START_TOKEN,
...insertedCursorLines.slice(
editableRegionStartLine,
editableRegionEndLine + 1,
),
MODEL_1_EDITABLE_REGION_END_TOKEN,
...insertedCursorLines.slice(editableRegionEndLine + 1),
...insertedCursorLines.slice(editableRegionEndLine + 1, windowEnd + 1),
];
return instrumentedLines.join("\n");