use margin constant to calculate edit range
This commit is contained in:
parent
e10162594a
commit
3cbc82d736
3 changed files with 30 additions and 10 deletions
|
|
@ -1 +1,3 @@
|
|||
export const IS_NEXT_EDIT_ACTIVE = false;
|
||||
export const NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN = 5;
|
||||
export const NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN = 5;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import { IDE, Position } from "../..";
|
||||
import { SnippetPayload } from "../../autocomplete/snippets";
|
||||
import { HelperVars } from "../../autocomplete/util/HelperVars";
|
||||
import {
|
||||
NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
|
||||
NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN,
|
||||
} from "../constants";
|
||||
|
||||
export type Prompt = SystemPrompt | UserPrompt;
|
||||
|
||||
|
|
@ -185,7 +189,7 @@ export async function renderFineTunedBasicUserPrompt(
|
|||
|
||||
function insertPins(lines: string[], cursorPos: Position) {
|
||||
const a = insertCursorPin(lines, cursorPos);
|
||||
const b = insertEditableRegionPinsWithStaticRange(a, cursorPos, 5, 5);
|
||||
const b = insertEditableRegionPinsWithStaticRange(a, cursorPos);
|
||||
return b.join("\n");
|
||||
}
|
||||
|
||||
|
|
@ -209,18 +213,19 @@ function insertCursorPin(lines: string[], cursorPos: Position) {
|
|||
function insertEditableRegionPinsWithStaticRange(
|
||||
lines: string[],
|
||||
cursorPos: Position,
|
||||
marginTop: number,
|
||||
marginBottom: number,
|
||||
) {
|
||||
if (cursorPos.line < 0 || cursorPos.line >= lines.length) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
// Ensure editable regions are within bounds.
|
||||
const editableRegionStart = Math.max(cursorPos.line - marginTop, 0);
|
||||
const editableRegionStart = Math.max(
|
||||
cursorPos.line - NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN,
|
||||
0,
|
||||
);
|
||||
const editableRegionEnd = Math.min(
|
||||
cursorPos.line + marginBottom,
|
||||
lines.length - 1,
|
||||
cursorPos.line + NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
|
||||
lines.length - 1, // Line numbers should be zero-indexed.
|
||||
);
|
||||
|
||||
const instrumentedLines = [
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ import { EXTENSION_NAME } from "core/control-plane/env";
|
|||
import * as vscode from "vscode";
|
||||
|
||||
import { myersDiff } from "core/diff/myers";
|
||||
import {
|
||||
NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
|
||||
NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN,
|
||||
} from "core/nextEdit/constants";
|
||||
import { getRenderableDiff } from "core/nextEdit/diff/diff";
|
||||
import { SyntaxHighlighter } from "core/syntaxHighlighting/SyntaxHighlighter";
|
||||
import { getThemeString } from "../util/getTheme";
|
||||
|
|
@ -197,8 +201,14 @@ export class NextEditWindowManager {
|
|||
|
||||
// Get current cursor position.
|
||||
const position = editor.selection.active;
|
||||
const startPos = Math.max(position.line - 5, 0);
|
||||
const endPos = Math.min(position.line + 5, editor.document.lineCount - 1);
|
||||
const startPos = Math.max(
|
||||
position.line - NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN,
|
||||
0,
|
||||
);
|
||||
const endPos = Math.min(
|
||||
position.line + NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
|
||||
editor.document.lineCount - 1,
|
||||
);
|
||||
const oldEditRangeSlice = editor.document
|
||||
.getText()
|
||||
.split("\n")
|
||||
|
|
@ -305,10 +315,13 @@ export class NextEditWindowManager {
|
|||
);
|
||||
} else {
|
||||
// Define the editable region.
|
||||
const editableRegionStartLine = Math.max(0, position.line - 5);
|
||||
const editableRegionStartLine = Math.max(
|
||||
0,
|
||||
position.line - NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN,
|
||||
);
|
||||
const editableRegionEndLine = Math.min(
|
||||
editor.document.lineCount - 1,
|
||||
position.line + 5,
|
||||
position.line + NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
|
||||
);
|
||||
const startPos = new vscode.Position(editableRegionStartLine, 0);
|
||||
const endPosChar = editor.document.lineAt(editableRegionEndLine).text
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue