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

Conversation

tsukimizake
Copy link
Collaborator

@tsukimizake tsukimizake commented Oct 22, 2024

  • aiderCommand.sendPrompt()でペーストを使うのをやめて全てjobIdへのchansendにすることでカレントバッファがaiderバッファでないときでもsendPromptできるようにしました
  • silentAdd系のちらつきを解消しました

Summary by CodeRabbit

  • New Features

    • Enhanced prompt sending functionality for improved user interaction with the Aider buffer.
    • Added flexibility in buffer opening behavior when sending prompts and adding files.
  • Bug Fixes

    • Adjusted command implementations to prevent unintended buffer openings when adding current files.
  • Documentation

    • Updated comments for clarity regarding changes in functionality.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces significant modifications to the sendPrompt function across multiple files in the Aider module. Changes include the introduction of an optional parameter for buffer handling and adjustments to how prompts are sent to the Aider buffer. The new implementation splits prompts into lines and modifies the control flow for buffer operations, enhancing the flexibility of command executions without altering the overall structure of the commands.

Changes

File Change Summary
denops/aider/actualAiderCommand.ts Modified sendPrompt to split prompts into lines and send them using an escape sequence followed by a newline character. Updated comments to reflect changes in functionality.
denops/aider/bufferOperation.ts Updated sendPrompt to include an optional opts parameter for buffer handling. Added logic to conditionally open buffers based on opts.openBuf. Adjusted prepareAiderBuffer to call openAiderBuffer accordingly.
denops/aider/main.ts Enhanced addFileToAider to include an optional opts parameter. Updated command implementations to pass this parameter, modifying behavior to prevent buffer opening when adding files.

Possibly related PRs

Suggested reviewers

  • nekowasabi

🐇 In the land of code, where changes bloom,
Aider commands dance, dispelling the gloom.
With prompts now split, and buffers in tow,
Flexibility reigns, as we watch features grow!
Hopping through lines, with joy we declare,
The magic of updates is floating in air! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

await fn.feedkeys(denops, '"qp');
await denops.call("chansend", jobId, "\n");
const promptLines = prompt.split("\n");
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

issueの下の方のコメントでESC Ctrl-Mでaiderに送信せず改行できるって言ってるし私の手元環境でもうまく動いてるけどもしかしたら環境によって普通に送信されてしまったりするかもしれない

Copy link
Owner

Choose a reason for hiding this comment

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

[Q] \nから変更するメリットがあるのでしょうか 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

\nだとVisualとかで複数行入力したときに一行ずつaiderに送られてしまうんじゃ

Copy link
Owner

Choose a reason for hiding this comment

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

@tsukimizake
await fn.feedkeys(denops, "G"); がないと、毎回ターミナルウインドウでGを押して下まで移動しないといけなくなるので、これは必要かもです。

Copy link
Owner

Choose a reason for hiding this comment

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

ただ、ここでfeedkeysをするのはなんか違うきがする。プロンプト送信に徹したい。( ;´。 `;)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
denops/aider/bufferOperation.ts (1)

Line range hint 88-101: LGTM! Consider adding JSDoc for the new parameter.

The changes to the sendPrompt function improve its flexibility by allowing control over buffer opening. This is a good enhancement that maintains backward compatibility.

Consider adding JSDoc for the new opts parameter to improve code documentation:

/**
 * Sends a prompt to the Aider buffer.
 * @param {Denops} denops - The Denops instance.
 * @param {string} input - The prompt to send.
 * @param {Object} [opts={ openBuf: true }] - Options for sending the prompt.
 * @param {boolean} [opts.openBuf=true] - Whether to open the buffer before sending the prompt.
 */
export async function sendPrompt(denops: Denops, input: string, opts = { openBuf: true }): Promise<void> {
  // ... (existing implementation)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1bc6d25 and caf2408.

📒 Files selected for processing (3)
  • denops/aider/actualAiderCommand.ts (1 hunks)
  • denops/aider/bufferOperation.ts (2 hunks)
  • denops/aider/main.ts (5 hunks)
🧰 Additional context used
📓 Learnings (1)
denops/aider/actualAiderCommand.ts (2)
Learnt from: tsukimizake
PR: nekowasabi/aider.vim#18
File: denops/aider/aiderCommand.ts:45-53
Timestamp: 2024-09-30T14:46:06.173Z
Learning: In the `sendPrompt` function in `denops/aider/aiderCommand.ts`, replacing `fn.feedkeys` with `fn.append` did not work.
Learnt from: tsukimizake
PR: nekowasabi/aider.vim#23
File: denops/aider/actualAiderCommand.ts:76-79
Timestamp: 2024-10-05T15:24:04.950Z
Learning: `denops/aider/actualAiderCommand.ts` の `sendPrompt` 関数で直接 `chansend` を使用すると、入力が分割されてしまう可能性がある。
🔇 Additional comments (4)
denops/aider/actualAiderCommand.ts (1)

43-45: Improved prompt handling, but consider potential input splitting.

The new implementation of sendPrompt brings several improvements:

  1. It now handles multi-line prompts effectively by splitting and rejoining them.
  2. The use of \x1b\x0d (Esc + Ctrl-M) instead of \n is a clever way to avoid immediate submission, addressing the issue mentioned in the linked GitHub issue.
  3. Direct use of chansend aligns with the PR objective and allows the function to work regardless of the current buffer.

However, there's a potential concern:

A previous learning (PR #23) mentioned that direct use of chansend might lead to input being split. Let's verify if this is still a concern:

If the verification doesn't show any additional error handling, consider adding a safeguard against potential input splitting.

Would you like assistance in implementing additional error handling or input validation for the chansend call?

denops/aider/main.ts (3)

85-90: LGTM: Improved flexibility in addFileToAider function

The addition of the optional opts parameter with a default value of { openBuf: true } enhances the flexibility of the addFileToAider function. This change aligns well with the PR objectives of refactoring the sendPrompt functionality and allows for more granular control over buffer operations.


150-150: LGTM: Consistent behavior for "silent" commands

The silentAddCurrentFile and silentAddCurrentFileReadOnly commands have been updated to use { openBuf: false } when calling addFileToAider. This change improves consistency between the command names and their behavior, as "silent" commands now don't open a buffer when adding files.

Also applies to: 169-171


Line range hint 1-270: Overall assessment: Changes improve flexibility and consistency

The modifications to denops/aider/main.ts successfully refactor the sendPrompt functionality as intended. The changes introduce more flexible buffer handling options and improve consistency in command behavior. These enhancements align well with the PR objectives and should contribute to a more robust and user-friendly Aider plugin.

denops/aider/main.ts Show resolved Hide resolved
@@ -41,8 +41,8 @@ async function run(denops: Denops): Promise<undefined> {
*/
async function sendPrompt(denops: Denops, jobId: number, prompt: string): Promise<undefined> {
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
Copy link
Owner

Choose a reason for hiding this comment

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

これは知らなかった。 👍

@@ -148,8 +148,6 @@ export async function main(denops: Denops): Promise<void> {

await command("silentAddCurrentFile", "0", async () => {
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.

( ;´ワ `;)つ☆

@@ -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.

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

@nekowasabi
Copy link
Owner

@tsukimizake
いくつか質問を追加しました。

@nekowasabi
Copy link
Owner

質問は本筋とは関係ないのでLGTM

@nekowasabi nekowasabi merged commit dc1209b into nekowasabi:main Oct 22, 2024
2 checks passed
@tsukimizake tsukimizake deleted the refactor_sendPrompt branch October 22, 2024 11:11
@tsukimizake
Copy link
Collaborator Author

tsukimizake commented Oct 22, 2024

ちらつきが消えたのはいいのだけど本当にsilentになってしまったのでaider.sendPrompt内で下に/add ... みたいなmessage出すくらいはしてもいいかもしれねえ

@nekowasabi
Copy link
Owner

@tsukimizake
:done:
6a44cb1

This was referenced Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants