feat: next edit char-level diff (#7776)

* remove filter from next edit svg border

* reduce border radius to 2 in next edit svg

* update border

* remove strikethrough from next edit deletion ui

* remove diff background for now

* feat: word-level diff in next edit svg

* fix: don't alternate non-responses due to empty chain

* fix: log next edit completions to continue console

* fix: test and update chaining behavior to avoid repetitive requests and avoid alternating non-responses
This commit is contained in:
Nate Sesti 2025-09-19 00:25:33 -07:00 • committed by GitHub
parent d78fc99087
commit 12e933bf9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 607 additions and 58 deletions

View file

@ -19,7 +19,7 @@ import {
getSingletonHighlighter,
Highlighter,
} from "shiki";
import { DiffLine } from "..";
import { DiffChar, DiffLine } from "..";
import { escapeForSVG, kebabOfThemeStr } from "../util/text";
interface CodeRendererOptions {
@ -228,6 +228,7 @@ export class CodeRenderer {
options: ConversionOptions,
currLineOffsetFromTop: number,
newDiffLines: DiffLine[],
newDiffChars: DiffChar[],
): Promise<Buffer> {
const strokeWidth = 1;
const highlightedCodeHtml = await this.highlightCode(
@ -236,13 +237,14 @@ export class CodeRenderer {
currLineOffsetFromTop,
newDiffLines,
);
// console.log(highlightedCodeHtml);
const { guts, lineBackgrounds } = this.convertShikiHtmlToSvgGut(
highlightedCodeHtml,
options,
newDiffChars,
);
const backgroundColor = this.getBackgroundColor(highlightedCodeHtml);
const borderColor = "#6b6b6b";
const lines = code.split("\n");
const actualHeight = lines.length * options.lineHeight;
@ -256,12 +258,11 @@ export class CodeRenderer {
}
</style>
<g>
<rect x="0" y="0" rx="10" ry="10" width="${options.dimensions.width}" height="${actualHeight}" fill="${this.editorBackground}" shape-rendering="crispEdges" />
<rect x="0" y="0" rx="2" ry="2" width="${options.dimensions.width}" height="${actualHeight}" fill="${backgroundColor}" stroke="${borderColor}" stroke-width="${strokeWidth}" shape-rendering="crispEdges" />
${lineBackgrounds}
${guts}
</g>
</svg>`;
// console.log(svg);
return Buffer.from(svg, "utf8");
}
@ -269,11 +270,56 @@ export class CodeRenderer {
convertShikiHtmlToSvgGut(
shikiHtml: string,
options: ConversionOptions,
diffChars: DiffChar[],
): { guts: string; lineBackgrounds: string } {
const dom = new JSDOM(shikiHtml);
const document = dom.window.document;
const lines = Array.from(document.querySelectorAll(".line"));
const additionSegmentsByLine = new Map<
number,
Array<{ start: number; end: number }>
>();
diffChars.forEach((diff) => {
if (
diff.type !== "new" ||
diff.newLineIndex === undefined ||
diff.newCharIndexInLine === undefined
) {
return;
}
if (diff.char.includes("\n")) {
return;
}
const start = diff.newCharIndexInLine;
const end = start + diff.char.length;
const existing = additionSegmentsByLine.get(diff.newLineIndex) ?? [];
existing.push({ start, end });
additionSegmentsByLine.set(diff.newLineIndex, existing);
});
additionSegmentsByLine.forEach((segments, lineIndex) => {
segments.sort((a, b) => a.start - b.start);
const merged: Array<{ start: number; end: number }> = [];
segments.forEach((segment) => {
if (merged.length === 0) {
merged.push({ ...segment });
return;
}
const last = merged[merged.length - 1];
if (segment.start <= last.end) {
last.end = Math.max(last.end, segment.end);
} else {
merged.push({ ...segment });
}
});
additionSegmentsByLine.set(lineIndex, merged);
});
const svgLines = lines.map((line, index) => {
const spans = Array.from(line.childNodes)
.map((node) => {
@ -309,60 +355,37 @@ export class CodeRenderer {
return `<text x="0" y="${y}" font-family="${options.fontFamily}" font-size="${options.fontSize.toString()}" xml:space="preserve" dominant-baseline="central" shape-rendering="crispEdges">${spans}</text>`;
});
const estimatedCharWidth = options.fontSize * 0.6;
const additionFill = "rgba(40, 167, 69, 0.25)";
const lineBackgrounds = lines
.map((line, index) => {
const classes = line?.getAttribute("class") || "";
const bgColor = classes.includes("highlighted")
? this.editorLineHighlight
: classes.includes("diff add")
? "rgba(255, 255, 0, 0.2)"
: this.editorBackground;
const y = index * options.lineHeight;
const isFirst = index === 0;
const isLast = index === lines.length - 1;
const isSingleLine = isFirst && isLast;
const radius = 10;
const segments = additionSegmentsByLine.get(index) ?? [];
const backgrounds: string[] = [];
// Handle single line case (both first and last)
if (isSingleLine) {
return `<path d="M ${radius} ${y}
L ${options.dimensions.width - radius} ${y}
Q ${options.dimensions.width} ${y} ${options.dimensions.width} ${y + radius}
L ${options.dimensions.width} ${y + options.lineHeight - radius}
Q ${options.dimensions.width} ${y + options.lineHeight} ${options.dimensions.width - radius} ${y + options.lineHeight}
L ${radius} ${y + options.lineHeight}
Q ${0} ${y + options.lineHeight} ${0} ${y + options.lineHeight - radius}
L ${0} ${y + radius}
Q ${0} ${y} ${radius} ${y}
Z"
fill="${bgColor}" />`;
if (classes.includes("highlighted")) {
backgrounds.push(
`<rect x="0" y="${y}" width="100%" height="${options.lineHeight}" fill="${this.editorLineHighlight}" shape-rendering="crispEdges" />`,
);
}
// SVG notes:
// By default SVGs have anti-aliasing on.
// This is undesirable in our case because pixel-perfect alignment of these rectangles will introduce thin gaps.
// Turning it off with 'shape-rendering="crispEdges"' solves the issue.
return isFirst
? `<path d="M ${0} ${y + options.lineHeight}
L ${0} ${y + radius}
Q ${0} ${y} ${radius} ${y}
L ${options.dimensions.width - radius} ${y}
Q ${options.dimensions.width} ${y} ${options.dimensions.width} ${y + radius}
L ${options.dimensions.width} ${y + options.lineHeight}
Z"
fill="${bgColor}" />`
: isLast
? `<path d="M ${0} ${y}
L ${0} ${y + options.lineHeight - radius}
Q ${0} ${y + options.lineHeight} ${radius} ${y + options.lineHeight}
L ${options.dimensions.width - radius} ${y + options.lineHeight}
Q ${options.dimensions.width} ${y + options.lineHeight} ${options.dimensions.width} ${y + options.lineHeight - 10}
L ${options.dimensions.width} ${y}
Z"
fill="${bgColor}" />`
: `<rect x="0" y="${y}" width="100%" height="${options.lineHeight}" fill="${bgColor}" shape-rendering="crispEdges" />`;
segments.forEach(({ start, end }) => {
const widthInChars = Math.max(end - start, 0);
if (widthInChars <= 0) {
return;
}
const x = start * estimatedCharWidth;
const segmentWidth = widthInChars * estimatedCharWidth;
backgrounds.push(
`<rect x="${x}" y="${y}" width="${segmentWidth}" height="${options.lineHeight}" fill="${additionFill}" shape-rendering="crispEdges" />`,
);
});
return backgrounds.join("\n");
})
.filter((bg) => bg.length > 0)
.join("\n");
return {
@ -394,6 +417,7 @@ export class CodeRenderer {
options: ConversionOptions,
currLineOffsetFromTop: number,
newDiffLines: DiffLine[],
newDiffChars: DiffChar[],
): Promise<DataUri> {
switch (options.imageType) {
// case "png":
@ -413,6 +437,7 @@ export class CodeRenderer {
options,
currLineOffsetFromTop,
newDiffLines,
newDiffChars,
);
return `data:image/svg+xml;base64,${svgBuffer.toString("base64")}`;
}

View file

@ -1056,6 +1056,10 @@ export abstract class BaseLLM implements ILLM {
const msg = fromChatResponse(response);
yield msg;
completion = this._formatChatMessage(msg);
interaction?.logItem({
kind: "message",
message: msg,
});
} else {
// Stream true
const stream = this.openaiAdapter.chatCompletionStream(

View file

@ -41,10 +41,11 @@ const SVG_CONFIG = {
// filter: `drop-shadow(4px 4px 0px rgba(112, 114, 209, 0.4))
// drop-shadow(8px 8px 0px rgba(107, 166, 205, 0.3))
// drop-shadow(12px 12px 0px rgba(136, 194, 163, 0.2));`,
filter: `drop-shadow(4px 4px 0px rgba(112, 114, 209, 0.4))
drop-shadow(-2px 4px 0px rgba(107, 166, 205, 0.3))
drop-shadow(4px -2px 0px rgba(136, 194, 163, 0.2))
drop-shadow(-2px -2px 0px rgba(112, 114, 209, 0.2));`,
// filter: `drop-shadow(4px 4px 0px rgba(112, 114, 209, 0.4))
// drop-shadow(-2px 4px 0px rgba(107, 166, 205, 0.3))
// drop-shadow(4px -2px 0px rgba(136, 194, 163, 0.2))
// drop-shadow(-2px -2px 0px rgba(112, 114, 209, 0.2));`,
filter: "none",
radius: 3,
leftMargin: 40,
defaultText: "",
@ -413,6 +414,8 @@ export class NextEditWindowManager {
);
}
const diffChars = myersCharDiff(oldEditRangeSlice, newEditRangeSlice);
// Create and apply decoration with the text.
if (newEditRangeSlice !== "") {
try {
@ -423,6 +426,7 @@ export class NextEditWindowManager {
newEditRangeSlice,
this.editableRegionStartLine,
diffLines,
diffChars,
);
} catch (error) {
console.error("Failed to render window:", error);
@ -432,8 +436,6 @@ export class NextEditWindowManager {
}
}
const diffChars = myersCharDiff(oldEditRangeSlice, newEditRangeSlice);
this.renderDeletions(editor, diffChars);
// Reserve tab and esc to either accept or reject the displayed next edit contents.
@ -686,6 +688,7 @@ export class NextEditWindowManager {
text: string,
currLineOffsetFromTop: number,
newDiffLines: DiffLine[],
diffChars: DiffChar[],
): Promise<
| { uri: vscode.Uri; dimensions: { width: number; height: number } }
| undefined
@ -710,6 +713,7 @@ export class NextEditWindowManager {
},
currLineOffsetFromTop,
newDiffLines,
diffChars,
);
return {
@ -733,12 +737,14 @@ export class NextEditWindowManager {
position: vscode.Position,
editableRegionStartLine: number,
newDiffLines: DiffLine[],
diffChars: DiffChar[],
): Promise<vscode.TextEditorDecorationType | undefined> {
const currLineOffsetFromTop = position.line - editableRegionStartLine;
const uriAndDimensions = await this.createCodeRender(
predictedCode,
currLineOffsetFromTop,
newDiffLines,
diffChars,
);
if (!uriAndDimensions) {
return undefined;
@ -857,6 +863,7 @@ export class NextEditWindowManager {
predictedCode: string,
editableRegionStartLine: number,
newDiffLines: DiffLine[],
diffChars: DiffChar[],
) {
// Capture document version to detect changes.
const docVersion = editor.document.version;
@ -868,6 +875,7 @@ export class NextEditWindowManager {
position,
editableRegionStartLine,
newDiffLines,
diffChars,
);
if (!decoration) {
console.error("Failed to create decoration for text:", predictedCode);
@ -944,7 +952,6 @@ export class NextEditWindowManager {
const deleteDecorationType = vscode.window.createTextEditorDecorationType({
backgroundColor: "rgba(255, 0, 0, 0.5)",
textDecoration: "line-through",
});
editor.setDecorations(deleteDecorationType, charsToDelete);

View file

@ -0,0 +1,488 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import * as vscode from "vscode";
import { ContinueCompletionProvider } from "../completionProvider";
import * as NextEditLoggingServiceModule from "core/nextEdit/NextEditLoggingService";
import * as PrefetchQueueModule from "core/nextEdit/NextEditPrefetchQueue";
import * as NextEditProviderModule from "core/nextEdit/NextEditProvider";
import * as JumpManagerModule from "../../activation/JumpManager";
type MockNextEditProvider = ReturnType<typeof createMockNextEditProvider>;
type MockPrefetchQueue = ReturnType<typeof createMockPrefetchQueue>;
type MockJumpManager = ReturnType<typeof createMockJumpManager>;
const mockOutcome = {
completion: "suggested change",
diffLines: [],
editableRegionStartLine: 0,
editableRegionEndLine: 0,
} as any;
let mockNextEditProvider: MockNextEditProvider;
let mockPrefetchQueue: MockPrefetchQueue;
let mockJumpManager: MockJumpManager;
beforeEach(() => {
vi.clearAllMocks();
mockNextEditProvider = createMockNextEditProvider();
(NextEditProviderModule as any).__setMockNextEditProviderInstance(
mockNextEditProvider,
);
mockPrefetchQueue = createMockPrefetchQueue();
(PrefetchQueueModule as any).__setMockPrefetchQueueInstance(
mockPrefetchQueue,
);
mockJumpManager = createMockJumpManager();
(JumpManagerModule as any).__setMockJumpManagerInstance(mockJumpManager);
const mockLoggingService = createMockLoggingService();
(NextEditLoggingServiceModule as any).__setMockNextEditLoggingServiceInstance(
mockLoggingService,
);
(vscode.window as any).activeTextEditor = null;
});
describe("ContinueCompletionProvider triggering logic", () => {
it("starts a new chain when none exists", async () => {
const document = createDocument();
setActiveEditor(document);
const provider = buildProvider();
await provider.provideInlineCompletionItems(
document,
createPosition(),
createContext(),
createToken(),
);
expect(mockNextEditProvider.startChain).toHaveBeenCalledTimes(1);
expect(
mockNextEditProvider.provideInlineCompletionItems,
).toHaveBeenCalledTimes(1);
expect(mockNextEditProvider.deleteChain).not.toHaveBeenCalled();
});
it("clears an empty chain once in full file diff mode", async () => {
const document = createDocument();
setActiveEditor(document);
mockNextEditProvider.chainExists.mockReturnValue(true);
mockPrefetchQueue.__setProcessed([]);
mockPrefetchQueue.__setUnprocessed([]);
const provider = buildProvider();
await provider.provideInlineCompletionItems(
document,
createPosition(),
createContext(),
createToken(),
);
expect(mockNextEditProvider.deleteChain).toHaveBeenCalledTimes(1);
expect(mockNextEditProvider.startChain).toHaveBeenCalledTimes(1);
expect(
mockNextEditProvider.provideInlineCompletionItems,
).toHaveBeenCalledTimes(1);
});
it("returns null after clearing empty chain when no outcome is available", async () => {
const document = createDocument();
setActiveEditor(document);
mockNextEditProvider.chainExists.mockReturnValue(true);
mockPrefetchQueue.__setProcessed([]);
mockPrefetchQueue.__setUnprocessed([]);
mockNextEditProvider.provideInlineCompletionItems.mockResolvedValueOnce(
undefined,
);
const provider = buildProvider();
const result = await provider.provideInlineCompletionItems(
document,
createPosition(),
createContext(),
createToken(),
);
expect(result).toBeNull();
expect(mockNextEditProvider.deleteChain).toHaveBeenCalledTimes(1);
expect(mockNextEditProvider.startChain).toHaveBeenCalledTimes(1);
expect(
mockNextEditProvider.provideInlineCompletionItems,
).toHaveBeenCalledTimes(1);
});
it("uses queued outcomes when processed items exist", async () => {
const document = createDocument();
setActiveEditor(document);
mockNextEditProvider.chainExists.mockReturnValue(true);
mockPrefetchQueue.__setProcessed([
{
location: {
range: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
},
},
outcome: mockOutcome,
},
]);
mockJumpManager.suggestJump.mockResolvedValue(true);
const provider = buildProvider();
await provider.provideInlineCompletionItems(
document,
createPosition(),
createContext(),
createToken(),
);
expect(mockPrefetchQueue.dequeueProcessed).toHaveBeenCalledTimes(1);
expect(mockJumpManager.setCompletionAfterJump).toHaveBeenCalledTimes(1);
expect(mockNextEditProvider.startChain).not.toHaveBeenCalled();
expect(mockNextEditProvider.deleteChain).not.toHaveBeenCalled();
expect(
mockNextEditProvider.provideInlineCompletionItems,
).not.toHaveBeenCalled();
});
});
function buildProvider(options: { usingFullFileDiff?: boolean } = {}) {
const usingFullFileDiff = options.usingFullFileDiff ?? true;
const configHandler = {
loadConfig: vi.fn(async () => ({
config: { selectedModelByRole: { autocomplete: undefined } },
})),
} as any;
const ide = { ideUtils: {} } as any;
const webviewProtocol = {} as any;
const provider = new ContinueCompletionProvider(
configHandler,
ide,
webviewProtocol,
usingFullFileDiff,
);
provider.activateNextEdit();
return provider;
}
function createDocument(
text = "function example() {\n return true;\n}",
): vscode.TextDocument {
const lines = text.split("\n");
return {
uri: vscode.Uri.parse("file:///test"),
isUntitled: false,
getText: (range?: any) => {
if (!range) {
return text;
}
const startLine = range.start?.line ?? 0;
const endLine = range.end?.line ?? startLine;
const startChar = range.start?.character ?? 0;
const endChar = range.end?.character ?? lines[endLine]?.length ?? 0;
if (startLine === endLine) {
const lineText = lines[startLine] ?? "";
return lineText.slice(startChar, endChar);
}
return text;
},
lineAt: (position: any) => {
const lineNumber =
typeof position === "number" ? position : position.line;
const lineText = lines[lineNumber] ?? "";
const range = new (vscode.Range as any)(
new (vscode.Position as any)(lineNumber, 0),
new (vscode.Position as any)(lineNumber, lineText.length),
);
return {
lineNumber,
text: lineText,
range,
rangeIncludingLineBreak: range,
firstNonWhitespaceCharacterIndex: 0,
isEmptyOrWhitespace: lineText.trim().length === 0,
} as unknown as vscode.TextLine;
},
} as unknown as vscode.TextDocument;
}
function createContext(): any {
return {
triggerKind: (vscode.InlineCompletionTriggerKind as any).Automatic,
selectedCompletionInfo: undefined,
};
}
function createPosition(line = 0, character = 0) {
return new (vscode.Position as any)(line, character);
}
function createToken(): any {
return {
isCancellationRequested: false,
onCancellationRequested: vi.fn(),
};
}
function setActiveEditor(document: any, cursor = createPosition()) {
const selection = { active: cursor, anchor: cursor };
(vscode.window as any).activeTextEditor = {
document,
selection,
selections: [selection],
};
}
function createMockNextEditProvider() {
return {
chainExists: vi.fn(() => false),
startChain: vi.fn(),
deleteChain: vi.fn(async () => {}),
provideInlineCompletionItems: vi.fn(async () => mockOutcome),
provideInlineCompletionItemsWithChain: vi.fn(async () => mockOutcome),
markDisplayed: vi.fn(),
getChainLength: vi.fn(() => 0),
};
}
function createMockPrefetchQueue() {
let processedItems: any[] = [];
let unprocessedItems: any[] = [];
const queue: any = {
initialize: vi.fn(),
process: vi.fn(),
peekThreeProcessed: vi.fn(),
dequeueProcessed: vi.fn(() => processedItems.shift()),
enqueueProcessed: vi.fn((item: any) => {
processedItems.push(item);
}),
__setProcessed(items: any[]) {
processedItems = [...items];
},
__setUnprocessed(items: any[]) {
unprocessedItems = [...items];
},
};
Object.defineProperty(queue, "processedCount", {
get: () => processedItems.length,
});
Object.defineProperty(queue, "unprocessedCount", {
get: () => unprocessedItems.length,
});
return queue;
}
function createMockJumpManager() {
return {
isJumpInProgress: vi.fn(() => false),
setJumpInProgress: vi.fn(),
completionAfterJump: undefined,
clearCompletionAfterJump: vi.fn(),
setCompletionAfterJump: vi.fn(),
suggestJump: vi.fn(async () => false),
wasJumpJustAccepted: vi.fn(() => false),
};
}
function createMockLoggingService() {
return {
trackPendingCompletion: vi.fn(),
handleAbort: vi.fn(),
markDisplayed: vi.fn(),
cancelRejectionTimeout: vi.fn(),
deleteAbortController: vi.fn(),
cancel: vi.fn(),
};
}
vi.mock("vscode", () => {
class Position {
constructor(
public line: number,
public character: number,
) {}
}
class Range {
constructor(
public start: Position,
public end: Position,
) {}
}
class InlineCompletionItem {
public insertText: string;
public range: Range;
public command?: any;
constructor(insertText: string, range: Range, command?: any) {
this.insertText = insertText;
this.range = range;
this.command = command;
}
}
const window = {
activeTextEditor: null as any,
showErrorMessage: vi.fn(() => Promise.resolve(undefined)),
};
const workspace = {
notebookDocuments: [] as any[],
getConfiguration: vi.fn(() => ({ get: vi.fn() })),
};
return {
window,
workspace,
Uri: { parse: (value: string) => ({ toString: () => value }) },
Position,
Range,
InlineCompletionItem,
InlineCompletionTriggerKind: { Automatic: 0, Invoke: 1 },
NotebookCellKind: { Markup: 1 },
};
});
vi.mock("core/autocomplete/CompletionProvider", () => {
return {
CompletionProvider: class {
provideInlineCompletionItems = vi.fn();
markDisplayed = vi.fn();
},
};
});
vi.mock("core/autocomplete/util/processSingleLineCompletion", () => ({
processSingleLineCompletion: vi.fn((text: string) => ({
completionText: text,
range: { start: 0, end: text.length },
})),
}));
vi.mock("../statusBar", () => {
const StatusBarStatus = {
Enabled: "enabled",
Disabled: "disabled",
} as const;
return {
StatusBarStatus,
getStatusBarStatus: vi.fn(() => StatusBarStatus.Enabled),
setupStatusBar: vi.fn(),
stopStatusBarLoading: vi.fn(),
};
});
vi.mock("../GhostTextAcceptanceTracker", () => {
const instance = {
setExpectedGhostTextAcceptance: vi.fn(),
};
return {
GhostTextAcceptanceTracker: {
getInstance: () => instance,
},
};
});
vi.mock("../lsp", () => ({
getDefinitionsFromLsp: vi.fn(),
}));
vi.mock("../recentlyEdited", () => ({
RecentlyEditedTracker: class {
async getRecentlyEditedRanges() {
return [];
}
},
}));
vi.mock("../RecentlyVisitedRangesService", () => ({
RecentlyVisitedRangesService: class {
getSnippets() {
return [];
}
},
}));
vi.mock("../activation/NextEditWindowManager", () => ({
NextEditWindowManager: {
isInstantiated: vi.fn(() => false),
getInstance: vi.fn(),
},
}));
vi.mock("../../activation/JumpManager", () => {
let instance: any = null;
return {
JumpManager: {
getInstance: () => instance,
},
__setMockJumpManagerInstance(value: any) {
instance = value;
},
};
});
vi.mock("core/nextEdit/NextEditPrefetchQueue", () => {
let instance: any = null;
return {
PrefetchQueue: {
getInstance: () => instance,
},
__setMockPrefetchQueueInstance(value: any) {
instance = value;
},
};
});
vi.mock("core/nextEdit/NextEditProvider", () => {
let instance: any = null;
return {
NextEditProvider: {
initialize: vi.fn(() => instance),
getInstance: vi.fn(() => instance),
},
__setMockNextEditProviderInstance(value: any) {
instance = value;
},
};
});
vi.mock("core/nextEdit/NextEditLoggingService", () => {
let instance: any = null;
return {
NextEditLoggingService: {
getInstance: () => instance,
},
__setMockNextEditLoggingServiceInstance(value: any) {
instance = value;
},
};
});
vi.mock("core/nextEdit/diff/diff", () => ({
checkFim: vi.fn(() => ({ isFim: true, fimText: "ghost" })),
}));
vi.mock("../util/errorHandling", () => ({
handleLLMError: vi.fn(async () => false),
}));

View file

@ -330,10 +330,25 @@ export class ContinueCompletionProvider
// Determine why this method was triggered.
const isJumping = this.jumpManager.isJumpInProgress();
const chainExists = this.nextEditProvider.chainExists();
let chainExists = this.nextEditProvider.chainExists();
const processedCount = this.prefetchQueue.processedCount;
const unprocessedCount = this.prefetchQueue.unprocessedCount;
console.log("isJumping:", isJumping, "/ chainExists:", chainExists);
this.prefetchQueue.peekThreeProcessed();
let resetChainInFullFileDiff = false;
if (
chainExists &&
this.usingFullFileDiff &&
processedCount === 0 &&
unprocessedCount === 0
) {
// Skipping jump logic due to empty queues while using full file diff
await this.nextEditProvider.deleteChain();
chainExists = false;
resetChainInFullFileDiff = true;
}
if (isJumping && chainExists) {
// Case 2: Jumping (chain exists, jump was taken)
console.log("trigger reason: jumping");
@ -421,6 +436,7 @@ export class ContinueCompletionProvider
}
} else {
// Case 1: Typing (chain does not exist).
// if resetChainInFullFileDiff is true then we are Rebuilding next edit chain after clearing empty queues in full file diff mode
this.nextEditProvider.startChain();
const input: AutocompleteInput = {
@ -439,6 +455,15 @@ export class ContinueCompletionProvider
{ withChain: false, usingFullFileDiff: this.usingFullFileDiff },
);
if (
resetChainInFullFileDiff &&
(!outcome ||
(!outcome.completion && outcome.diffLines.length === 0))
) {
// No next edit outcome after resetting chain; returning null
return null;
}
// Start prefetching next edits if not using full file diff.
// NOTE: this is better off not awaited. fire and forget.
if (!this.usingFullFileDiff) {