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

Refactor send prompt #33

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions denops/aider/bufferOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function prepareAiderBuffer(denops: Denops, openBufferType: BufferL
}
}

export async function sendPrompt(denops: Denops, input: string, openBuf = true): Promise<void> {
export async function sendPrompt(denops: Denops, input: string, opts = { openBuf: true }): Promise<void> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Q] optsをjson的に渡せるようにしたのは、将来的な拡張性のためでしょうか

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

まあyes 1個だけでもなんかboolの引数だけがあるよりわかりやすいし

Copy link
Owner

@nekowasabi nekowasabi Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかに。呼び出しが明示的になった感

const aiderBuf = await getAiderBuffer(denops);
if (aiderBuf === undefined) {
await denops.cmd("echo 'Aider is not running'");
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions denops/aider/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function main(denops: Denops): Promise<void> {
denops: Denops,
openBufferType: BufferLayout,
prefix: string,
openBuf = true,
opts = { openBuf: true },
): Promise<void> {
const currentBufnr = await fn.bufnr(denops, "%");
const aiderBuffer = await buffer.getAiderBuffer(denops);
Expand All @@ -101,7 +101,7 @@ export async function main(denops: Denops): Promise<void> {

const currentFile = await getCurrentFilePath(denops);
const prompt = `/${prefix} ${currentFile}`;
await buffer.sendPrompt(denops, prompt, openBuf);
await buffer.sendPrompt(denops, prompt, opts);
tsukimizake marked this conversation as resolved.
Show resolved Hide resolved
}

const commands: Command[] = [
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function main(denops: Denops): Promise<void> {
}),

await command("silentAddCurrentFile", "0", async () => {
await addFileToAider(denops, openBufferType, "add", false);
await addFileToAider(denops, openBufferType, "add", { openBuf: false });
await denops.cmd("fclose!");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( ;´ワ `;)つ☆

await denops.cmd("silent! e!");
}),
Expand All @@ -168,7 +168,9 @@ export async function main(denops: Denops): Promise<void> {
}),

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!");
}),
Expand Down