diff --git a/core/core.ts b/core/core.ts index 75dc023ef..7257913c0 100644 --- a/core/core.ts +++ b/core/core.ts @@ -541,6 +541,12 @@ export class Core { ); return outcome ? [outcome.completion, outcome.originalEditableRange] : []; }); + on("nextEdit/accept", async (msg) => { + this.nextEditProvider.accept(msg.data.completionId); + }); + on("nextEdit/reject", async (msg) => { + this.nextEditProvider.reject(msg.data.completionId); + }); on("streamDiffLines", async (msg) => { const { config } = await this.configHandler.loadConfig(); diff --git a/core/nextEdit/NextEditProvider.ts b/core/nextEdit/NextEditProvider.ts index fba86df33..1a56817cb 100644 --- a/core/nextEdit/NextEditProvider.ts +++ b/core/nextEdit/NextEditProvider.ts @@ -158,19 +158,19 @@ export class NextEditProvider { this.loggingService.cancel(); } - // public accept(completionId: string) { - // const outcome = this.loggingService.accept(completionId); - // if (!outcome) { - // return; - // } - // } + public accept(completionId: string) { + const outcome = this.loggingService.accept(completionId); + if (!outcome) { + return; + } + } - // public reject(completionId: string) { - // const outcome = this.loggingService.reject(completionId); - // if (!outcome) { - // return; - // } - // } + public reject(completionId: string) { + const outcome = this.loggingService.reject(completionId); + if (!outcome) { + return; + } + } public markDisplayed(completionId: string, outcome: NextEditOutcome) { this.loggingService.markDisplayed(completionId, outcome); @@ -237,7 +237,6 @@ export class NextEditProvider { // TODO: Toggle between the default endpoint and the finetuned endpoint. const prompts: Prompt[] = []; - if (this.endpointType === "default") { prompts.push(renderDefaultSystemPrompt()); prompts.push(renderDefaultUserPrompt(snippetPayload, helper)); @@ -278,11 +277,16 @@ export class NextEditProvider { } } else { const msg: ChatMessage = await llm.chat(prompts, token); + if (typeof msg.content === "string") { - // TODO: There are cases where msg.conetnt.split("<|start|>")[1] is undefined - const nextCompletion = replaceEscapedCharacters( - msg.content.split("<|editable_region_start|>\n")[1], - ).replace(/\n$/, ""); + // NOTE: There are cases where msg.conetnt.split("<|start|>")[1] is undefined + const nextCompletion = msg.content.split( + "<|editable_region_start|>\n", + )[1] + ? replaceEscapedCharacters( + msg.content.split("<|editable_region_start|>\n")[1], + ).replace(/\n$/, "") + : ""; const currCursorPos = helper.pos; const editableRegionStartLine = Math.max(