-
Notifications
You must be signed in to change notification settings - Fork 1
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 openAiderBuffer, small fix getAiderBuffer #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,14 +54,23 @@ export async function exitAiderBuffer(denops: Denops): Promise<void> { | |
*/ | ||
export async function openAiderBuffer( | ||
denops: Denops, | ||
aiderBuf: AiderBuffer | undefined, | ||
openBufferType: BufferLayout, | ||
): Promise<undefined | boolean> { | ||
// TODO openBufferTypeで大きく分岐するようリファクタすべき | ||
// return typeもbooleanにできる | ||
if (aiderBuf && openBufferType === "floating") { | ||
await openFloatingWindow(denops, aiderBuf.bufnr); | ||
return true; | ||
): Promise<void> { | ||
const aiderBuf = await getAiderBuffer(denops); | ||
if (openBufferType === "floating") { | ||
if (aiderBuf === undefined) { | ||
const bufnr = ensure( | ||
await n.nvim_create_buf(denops, false, true), | ||
is.Number, | ||
); | ||
await openFloatingWindow(denops, bufnr); | ||
await aider().run(denops); | ||
return; | ||
} | ||
if (aiderBuf !== undefined) { | ||
await openFloatingWindow(denops, aiderBuf.bufnr); | ||
return; | ||
} | ||
} | ||
|
||
if (openBufferType === "split" || openBufferType === "vsplit") { | ||
|
@@ -70,14 +79,9 @@ export async function openAiderBuffer( | |
} else { | ||
await openSplitWindow(denops); | ||
} | ||
await aider().run(denops); | ||
return; | ||
} | ||
|
||
const bufnr = ensure(await n.nvim_create_buf(denops, false, true), is.Number); | ||
|
||
await openFloatingWindow(denops, bufnr); | ||
|
||
return; | ||
} | ||
|
||
export async function sendPromptWithInput( | ||
|
@@ -94,7 +98,7 @@ export async function sendPromptWithInput( | |
const openBufferType = await getOpenBufferType(denops); | ||
|
||
if (openBufferType === "floating") { | ||
await openAiderBuffer(denops, aiderBuf, openBufferType); | ||
await openAiderBuffer(denops, openBufferType); | ||
await sendPromptFromFloatingWindow(denops, input); | ||
return; | ||
} | ||
|
@@ -142,7 +146,10 @@ export async function openFloatingWindowWithSelectedCode( | |
return; | ||
} | ||
} | ||
const backupPrompt = await getPromptFromVimVariable(denops, "aider_visual_select_buffer_prompt"); | ||
const backupPrompt = await getPromptFromVimVariable( | ||
denops, | ||
"aider_visual_select_buffer_prompt", | ||
); | ||
const bufnr = ensure(await n.nvim_create_buf(denops, false, true), is.Number); | ||
await openFloatingWindow(denops, bufnr); | ||
|
||
|
@@ -157,9 +164,16 @@ export async function openFloatingWindowWithSelectedCode( | |
await n.nvim_buf_set_keymap(denops, bufnr, "n", "q", "<cmd>close!<CR>", { | ||
silent: true, | ||
}); | ||
await n.nvim_buf_set_keymap(denops, bufnr, "n", "Q", "<cmd>AiderHideVisualSelectFloatingWindow<CR>", { | ||
silent: true, | ||
}); | ||
await n.nvim_buf_set_keymap( | ||
denops, | ||
bufnr, | ||
"n", | ||
"Q", | ||
"<cmd>AiderHideVisualSelectFloatingWindow<CR>", | ||
{ | ||
silent: true, | ||
}, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. biomeデフォルトの80文字/行でformatさせると改行増えすぎるなあという気持ち There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. biome教に殉じるか、設定増やすかですねえ。 |
||
await n.nvim_buf_set_keymap( | ||
denops, | ||
bufnr, | ||
|
@@ -182,7 +196,11 @@ export async function openFloatingWindowWithSelectedCode( | |
* @param {number} bufnr - バッファ番号。 | ||
* @param {string[]} backupPrompt - バックアッププロンプトの内容。 | ||
*/ | ||
async function handleBackupPrompt(denops: Denops, bufnr: number, backupPrompt: string[]) { | ||
async function handleBackupPrompt( | ||
denops: Denops, | ||
bufnr: number, | ||
backupPrompt: string[], | ||
) { | ||
await v.g.set(denops, "aider_visual_select_buffer_prompt", undefined); | ||
await n.nvim_buf_set_lines(denops, bufnr, 0, -1, true, backupPrompt); | ||
await feedkeys(denops, "Gi"); | ||
|
@@ -198,7 +216,11 @@ async function handleBackupPrompt(denops: Denops, bufnr: number, backupPrompt: s | |
* @param {number} bufnr - バッファ番号。 | ||
* @param {string[]} words - バッファに設定するコード行。 | ||
*/ | ||
async function handleNoBackupPrompt(denops: Denops, bufnr: number, words: string[]) { | ||
async function handleNoBackupPrompt( | ||
denops: Denops, | ||
bufnr: number, | ||
words: string[], | ||
) { | ||
const filetype = ensure( | ||
await fn.getbufvar(denops, "%", "&filetype"), | ||
is.String, | ||
|
@@ -211,7 +233,10 @@ async function handleNoBackupPrompt(denops: Denops, bufnr: number, words: string | |
await n.nvim_buf_set_lines(denops, bufnr, 0, 1, true, []); | ||
await n.nvim_buf_set_lines(denops, bufnr, -1, -1, true, [""]); | ||
|
||
const additionalPrompt = await getPromptFromVimVariable(denops, "aider_additional_prompt"); | ||
const additionalPrompt = await getPromptFromVimVariable( | ||
denops, | ||
"aider_additional_prompt", | ||
); | ||
if (additionalPrompt) { | ||
await n.nvim_buf_set_lines(denops, bufnr, -1, -1, true, ["# rule"]); | ||
await n.nvim_buf_set_lines(denops, bufnr, -1, -1, true, additionalPrompt); | ||
|
@@ -222,7 +247,9 @@ async function handleNoBackupPrompt(denops: Denops, bufnr: number, words: string | |
await feedkeys(denops, "Gi"); | ||
} | ||
|
||
export async function hideVisualSelectFloatingWindow(denops: Denops): Promise<void> { | ||
export async function hideVisualSelectFloatingWindow( | ||
denops: Denops, | ||
): Promise<void> { | ||
const bufferContent = ensure( | ||
await denops.call("getbufline", "%", 1, "$"), | ||
is.ArrayOf(is.String), | ||
|
@@ -386,7 +413,8 @@ export async function getAiderBuffer( | |
// プロセスが動いていない場合(session復元時など)はバッファを削除 | ||
if (!aider().isTestMode() && jobId === 0) { | ||
await denops.cmd(`b ${bufnr}`); | ||
await denops.cmd("bp | sp | bn | bd!"); // delete buffer without changing window | ||
await denops.cmd("b#"); | ||
await denops.cmd("bd! #"); | ||
continue; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,13 +92,7 @@ export async function main(denops: Denops): Promise<void> { | |
}), | ||
|
||
await command("run", "0", async () => { | ||
const aiderBuf = await buffer.getAiderBuffer(denops); | ||
await buffer.openAiderBuffer(denops, aiderBuf, openBufferType); | ||
|
||
if (aiderBuf === undefined) { | ||
await aider().run(denops); | ||
return; | ||
} | ||
await buffer.openAiderBuffer(denops, openBufferType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Action Required: Remaining usages of The search revealed that 🔗 Analysis chainLGTM: Simplified implementation of the The change directly calls To ensure this change doesn't introduce any regressions, let's verify that 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any remaining usage of 'aiderBuf' in the codebase
# Test: Search for 'aiderBuf' in all TypeScript files
rg --type typescript 'aiderBuf'
Length of output: 66 Script: #!/bin/bash
# Description: Check for any remaining usage of 'aiderBuf' in TypeScript files
# Test: Search for 'aiderBuf' in all TypeScript files using the correct type alias
rg --type ts 'aiderBuf'
Length of output: 1323 |
||
}), | ||
|
||
await command("silentRun", "0", () => aider().silentRun(denops)), | ||
|
@@ -129,9 +123,7 @@ export async function main(denops: Denops): Promise<void> { | |
if (openBufferType === "floating") { | ||
await aider().silentRun(denops); | ||
} else { | ||
const aiderBuf = await buffer.getAiderBuffer(denops); | ||
await buffer.openAiderBuffer(denops, aiderBuf, openBufferType); | ||
await aider().run(denops); | ||
await buffer.openAiderBuffer(denops, openBufferType); | ||
await denops.cmd("wincmd p"); | ||
console.log("Run AiderAddCurrentFile again."); | ||
return; | ||
|
@@ -162,9 +154,7 @@ export async function main(denops: Denops): Promise<void> { | |
if (openBufferType === "floating") { | ||
await aider().silentRun(denops); | ||
} else { | ||
const aiderBuf = await buffer.getAiderBuffer(denops); | ||
await buffer.openAiderBuffer(denops, aiderBuf, openBufferType); | ||
await aider().run(denops); | ||
await buffer.openAiderBuffer(denops, openBufferType); | ||
await denops.cmd("wincmd p"); | ||
console.log("Run AiderAddReadCurrentFile again."); | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Simplify conditional logic in 'openAiderBuffer' function
After checking
if (aiderBuf === undefined)
and returning, the subsequent checkif (aiderBuf !== undefined)
is redundant and can be replaced with anelse
statement for improved readability.Apply this diff to simplify the conditional logic:
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
biomeくんがelseを消そうとするんじゃ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsukimizake、ご指摘ありがとうございます。Biomeが
else
を削除するとのこと、承知しました。それではこのままにしておきます。/(=´x`=)\
✏️ Learnings added