From eaa6665f89d62531f3d66f3471397a32e95d5e7b Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Mon, 21 Oct 2024 16:28:52 +0900 Subject: [PATCH 1/6] adding proper silent commands --- denops/aider/actualAiderCommand.ts | 7 +++---- denops/aider/bufferOperation.ts | 6 ++++-- denops/aider/main.ts | 13 +++++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/denops/aider/actualAiderCommand.ts b/denops/aider/actualAiderCommand.ts index 6a0c3fe..b0b91fa 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"); + promptLines.push("\n"); + await denops.call("chansend", jobId, promptLines); } async function exit(denops: Denops, jobId: number, bufnr: number): Promise { diff --git a/denops/aider/bufferOperation.ts b/denops/aider/bufferOperation.ts index b847275..848e212 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, 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 (openBuf) { + await openAiderBuffer(denops, openBufferType); + } await sendPromptFromFloatingWindow(denops, input); return; } diff --git a/denops/aider/main.ts b/denops/aider/main.ts index c3c2c42..b38676b 100644 --- a/denops/aider/main.ts +++ b/denops/aider/main.ts @@ -83,7 +83,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, + openBuf = true, + ): Promise { const currentBufnr = await fn.bufnr(denops, "%"); const aiderBuffer = await buffer.getAiderBuffer(denops); @@ -97,7 +102,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, openBuf); } const commands: Command[] = [ @@ -143,7 +148,7 @@ export async function main(denops: Denops): Promise { }), await command("silentAddCurrentFile", "0", async () => { - await addFileToAider(denops, openBufferType, "add"); + await addFileToAider(denops, openBufferType, "add", false); await denops.cmd("fclose!"); await denops.cmd("silent! e!"); }), @@ -164,7 +169,7 @@ export async function main(denops: Denops): Promise { }), await command("silentAddCurrentFileReadOnly", "0", async () => { - await addFileToAider(denops, openBufferType, "read-only"); + await addFileToAider(denops, openBufferType, "read-only", false); await denops.cmd("fclose!"); await denops.cmd("silent! e!"); }), From 6e9185a4a395be25e3f56707fd73af1f66979601 Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Mon, 21 Oct 2024 17:27:18 +0900 Subject: [PATCH 2/6] fix sendPrompt on multiline --- denops/aider/actualAiderCommand.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/denops/aider/actualAiderCommand.ts b/denops/aider/actualAiderCommand.ts index b0b91fa..df95e91 100644 --- a/denops/aider/actualAiderCommand.ts +++ b/denops/aider/actualAiderCommand.ts @@ -41,8 +41,8 @@ async function run(denops: Denops): Promise { */ async function sendPrompt(denops: Denops, jobId: number, prompt: string): Promise { const promptLines = prompt.split("\n"); - promptLines.push("\n"); - await denops.call("chansend", jobId, promptLines); + const joined = promptLines.join("\x1b\x0d"); // use Esc + Ctrl-M instead of \n to avoid sending 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 { From 0f43f261a4065660f535c970c8d674597af57871 Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Tue, 22 Oct 2024 09:28:04 +0900 Subject: [PATCH 3/6] organize imports --- denops/aider/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/denops/aider/main.ts b/denops/aider/main.ts index b38676b..9b2f2bf 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. From 72624fd5af73f9fb02fbd302865a594c9f18e8be Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Tue, 22 Oct 2024 10:36:04 +0900 Subject: [PATCH 4/6] pass as opts record --- denops/aider/bufferOperation.ts | 4 ++-- denops/aider/main.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/denops/aider/bufferOperation.ts b/denops/aider/bufferOperation.ts index 848e212..e1f9118 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, openBuf = true): 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,7 @@ export async function sendPrompt(denops: Denops, input: string, openBuf = true): const openBufferType = await getOpenBufferType(denops); if (openBufferType === "floating") { - if (openBuf) { + if (opts?.openBuf) { await openAiderBuffer(denops, openBufferType); } await sendPromptFromFloatingWindow(denops, input); diff --git a/denops/aider/main.ts b/denops/aider/main.ts index 9b2f2bf..fb7bfd5 100644 --- a/denops/aider/main.ts +++ b/denops/aider/main.ts @@ -86,7 +86,7 @@ export async function main(denops: Denops): Promise { denops: Denops, openBufferType: BufferLayout, prefix: string, - openBuf = true, + opts = { openBuf: true }, ): Promise { const currentBufnr = await fn.bufnr(denops, "%"); const aiderBuffer = await buffer.getAiderBuffer(denops); @@ -101,7 +101,7 @@ export async function main(denops: Denops): Promise { const currentFile = await getCurrentFilePath(denops); const prompt = `/${prefix} ${currentFile}`; - await buffer.sendPrompt(denops, prompt, openBuf); + await buffer.sendPrompt(denops, prompt, opts); } const commands: Command[] = [ @@ -147,7 +147,7 @@ export async function main(denops: Denops): Promise { }), await command("silentAddCurrentFile", "0", async () => { - await addFileToAider(denops, openBufferType, "add", false); + await addFileToAider(denops, openBufferType, "add", { openBuf: false }); await denops.cmd("fclose!"); await denops.cmd("silent! e!"); }), @@ -168,7 +168,9 @@ export async function main(denops: Denops): Promise { }), await command("silentAddCurrentFileReadOnly", "0", async () => { - await addFileToAider(denops, openBufferType, "read-only", false); + await addFileToAider(denops, openBufferType, "read-only", { + openBuf: false, + }); await denops.cmd("fclose!"); await denops.cmd("silent! e!"); }), From cb477160b78142ff1f2dceeeb8aa79af488eebce Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Tue, 22 Oct 2024 13:13:02 +0900 Subject: [PATCH 5/6] fix flicker --- denops/aider/bufferOperation.ts | 1 - denops/aider/main.ts | 4 ---- 2 files changed, 5 deletions(-) diff --git a/denops/aider/bufferOperation.ts b/denops/aider/bufferOperation.ts index e1f9118..235f3a3 100644 --- a/denops/aider/bufferOperation.ts +++ b/denops/aider/bufferOperation.ts @@ -267,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 fb7bfd5..5a2460a 100644 --- a/denops/aider/main.ts +++ b/denops/aider/main.ts @@ -148,8 +148,6 @@ export async function main(denops: Denops): Promise { await command("silentAddCurrentFile", "0", async () => { await addFileToAider(denops, openBufferType, "add", { openBuf: false }); - await denops.cmd("fclose!"); - await denops.cmd("silent! e!"); }), await command( @@ -171,8 +169,6 @@ export async function main(denops: Denops): Promise { await addFileToAider(denops, openBufferType, "read-only", { openBuf: false, }); - await denops.cmd("fclose!"); - await denops.cmd("silent! e!"); }), await command( From caf24081c9740c9ccf7acd302b9b6697912363bc Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Tue, 22 Oct 2024 13:16:29 +0900 Subject: [PATCH 6/6] chore: update comment --- denops/aider/actualAiderCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/denops/aider/actualAiderCommand.ts b/denops/aider/actualAiderCommand.ts index df95e91..cb9c9cb 100644 --- a/denops/aider/actualAiderCommand.ts +++ b/denops/aider/actualAiderCommand.ts @@ -41,7 +41,7 @@ async function run(denops: Denops): Promise { */ async function sendPrompt(denops: Denops, jobId: number, prompt: string): Promise { const promptLines = prompt.split("\n"); - const joined = promptLines.join("\x1b\x0d"); // use Esc + Ctrl-M instead of \n to avoid sending cf. https://github.com/Aider-AI/aider/issues/901 + 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`); }