Skip to content

Maintenance: OutputPanelScopeImpl - Fix stale outputPanel reference#1586

Open
claude[bot] wants to merge 1 commit intomasterfrom
maintenance/fix-output-panel-stale-reference
Open

Maintenance: OutputPanelScopeImpl - Fix stale outputPanel reference#1586
claude[bot] wants to merge 1 commit intomasterfrom
maintenance/fix-output-panel-stale-reference

Conversation

@claude
Copy link

@claude claude bot commented Feb 24, 2026

Summary

  • Area inspected: vim-engine/src/main/kotlin/com/maddyhome/idea/vim/thinapi/OutputPanelScopeImpl.kt
  • Starting point was a random file (VimOutputPanelServiceBase.kt), which led to inspecting the related OutputPanelScopeImpl

Issue Found

When OutputPanelScopeImpl was changed from a class to an object singleton (commit 04d9282fb), the outputPanel property was left as a backing field:

private val outputPanel: VimOutputPanel = injector.outputPanel.getOrCreate(vimEditor, vimContext)

Since this is a Kotlin object, this field is initialized once when the singleton is first accessed. All subsequent calls to setText, appendText, clearText, etc. reuse the same stale VimOutputPanel instance — even if:

  • The user switched to a different editor
  • The original panel was closed (via user pressing q, or listeners in VimListenerManager/MotionGroup calling close())

Before the class→object change, OutputPanelScopeImpl() was instantiated fresh for each api.outputPanel { ... } call, so getOrCreate was called each time. After the change, that fresh evaluation only happens once.

Change Made

Made outputPanel a computed property with an explicit get(), consistent with:

  • vimEditor and vimContext in the same class
  • optionGroup in OptionScopeImpl
private val outputPanel: VimOutputPanel
    get() = injector.outputPanel.getOrCreate(vimEditor, vimContext)

This ensures each method call gets the current active panel (or creates a new one for the currently focused editor) via the existing getOrCreate mechanism.

Why This Improves the Code

  • Eliminates potential stale reference bugs when the output panel is closed and re-opened
  • Ensures the correct panel is used when the user switches editors between plugin calls
  • Makes the property consistent with the other computed properties in the same object

`outputPanel` was a `val` on the singleton object, meaning it was
captured once at initialization time via `getOrCreate`. After the
panel became inactive (e.g., user dismissed it or the associated
editor was closed), all subsequent `outputPanel { ... }` calls
continued to operate on this stale panel.

Change `outputPanel` to a computed property (`get()`) so it always
delegates to `injector.outputPanel.getOrCreate(...)`, which either
returns the current active panel or creates a fresh one for the
currently focused editor.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude claude bot force-pushed the maintenance/fix-output-panel-stale-reference branch from de053c4 to 9b20d56 Compare March 10, 2026 06:23
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.

0 participants