From 56313d83eb563ebf15e861273fe132a0fbb63267 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 28 Oct 2024 15:02:29 -0700 Subject: [PATCH] if file empty insert and return --- core/edit/lazy/streamLazyApply.ts | 2 +- .../continue/IdeProtocolClient.kt | 24 ++++++++++++------- .../vscode/src/extension/VsCodeMessenger.ts | 10 ++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/core/edit/lazy/streamLazyApply.ts b/core/edit/lazy/streamLazyApply.ts index 6dd9cef6d..dece697ca 100644 --- a/core/edit/lazy/streamLazyApply.ts +++ b/core/edit/lazy/streamLazyApply.ts @@ -43,7 +43,7 @@ export async function* streamLazyApply( let lazyCompletionLines = streamLines(lazyCompletion, true); // Process line output // lazyCompletionLines = filterEnglishLinesAtStart(lazyCompletionLines); - lazyCompletionLines = stopAtLines(lazyCompletionLines, () => {}, ["```"]); + lazyCompletionLines = stopAtLines(lazyCompletionLines, () => { }, ["```"]); lazyCompletionLines = filterLeadingNewline(lazyCompletionLines); // Fill in unchanged code diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index a165cc96d..672a7502f 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -635,6 +635,22 @@ class IdeProtocolClient( val text = msg["text"] as String val curSelectedModelTitle = msg["curSelectedModelTitle"] as String + val editor = FileEditorManager.getInstance(project).selectedTextEditor + + if (editor == null) { + showToast("error", "No active editor to apply edits to") + respond(null) + return@launch + } + + if (editor.document.text.trim().isEmpty()) { + WriteCommandAction.runWriteCommandAction(project) { + document.insertString(0, text) + } + respond(null) + return@launch + } + val config = readConfigJson() var llm = getModelByRole(config, "applyCodeBlock") @@ -654,14 +670,6 @@ class IdeProtocolClient( val prompt = "The following code was suggested as an edit:\n```\n${text}\n```\nPlease apply it to the previous code." - val editor = FileEditorManager.getInstance(project).selectedTextEditor - - if (editor == null) { - showToast("error", "No active editor to apply edits to") - respond(null) - return@launch - } - val rif = getHighlightedCode() val (prefix, highlighted, suffix) = if (rif == null) { diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 524b61801..6ba5f1279 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -158,6 +158,16 @@ export class VsCodeMessenger { return; } + // If document is empty, insert at 0,0 and finish + if (!editor.document.getText().trim()) { + editor.edit(builder => builder.insert(new vscode.Position(0, 0), data.text)); + await webviewProtocol.request("updateApplyState", { + streamId: data.streamId, + status: "done", + }); + return; + } + // Get LLM from config const configHandler = await configHandlerPromise; const config = await configHandler.loadConfig();