diff --git a/denops/aider/actualAiderCommand.ts b/denops/aider/actualAiderCommand.ts index 6a0c3fe..cb9c9cb 100644 --- a/denops/aider/actualAiderCommand.ts +++ b/denops/aider/actualAiderCommand.ts @@ -40,10 +40,9 @@ async function run(denops: Denops): Promise { * @returns {Promise} */ async function sendPrompt(denops: Denops, jobId: number, prompt: string): Promise { - await v.r.set(denops, "q", prompt); - await fn.feedkeys(denops, "G"); - await fn.feedkeys(denops, '"qp'); - await denops.call("chansend", jobId, "\n"); + const promptLines = prompt.split("\n"); + const joined = promptLines.join("\x1b\x0d"); // use Esc + Ctrl-M instead of \n to avoid submit cf. https://github.com/Aider-AI/aider/issues/901 + await denops.call("chansend", jobId, `${joined}\n`); } async function exit(denops: Denops, jobId: number, bufnr: number): Promise { diff --git a/denops/aider/bufferOperation.ts b/denops/aider/bufferOperation.ts index b847275..235f3a3 100644 --- a/denops/aider/bufferOperation.ts +++ b/denops/aider/bufferOperation.ts @@ -85,7 +85,7 @@ export async function prepareAiderBuffer(denops: Denops, openBufferType: BufferL } } -export async function sendPrompt(denops: Denops, input: string): Promise { +export async function sendPrompt(denops: Denops, input: string, opts = { openBuf: true }): Promise { const aiderBuf = await getAiderBuffer(denops); if (aiderBuf === undefined) { await denops.cmd("echo 'Aider is not running'"); @@ -96,7 +96,9 @@ export async function sendPrompt(denops: Denops, input: string): Promise { const openBufferType = await getOpenBufferType(denops); if (openBufferType === "floating") { - await openAiderBuffer(denops, openBufferType); + if (opts?.openBuf) { + await openAiderBuffer(denops, openBufferType); + } await sendPromptFromFloatingWindow(denops, input); return; } @@ -265,7 +267,6 @@ async function sendPromptFromFloatingWindow(denops: Denops, prompt: string): Pro if (aiderBuf === undefined) { return; } - await openFloatingWindow(denops, aiderBuf.bufnr); await aider().sendPrompt(denops, aiderBuf.jobId, prompt); } diff --git a/denops/aider/main.ts b/denops/aider/main.ts index c3c2c42..5a2460a 100644 --- a/denops/aider/main.ts +++ b/denops/aider/main.ts @@ -1,10 +1,9 @@ +import { relative } from "https://deno.land/std@0.115.1/path/mod.ts"; import * as fn from "https://deno.land/x/denops_std@v6.5.1/function/mod.ts"; import type { Denops } from "https://deno.land/x/denops_std@v6.5.1/mod.ts"; -import { aider } from "./aiderCommand.ts"; import * as buffer from "./bufferOperation.ts"; import type { BufferLayout } from "./bufferOperation.ts"; import { getCurrentFilePath } from "./utils.ts"; -import { relative } from "https://deno.land/std@0.115.1/path/mod.ts"; /** * The main function that sets up the Aider plugin functionality. @@ -83,7 +82,12 @@ export async function main(denops: Denops): Promise { const openBufferType: BufferLayout = await buffer.getOpenBufferType(denops); - async function addFileToAider(denops: Denops, openBufferType: BufferLayout, prefix: string): Promise { + async function addFileToAider( + denops: Denops, + openBufferType: BufferLayout, + prefix: string, + opts = { openBuf: true }, + ): Promise { const currentBufnr = await fn.bufnr(denops, "%"); const aiderBuffer = await buffer.getAiderBuffer(denops); @@ -97,7 +101,7 @@ export async function main(denops: Denops): Promise { const currentFile = await getCurrentFilePath(denops); const prompt = `/${prefix} ${currentFile}`; - await buffer.sendPrompt(denops, prompt); + await buffer.sendPrompt(denops, prompt, opts); } const commands: Command[] = [ @@ -143,9 +147,7 @@ export async function main(denops: Denops): Promise { }), await command("silentAddCurrentFile", "0", async () => { - await addFileToAider(denops, openBufferType, "add"); - await denops.cmd("fclose!"); - await denops.cmd("silent! e!"); + await addFileToAider(denops, openBufferType, "add", { openBuf: false }); }), await command( @@ -164,9 +166,9 @@ export async function main(denops: Denops): Promise { }), await command("silentAddCurrentFileReadOnly", "0", async () => { - await addFileToAider(denops, openBufferType, "read-only"); - await denops.cmd("fclose!"); - await denops.cmd("silent! e!"); + await addFileToAider(denops, openBufferType, "read-only", { + openBuf: false, + }); }), await command(