Skip to content

Commit e8de12e

Browse files
authored
Merge pull request #7107 from continuedev/jacob/con-3358
fix: prompt building
2 parents 7baa08f + db14da1 commit e8de12e

19 files changed

Lines changed: 414 additions & 270 deletions

core/llm/autodetect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function isProviderHandlesTemplatingOrNoTemplateTypeRequired(
178178
// update core/nextEdit/templating/NextEditPromptEngine.ts as well.
179179
const MODEL_SUPPORTS_NEXT_EDIT: string[] = [
180180
NEXT_EDIT_MODELS.MERCURY_CODER_NEXTEDIT,
181-
NEXT_EDIT_MODELS.MODEL_1,
181+
NEXT_EDIT_MODELS.INSTINCT,
182182
];
183183

184184
function modelSupportsNextEdit(

core/llm/autodetect.vitest.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ describe("modelSupportsNextEdit", () => {
245245
).toBe(true);
246246
});
247247

248-
it("should return true for model-1", () => {
249-
expect(modelSupportsNextEdit(undefined, "model-1", undefined)).toBe(true);
248+
it("should return true for instinct", () => {
249+
expect(modelSupportsNextEdit(undefined, "instinct", undefined)).toBe(
250+
true,
251+
);
250252
});
251253

252254
it("should return true when model contains supported model name as substring", () => {
@@ -269,9 +271,9 @@ describe("modelSupportsNextEdit", () => {
269271
).toBe(true);
270272
});
271273

272-
it("should return true when title contains model-1", () => {
274+
it("should return true when title contains instinct", () => {
273275
expect(
274-
modelSupportsNextEdit(undefined, "some-model", "model-1 deployment"),
276+
modelSupportsNextEdit(undefined, "some-model", "instinct deployment"),
275277
).toBe(true);
276278
});
277279

@@ -317,7 +319,7 @@ describe("modelSupportsNextEdit", () => {
317319

318320
it("should handle case sensitivity correctly", () => {
319321
expect(
320-
modelSupportsNextEdit(undefined, "MERCURY-CODER-NEXTEDIT", "MODEL-1"),
322+
modelSupportsNextEdit(undefined, "MERCURY-CODER-NEXTEDIT", "instinct"),
321323
).toBe(true);
322324
});
323325

core/llm/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export enum LLMConfigurationStatuses {
2121

2222
export enum NEXT_EDIT_MODELS {
2323
MERCURY_CODER_NEXTEDIT = "mercury-coder-nextedit",
24-
MODEL_1 = "model-1",
24+
INSTINCT = "instinct",
2525
}
2626

2727
export {

core/nextEdit/NextEditEditableRegionCalculator.ts

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import Parser from "web-tree-sitter";
22
import { Chunk, IDE, ILLM, Position, Range, RangeInFile } from "..";
33
import { getAst } from "../autocomplete/util/ast";
4+
import { NEXT_EDIT_MODELS } from "../llm/constants";
45
import { DocumentHistoryTracker } from "./DocumentHistoryTracker";
5-
import {
6-
NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
7-
NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN,
8-
} from "./constants";
6+
import { MODEL_WINDOW_SIZES } from "./constants";
97

108
export enum EditableRegionStrategy {
119
Naive = "naive",
@@ -60,16 +58,16 @@ function naiveJump(ctx: any): RangeInFile[] | null {
6058

6159
// Sliding splits the file using into sliding window.
6260
function slidingJump(ctx: any): RangeInFile[] | null {
63-
const { fileLines, filepath } = ctx;
64-
if (!fileLines || !filepath) {
65-
console.warn("Missing required context for naive jump");
61+
const { fileLines, filepath, modelName, currentCursorPos } = ctx;
62+
if (!fileLines || !filepath || !modelName || !currentCursorPos) {
63+
console.warn("Missing required context for sliding jump");
6664
return null;
6765
}
6866

69-
const windowSize =
70-
NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN +
71-
NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN +
72-
1; // 1 for current line;
67+
const topMargin = MODEL_WINDOW_SIZES[modelName as NEXT_EDIT_MODELS].topMargin;
68+
const bottomMargin =
69+
MODEL_WINDOW_SIZES[modelName as NEXT_EDIT_MODELS].bottomMargin;
70+
const windowSize = topMargin + bottomMargin + 1; // 1 for current line
7371

7472
if (fileLines.length <= windowSize) {
7573
return [
@@ -86,29 +84,74 @@ function slidingJump(ctx: any): RangeInFile[] | null {
8684
];
8785
}
8886

89-
const slidingStep = Math.max(1, Math.floor(windowSize / 2));
9087
const ranges: RangeInFile[] = [];
88+
const cursorLine = currentCursorPos.line;
9189

92-
for (
93-
let startLine = 0;
94-
startLine < fileLines.length;
95-
startLine += slidingStep
96-
) {
97-
const endLine = Math.min(startLine + windowSize - 1, fileLines.length - 1);
90+
// Create the first window centered around the cursor position
91+
const firstWindowStart = Math.max(0, cursorLine - topMargin);
92+
const firstWindowEnd = Math.min(
93+
fileLines.length - 1,
94+
cursorLine + bottomMargin,
95+
);
9896

99-
ranges.push({
100-
filepath,
101-
range: {
102-
start: { line: startLine, character: 0 },
103-
end: {
104-
line: endLine,
105-
character: fileLines[endLine].length,
106-
},
97+
ranges.push({
98+
filepath,
99+
range: {
100+
start: { line: firstWindowStart, character: 0 },
101+
end: {
102+
line: firstWindowEnd,
103+
character: fileLines[firstWindowEnd].length,
107104
},
108-
});
105+
},
106+
});
107+
108+
// Alternating pattern: down once, up once, repeat
109+
const slidingStep = Math.max(1, Math.floor(windowSize / 2));
110+
let currentStartDown = firstWindowEnd + 1;
111+
let currentStartUp = firstWindowStart - slidingStep;
112+
while (currentStartDown < fileLines.length || currentStartUp >= 0) {
113+
// Go down once
114+
if (currentStartDown < fileLines.length) {
115+
const windowStart = currentStartDown;
116+
const windowEnd = Math.min(
117+
windowStart + windowSize - 1,
118+
fileLines.length - 1,
119+
);
120+
121+
ranges.push({
122+
filepath,
123+
range: {
124+
start: { line: windowStart, character: 0 },
125+
end: {
126+
line: windowEnd,
127+
character: fileLines[windowEnd].length,
128+
},
129+
},
130+
});
131+
132+
currentStartDown += slidingStep;
133+
}
134+
135+
// Go up once
136+
if (currentStartUp >= 0) {
137+
const windowStart = Math.max(0, currentStartUp);
138+
const windowEnd = Math.min(
139+
windowStart + windowSize - 1,
140+
fileLines.length - 1,
141+
);
142+
143+
ranges.push({
144+
filepath,
145+
range: {
146+
start: { line: windowStart, character: 0 },
147+
end: {
148+
line: windowEnd,
149+
character: fileLines[windowEnd].length,
150+
},
151+
},
152+
});
109153

110-
if (endLine >= fileLines.length - 1) {
111-
break;
154+
currentStartUp -= slidingStep;
112155
}
113156
}
114157

core/nextEdit/NextEditPrefetchQueue.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export class PrefetchQueue {
5959
!this.abortController.signal.aborted
6060
) {
6161
const location = this.dequeueUnprocessed();
62+
console.log("processing:");
63+
console.log(
64+
location?.range.start.line + " to " + location?.range.end.line,
65+
);
66+
6267
if (!location) break;
6368

6469
try {
@@ -70,12 +75,20 @@ export class PrefetchQueue {
7075
this.usingFullFileDiff,
7176
);
7277

73-
if (!outcome) continue;
78+
if (!outcome) {
79+
console.log("outcome is undefined");
80+
continue;
81+
}
7482

7583
this.enqueueProcessed({
7684
location,
7785
outcome,
7886
});
87+
88+
console.log(
89+
"the length of processed queue after processing is:",
90+
this.processedQueue.length,
91+
);
7992
} catch (error) {
8093
if (!this.abortController.signal.aborted) {
8194
// Handle error
@@ -115,6 +128,16 @@ export class PrefetchQueue {
115128
return this.processedQueue[0];
116129
}
117130

131+
peekThreeProcessed(): void {
132+
const count = Math.min(3, this.processedQueue.length);
133+
const firstThree = this.processedQueue.slice(0, count);
134+
firstThree.forEach((item, index) => {
135+
console.log(
136+
`Item ${index + 1}: ${item.location.range.start.line} to ${item.location.range.end.line}`,
137+
);
138+
});
139+
}
140+
118141
setPreetchLimit(limit: number): void {
119142
this.prefetchLimit = limit;
120143
}

0 commit comments

Comments
 (0)