Skip to content

feat(tmux): robust tmux exit and prevent layout change on AddCurrentFile#50

Merged
nekowasabi merged 4 commits intomainfrom
feat/tmux-support-commands
Aug 9, 2025
Merged

feat(tmux): robust tmux exit and prevent layout change on AddCurrentFile#50
nekowasabi merged 4 commits intomainfrom
feat/tmux-support-commands

Conversation

@nekowasabi
Copy link
Copy Markdown
Owner

@nekowasabi nekowasabi commented Aug 9, 2025

Summary

  • AiderExit: Always clean up tmux pane; guard missing var to avoid Vim(unlet):E108.
  • AddCurrentFile: Skip prepare/reattach when tmux pane already exists to prevent join-pane from resizing layout.
  • Tests: Add tmux-mode tests for prompt send, add-current-file behavior, and exit cleanup.

Details

  • :AiderExit now calls exit routine unconditionally and removes g:aider_tmux_pane_id only if it exists.
  • In split/vsplit tmux mode, if g:aider_tmux_pane_id exists, do not call prepareAiderBuffer so layout stays unchanged.
  • Updated tests/aider_tmux_test.ts and ensured suite passes.

Test plan

  • deno test --allow-env --allow-run --allow-net tests
  • Verify 17 tests pass locally and in CI.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of global variables to prevent errors when removing non-existent tmux pane IDs during exit and buffer operations.
    • Adjusted buffer preparation logic to avoid unnecessary actions when using tmux splits, ensuring a smoother layout experience.
  • Tests

    • Added new tests to verify tmux-related functionality, including prompt sending, file addition, and proper cleanup of global variables.

…xit always clean up tmux pane

- Skip prepare/reattach in split/vsplit when a tmux pane already exists to prevent join-pane resizing on AddCurrentFile
- Make :AiderExit always invoke exit handler so tmux pane is cleaned up even without an open buffer
- Add tests covering tmux prompt send, add-current-file behavior, and exit cleanup
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce existence checks before removing the global variable aider_tmux_pane_id in both the main command and buffer operation logic. The buffer preparation logic is updated to skip unnecessary steps when a tmux pane is already active. The test suite is expanded with new tmux-related tests to verify correct behavior and cleanup.

Changes

Cohort / File(s) Change Summary
Aider Command Exit Logic
denops/aider/actualAiderCommand.ts, denops/aider/bufferOperation.ts
Added checks to ensure the global variable aider_tmux_pane_id exists before attempting to remove it during exit operations, preventing errors if the variable is absent.
Buffer Preparation and Exit Flow
denops/aider/main.ts
Modified buffer preparation to skip re-attaching when a tmux pane is active, and simplified exit command logic to always call the buffer exit function.
Tmux-Related Test Coverage
tests/aider_tmux_test.ts
Added four new tests simulating tmux environments, verifying prompt sending, file addition, and proper cleanup of the tmux pane ID variable; updated imports for buffer content assertion.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Vim
    participant AiderPlugin
    participant Tmux

    User->>Vim: Issues Aider exit command
    Vim->>AiderPlugin: Calls exit logic
    AiderPlugin->>Vim: Check if g:aider_tmux_pane_id exists
    alt Variable exists
        AiderPlugin->>Vim: Remove g:aider_tmux_pane_id
    else Variable does not exist
        AiderPlugin-->>Vim: Skip removal
    end
    AiderPlugin->>Tmux: Kill pane (if needed)
    Vim->>User: Command completes
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • tsukimizake

Poem

In a tmux pane, I hop with glee,
Checking variables before I flee.
No more errors when I go,
My cleanup’s neat, my tests now show!
With every hop, my code’s more bright—
A tidy warren, bug-free delight.
🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4be2728 and 64f9ddd.

