Skip to content

Improve progress bar - #43

Merged
nikero41 merged 1 commit into
mainfrom
progress-bar-improvements
Mar 30, 2026
Merged

Improve progress bar#43
nikero41 merged 1 commit into
mainfrom
progress-bar-improvements

Conversation

@nikero41

Copy link
Copy Markdown
Owner

This pull request refactors the LSP progress bar implementation to make it more robust, modular, and better suited for handling multiple concurrent tasks. The changes introduce a new ProgressBar class with improved state management and timer-based rendering, and update the autocmd setup to use the new interface.

Major improvements to progress bar architecture:

  • Refactored the progress bar logic into a ProgressBar class with internal state, task tracking, and timer-based rendering, replacing the previous stateless function-based approach. This allows for better handling of multiple LSP progress tasks and more reliable updates.
  • Added support for scheduling and batching progress bar rendering and clearing using timers, which reduces flicker and unnecessary redraws.
  • Introduced a new on_lsp_progress method to handle LSP progress events, replacing the inline logic in the autocmd callback. The autocmd now delegates directly to this method for better separation of concerns. [1] [2]

Enhancements to environment compatibility and cleanup:

  • Improved OSC sequence handling for tmux by using vim.env.TMUX and updated the OSC sequence construction for better compatibility.
  • Ensured that the progress bar is properly cleared and timers are stopped on exit by introducing a destroy method and updating the VimLeavePre autocmd to call it.

These changes collectively make the progress bar more reliable, extensible, and maintainable, especially when handling multiple simultaneous LSP tasks.

@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6729ece-8d11-4d00-a2f7-4f0e42be616b

📥 Commits

Reviewing files that changed from the base of the PR and between bc22a03 and 9c378ed.

📒 Files selected for processing (2)
  • lua/autocmds.lua
  • lua/nikero/progress_bar.lua

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Improved LSP progress indicator handling with better task tracking and rendering efficiency to reduce UI flickering.

Walkthrough

The LSP progress handling was refactored from static module methods to an instance-based architecture. The autocmd now delegates to a singleton progress bar object, which internally tracks tasks, schedules renders via timers, coalesces updates, and manages state to suppress redundant UI sends.

Changes

Cohort / File(s) Summary
Autocmd Delegation
lua/autocmds.lua
Simplified LspProgress callback to invoke progress_bar:on_lsp_progress(args), removing prior inline logic for branching on value.kind and percentage.
Progress Bar Restructuring
lua/nikero/progress_bar.lua
Refactored from static methods to instance-based design with task aggregation by client/token, timer-based rendering with coalescing, state tracking (last_state, last_percent), and vim.api.nvim_ui_send-based OSC delivery. Changed module export from static table to singleton instance. Added on_lsp_progress(), destroy() lifecycle, and internal task/timer management.

Sequence Diagram(s)

sequenceDiagram
    participant LSP as LSP Server
    participant Autocmd
    participant ProgressBar as Progress Bar<br/>(Singleton)
    participant Timer as Timer
    participant VimAPI as Vim API

    LSP->>Autocmd: progress event (on_lsp_progress)
    Autocmd->>ProgressBar: on_lsp_progress(args)
    
    alt value.kind == "end"
        ProgressBar->>ProgressBar: remove task<br/>(clear state)
    else value.percentage
        ProgressBar->>ProgressBar: update task state<br/>(aggregate %)<br/>(track last_state)
    end
    
    ProgressBar->>ProgressBar: schedule render<br/>(coalesce updates)
    alt render_timer not active
        ProgressBar->>Timer: set_timeout(render_callback)
    end
    
    Timer->>ProgressBar: render_callback()
    ProgressBar->>ProgressBar: build OSC string<br/>(check last_percent<br/>suppress if no change)
    
    alt no tasks after delay
        ProgressBar->>ProgressBar: send clear signal
    else tasks exist
        ProgressBar->>VimAPI: nvim_ui_send(osc_string)
        VimAPI-->>ProgressBar: success or fail
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 The progress bar hops with state anew—
Tasks aggregated, timers spring to,
No more static paths, but singleton wise,
Coalescing renders beneath Vim's eyes.
State persists, redundant sends we eschew,
A refactor most elegant, through and through! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improve progress bar' directly aligns with the main objective of refactoring the LSP progress bar implementation to enhance its architecture and reliability.
Description check ✅ Passed The description comprehensively explains the refactoring of the progress bar into a class-based design with state management, timer-based rendering, and LSP progress event handling, all of which are reflected in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch progress-bar-improvements

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@nikero41
nikero41 merged commit e6d88fe into main Mar 30, 2026
3 checks passed
@nikero41
nikero41 deleted the progress-bar-improvements branch March 30, 2026 15:03
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