diff --git a/core/nextEdit/NextEditProvider.ts b/core/nextEdit/NextEditProvider.ts index 8f9f55527..67f7d1cf0 100644 --- a/core/nextEdit/NextEditProvider.ts +++ b/core/nextEdit/NextEditProvider.ts @@ -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, diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index 7d4eb5b80..cf7748c17 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -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, diff --git a/core/nextEdit/templating/model1.ts b/core/nextEdit/templating/model1.ts index 3a7a617c0..ad547b549 100644 --- a/core/nextEdit/templating/model1.ts +++ b/core/nextEdit/templating/model1.ts @@ -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");