Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add send prompt by commandline #35

Merged
merged 7 commits into from
Oct 24, 2024
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,26 @@ To use aider.vim, you can run the following commands within Vim or Neovim:
- `:AiderAddWeb` - Displays a prompt for the specified URL and adds it to the aider context.
- `:AiderOpenIgnore` - Opens the `.aiderignore` file in the git root directory if it exists.
- `:AiderAddIgnoreCurrentFile` - Adds the current file to the `.aiderignore`.
- `:AiderSendPromptByCommandline <prompt>` - Sends a prompt from the command line and displays the Aider window.
- `:AiderSilentSendPromptByCommandline <prompt>` - Sends a prompt from the command line and refreshes the buffer.
- `:AiderAsk <question>` - Sends a question to aider without adding any files to the context.
- `:AiderHide` - Hides the floating window and reloads the buffer.
- `:AiderPaste` - Pastes the content from the clipboard into the aider context.
- `:AiderHideVisualSelectFloatingWindow` - Hides the visual selection floating window used for displaying selected text.
- `:AiderVoice` - Sends voice commands to Aider(using wishper).

### Advanced Usage
If you want to send a custom prompt to Aider, use `AiderSendPromptByCommandline`.
Set it up as follows:

```vim
" Send a prompt to Aider and display the Aider window
:AiderSendPromptByCommandline "/chat-mode architect"

" Send a prompt to Aider but do not display the Aider window
:AiderSilentSendPromptByCommandline "/chat-mode code"
```

## Additional Prompt

You can set an additional prompt that will be automatically added to every
Expand Down
2 changes: 1 addition & 1 deletion denops/aider/bufferOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function openFloatingWindowWithSelectedCode(
await n.nvim_buf_set_keymap(denops, bufnr, "n", "q", "<cmd>AiderHideVisualSelectFloatingWindow<CR>", {
silent: true,
});
await n.nvim_buf_set_keymap(denops, bufnr, "n", "<cr>", "<cmd>AiderSendPrompt<cr><cmd>AiderRun<cr>", {
await n.nvim_buf_set_keymap(denops, bufnr, "n", "<cr>", "<cmd>AiderSendPromptByBuffer<cr><cmd>AiderRun<cr>", {
silent: true,
});
}
Expand Down
21 changes: 20 additions & 1 deletion denops/aider/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,29 @@ export async function main(denops: Denops): Promise<void> {
}

const commands: Command[] = [
await command("sendPrompt", "0", async () => {
await command("sendPromptByBuffer", "0", async () => {
await buffer.sendPromptByBuffer(denops, openBufferType);
}),

await command(
"sendPromptByCommandline",
"1",
async (prompt: string) => {
await buffer.sendPrompt(denops, prompt, { openBuf: true });
},
{ pattern: "[<f-args>]" },
),

await command(
"silentSendPromptByCommandline",
"1",
async (prompt: string) => {
await buffer.sendPrompt(denops, prompt, { openBuf: false });
console.log(`Sent prompt: ${prompt}`);
},
{ pattern: "[<f-args>]" },
),

await command("run", "0", async () => {
await buffer.openAiderBuffer(denops, openBufferType);
}),
Expand Down
32 changes: 28 additions & 4 deletions tests/aider_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,35 @@ test("both", "AiderAddBuffers should return empty for files not under git manage
await assertAiderBufferString(denops, "input: /add \n");
});

test("both", "AiderAddBuffers should return /add `bufferName` if there is a buffer under git management", async (denops) => {
test(
"both",
"AiderAddBuffers should return /add `bufferName` if there is a buffer under git management",
async (denops) => {
await denops.cmd("AiderRun");
await sleep(SLEEP_BEFORE_ASSERT);
await denops.cmd("e ./tests/aider_test.ts");
await denops.cmd("AiderAddBuffers");
await sleep(SLEEP_BEFORE_ASSERT);
await assertAiderBufferString(denops, "input: /add tests/aider_test.ts\n");
},
);
nekowasabi marked this conversation as resolved.
Show resolved Hide resolved

test("both", "AiderSendPromptByCommandline should work", async (denops) => {
await denops.cmd("AiderRun");
await sleep(SLEEP_BEFORE_ASSERT);
await denops.cmd("e ./tests/aider_test.ts");
await denops.cmd("AiderAddBuffers");
await assertAiderBufferAlive(denops);
await sleep(SLEEP_BEFORE_ASSERT);
await denops.cmd("AiderSendPromptByCommandline test");
await sleep(SLEEP_BEFORE_ASSERT);
await assertAiderBufferString(denops, "input: test\n");
});
nekowasabi marked this conversation as resolved.
Show resolved Hide resolved

test("both", "AiderSilentSendPromptByCommandline should work", async (denops) => {
await denops.cmd("AiderSilentRun");
await sleep(SLEEP_BEFORE_ASSERT);
await assertAiderBufferAlive(denops);
await sleep(SLEEP_BEFORE_ASSERT);
await denops.cmd("AiderSilentSendPromptByCommandline silent test");
await sleep(SLEEP_BEFORE_ASSERT);
await assertAiderBufferString(denops, "input: /add tests/aider_test.ts\n");
await assertAiderBufferString(denops, "input: silent test\n");
nekowasabi marked this conversation as resolved.
Show resolved Hide resolved
});