📒 Files selected for processing (1)
  • denops/aider/main.ts (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/tmux-support-commands

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

Copy link
Copy Markdown
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

🧹 Nitpick comments (1)
tests/aider_tmux_test.ts (1)

67-82: Use an assertion helper instead of manual throw

Lines 78-81 manually check exists() and throw. Prefer using assertEquals(hasPane, 0) (or assert) for consistency with the rest of the suite.

-if (hasPane === 1) {
-  throw new Error("tmux pane id should be cleared by AiderExit");
-}
+assertEquals(hasPane, 0, "tmux pane id should be cleared by AiderExit");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 485a4f4 and 4be2728.

📒 Files selected for processing (4)
  • denops/aider/actualAiderCommand.ts (1 hunks)
  • denops/aider/bufferOperation.ts (1 hunks)
  • denops/aider/main.ts (2 hunks)
  • tests/aider_tmux_test.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: tsukimizake
PR: nekowasabi/aider.vim#28
File: .github/workflows/deno.yml:85-91
Timestamp: 2024-10-12T13:50:39.857Z
Learning: Tests in 'aider.vim' require the `-A` flag when running Deno tests because they use Deno APIs that need elevated permissions.
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: nekowasabi
PR: nekowasabi/aider.vim#35
File: tests/aider_test.ts:51-59
Timestamp: 2024-10-24T10:59:24.483Z
Learning: tests/aider_test.ts では、仕様上 `await sleep(SLEEP_BEFORE_ASSERT);` が必要であり、これを削除すると正しく動作しません。
Learnt from: tsukimizake
PR: nekowasabi/aider.vim#33
File: denops/aider/main.ts:104-104
Timestamp: 2024-10-22T04:24:37.284Z
Learning: In `denops/aider/main.ts`, when calling `buffer.sendPrompt`, it's permissible to omit the `opts` parameter since it has a default value.
📚 Learning: 2024-10-12T13:50:39.857Z
Learnt from: tsukimizake
PR: nekowasabi/aider.vim#28
File: .github/workflows/deno.yml:85-91
Timestamp: 2024-10-12T13:50:39.857Z
Learning: Tests in 'aider.vim' require the `-A` flag when running Deno tests because they use Deno APIs that need elevated permissions.

Applied to files:

  • tests/aider_tmux_test.ts
  • denops/aider/actualAiderCommand.ts
  • denops/aider/main.ts
  • denops/aider/bufferOperation.ts
📚 Learning: 2024-10-24T10:59:24.483Z
Learnt from: nekowasabi
PR: nekowasabi/aider.vim#35
File: tests/aider_test.ts:51-59
Timestamp: 2024-10-24T10:59:24.483Z
Learning: tests/aider_test.ts では、仕様上 `await sleep(SLEEP_BEFORE_ASSERT);` が必要であり、これを削除すると正しく動作しません。

Applied to files:

  • tests/aider_tmux_test.ts
  • denops/aider/actualAiderCommand.ts
  • denops/aider/main.ts
  • denops/aider/bufferOperation.ts
📚 Learning: 2024-10-22T04:24:37.284Z
Learnt from: tsukimizake
PR: nekowasabi/aider.vim#33
File: denops/aider/main.ts:104-104
Timestamp: 2024-10-22T04:24:37.284Z
Learning: In `denops/aider/main.ts`, when calling `buffer.sendPrompt`, it's permissible to omit the `opts` parameter since it has a default value.

Applied to files:

  • tests/aider_tmux_test.ts
  • denops/aider/actualAiderCommand.ts
  • denops/aider/main.ts
  • denops/aider/bufferOperation.ts
📚 Learning: 2024-09-30T14:46:06.173Z
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.

Applied to files:

  • tests/aider_tmux_test.ts
  • denops/aider/actualAiderCommand.ts
  • denops/aider/main.ts
  • denops/aider/bufferOperation.ts
📚 Learning: 2024-10-05T15:24:04.950Z
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` を使用すると、入力が分割されてしまう可能性がある。

Applied to files:

  • tests/aider_tmux_test.ts
  • denops/aider/actualAiderCommand.ts
  • denops/aider/main.ts
  • denops/aider/bufferOperation.ts
🧬 Code Graph Analysis (1)
tests/aider_tmux_test.ts (3)
tests/testRunner.ts (1)
  • test (22-37)
tests/assertions.ts (3)
  • sleep (6-7)
  • assertAiderBufferAlive (46-52)
  • assertAiderBufferString (60-75)
tests/aider_test.ts (7)
  • denops (50-67)
  • denops (19-24)
  • denops (70-78)
  • denops (37-44)
  • denops (83-91)
  • denops (26-32)
  • denops (13-17)
🔇 Additional comments (3)
denops/aider/bufferOperation.ts (1)

61-65: Good defensive cleanup

The extra exists() guard prevents unlet:E108 when the variable is missing – nice touch.

denops/aider/actualAiderCommand.ts (1)

146-149: Consistent variable-existence check

Mirrors the safeguard added elsewhere, keeping the exit path robust in both code- and tmux-driven exits.

tests/aider_tmux_test.ts (1)

32-45: Assertion may be brittle

When g:aider_tmux_pane_id is set, sendPrompt routes the text to the tmux pane, not the Aider buffer.
assertAiderBufferString will only pass because of test stubs; in real usage the buffer won’t update.
Recommend asserting assertAiderBufferAlive (or inspecting the pane) instead of buffer contents to avoid false positives.

Comment thread denops/aider/main.ts
@nekowasabi nekowasabi merged commit de4f522 into main Aug 9, 2025
1 of 2 checks passed
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.

1 participant