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

remove silentRun from AiderCommand #32

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 4 additions & 41 deletions denops/aider/actualAiderCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as util from "./utils.ts";

export const commands: AiderCommand = {
run,
silentRun,
sendPrompt,
exit,
checkIfAiderBuffer,
Expand All @@ -20,70 +19,34 @@ export const commands: AiderCommand = {
* @param {number} bufnr - バッファ番号
* @returns {Promise<boolean>}
*/
async function checkIfAiderBuffer(
denops: Denops,
bufnr: number,
): Promise<boolean> {
async function checkIfAiderBuffer(denops: Denops, bufnr: number): Promise<boolean> {
// aiderバッファの場合 `term://{path}//{pid}:aider --4o --no-auto-commits` のような名前になっている
const name = await util.getBufferName(denops, bufnr);
const splitted = name.split(" ");
return splitted[0].endsWith("aider");
}

async function run(denops: Denops): Promise<undefined> {
const aiderCommand = ensure(
await v.g.get(denops, "aider_command"),
is.String,
);
const aiderCommand = ensure(await v.g.get(denops, "aider_command"), is.String);
await denops.cmd(`terminal ${aiderCommand}`);
await emit(denops, "User", "AiderOpen");
}

/**
* Aiderをバックグラウンドで実行します。
* 新しいバッファを作成し、Aiderコマンドをターミナルで実行した後、
* 前のバッファに戻ります。
* @param {Denops} denops - Denopsインスタンス
* @returns {Promise<undefined>}
*/
async function silentRun(denops: Denops): Promise<undefined> {
await denops.cmd("enew");

const aiderCommand = ensure(
await v.g.get(denops, "aider_command"),
is.String,
);
await denops.cmd(`terminal ${aiderCommand}`);
await emit(denops, "User", "AiderOpen");

await denops.cmd("b#");

await denops.cmd("echo 'Aider is running in the background.'");
}

/**
* Aiderバッファにメッセージを送信します。
* @param {Denops} denops - Denops instance
* @param {number} jobId - The job id to send the message to
* @param {string} prompt - The prompt to send
* @returns {Promise<undefined>}
*/
async function sendPrompt(
denops: Denops,
jobId: number,
prompt: string,
): Promise<undefined> {
async function sendPrompt(denops: Denops, jobId: number, prompt: string): Promise<undefined> {
await v.r.set(denops, "q", prompt);
await fn.feedkeys(denops, "G");
await fn.feedkeys(denops, '"qp');
await denops.call("chansend", jobId, "\n");
}

async function exit(
denops: Denops,
jobId: number,
bufnr: number,
): Promise<undefined> {
async function exit(denops: Denops, jobId: number, bufnr: number): Promise<undefined> {
await denops.call("chansend", jobId, "/exit\n");
await denops.cmd(`bdelete! ${bufnr}`);
}
Expand Down
14 changes: 1 addition & 13 deletions denops/aider/aiderCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export interface AiderCommand {
*/
run: (denops: Denops) => Promise<undefined>;

/**
* Aiderコマンドを静かに実行します。
*
* @param denops - Denopsインスタンス。
* @returns コマンドが静かに実行されたときに解決されるPromise。
*/
silentRun: (denops: Denops) => Promise<undefined>;

/**
* Aiderコマンドにプロンプトを送信します。
*
Expand All @@ -30,11 +22,7 @@ export interface AiderCommand {
* @param prompt - 送信するプロンプト文字列。
* @returns プロンプトが送信されたときに解決されるPromise。
*/
sendPrompt: (
denops: Denops,
jobId: number,
prompt: string,
) => Promise<undefined>;
sendPrompt: (denops: Denops, jobId: number, prompt: string) => Promise<undefined>;

/**
* Aiderコマンドを終了します。
Expand Down
7 changes: 6 additions & 1 deletion denops/aider/bufferOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ export async function openAiderBuffer(denops: Denops, openBufferType: BufferLayo
}
}

export async function silentRun(denops: Denops): Promise<void> {
await denops.cmd("enew");
await aider().run(denops);
await denops.cmd("b#");
}
export async function prepareAiderBuffer(denops: Denops, openBufferType: BufferLayout): Promise<void> {
if (openBufferType === "floating") {
await aider().silentRun(denops);
silentRun(denops);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ぐぬぬ

Copy link
Owner

Choose a reason for hiding this comment

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

( ;´。 `;)

} else {
await openAiderBuffer(denops, openBufferType);
await denops.cmd("wincmd p");
Expand Down
2 changes: 1 addition & 1 deletion denops/aider/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function main(denops: Denops): Promise<void> {
await buffer.openAiderBuffer(denops, openBufferType);
}),

await command("silentRun", "0", () => aider().silentRun(denops)),
await command("silentRun", "0", () => buffer.silentRun(denops)),

await command("hideVisualSelectFloatingWindow", "0", async () => {
await buffer.hideVisualSelectFloatingWindow(denops);
Expand Down
6 changes: 0 additions & 6 deletions denops/aider/mockAiderCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export const commands: AiderCommand = {
mockAiderBufnr = bufnr;
},

silentRun: async (denops: Denops): Promise<undefined> => {
await denops.cmd("enew");
await commands.run(denops);
await denops.cmd("b#"); // hide buffer
},

sendPrompt: async (denops: Denops, _jobId: number, prompt: string): Promise<undefined> => {
await fn.feedkeys(denops, `ainput: ${prompt}\n`, "x");
},
Expand Down