fix: lazy load CodeCompanion on commands#1577
Open
ayamir wants to merge 1 commit into
Open
Conversation
c9c4c6c to
a87e736
Compare
There was a problem hiding this comment.
Pull request overview
Changes the codecompanion.nvim lazy-loading trigger from event = "VeryLazy" to a cmd = {...} list, so the plugin loads only when one of its user-facing commands is invoked. This avoids running CodeCompanion's setup (which registers autocmds and pulls in blink/copilot via completion-provider detection) during ordinary edit/save/quit sessions, addressing the stale-UI report in #1520.
Changes:
- Replace
event = "VeryLazy"with acmdlist (CodeCompanion,CodeCompanionActions,CodeCompanionChat,CodeCompanionCLI,CodeCompanionCmd,CodeCompanionHistory,CodeCompanionSummaries) for lazy loading.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Findings
Issue #1520 reports that saving and quitting with
ZZor:wqcan leave a stale Neovim UI in the terminal. The comments narrow this down to an autocmd-related timing issue::wfollowed by:qworks reliably.:noautocmd wqavoids the issue.use_chatis disabled.The current config loads
codecompanion.nvimonVeryLazywheneversettings.use_chatis true. That means normal editing sessions load CodeCompanion even if the chat feature is never used.Further investigation shows that CodeCompanion setup is not a no-op:
codecompanion.buffersautocmds and history-extensionUserautocmds;require("blink.cmp"), which can trigger lazy.nvim's module loader;So the old
VeryLazytrigger expands the active runtime surface during ordinary edit/save/quit sessions. This matches the issue comments: disablinguse_chatavoids the problem even when the user is not actively using chat.I also checked closed upstream CodeCompanion issues/PRs. I did not find the exact same stale-terminal-UI report, but the related history supports this diagnosis:
CodeCompanion.setup()so completion autocmds are registered during setup.require(...)side effects (blink.compatmadecmpdetection ambiguous).VimLeavePrefix where the autocmd group had to useclear = falseso multiple cleanup callbacks were preserved.So this does not point to one single broken autocmd in our config. The stronger conclusion is that loading CodeCompanion on
VeryLazyopts every normal editing session into CodeCompanion's setup-time completion/autocmd/process surface, even when chat is never used.Why This Change
This changes CodeCompanion to load only when one of its user-facing commands is executed. That keeps chat functionality available, but avoids installing chat/history autocmds during ordinary edit/save/quit workflows.
This is a conservative fix because it narrows the plugin's active surface instead of changing save/quit behavior globally or disabling the chat feature by default.
Impact
use_chat = true.ZZ/:wqsessions that do not use chat avoid CodeCompanion's autocmds.CodeCompanion,CodeCompanionActions,CodeCompanionChat,CodeCompanionCLI,CodeCompanionCmd,CodeCompanionHistory, andCodeCompanionSummaries.Fixes #1520