Skip to content

Conversation

@subev
Copy link

@subev subev commented Dec 26, 2025

Summary

  • Add inline virtual text counter showing current reference position (e.g., [3/12])
  • Counter displays at end of line where cursor jumps
  • Automatically clears when highlights are cleared
  • Configurable via new counter options

Changes

  • New module: lua/refjump/counter.lua - handles virtual text display
  • Modified: lua/refjump/jump.lua - calls counter instead of vim.notify
  • Modified: lua/refjump/highlight.lua - clears counter with highlights
  • Modified: lua/refjump/init.lua - adds counter configuration options

Configuration

require('refjump').setup({
  counter = {
    enable = true,        -- Enable/disable counter (default: true)
    hl_group = 'WarningMsg', -- Highlight group (default: bold orange)
  }
})

Demo

When jumping between references with ]r/[r, the counter appears at the end of the line:

  • Shows [1/5], [2/5], etc.
  • Bold orange text for high visibility
  • Clears automatically when moving cursor or pressing escape

Replaces the previous vim.notify() notification with inline display inspired by nvim-hlslens.

- Add new counter.lua module to display [X/Y] reference count
- Show counter as virtual text at end of line when jumping
- Counter clears automatically when highlights are cleared
- Configurable via counter.enable and counter.hl_group options
- Default styling: bold orange text for high visibility
Copy link
Owner

@mawkler mawkler left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

I was also thinking that perhaps you should break out the logic for getting the current index and the total number of references to its own function. That way one could use it if they for example wanted to instead display that information in the statusline instead of using virtual text. That function would return the two values current_reference_index, total_reference_count (or with similar names). I notice however when looking through my code that we're passing around state a lot, including the references and current reference. So perhaps the best way would be to create a Lua "object" for storing that state. What do you think?

subev added 3 commits January 3, 2026 22:02
- Add lua/refjump/state.lua for per-buffer state storage
- Expose get_reference_info() for statusline integration
- Remove counter.hl_group option, link RefjumpCounter to WarningMsg
- Refactor find_reference_index() to use vim.iter
- Move counter.enable check to jump.lua with show_counter() helper
- Add test infrastructure with plenary.nvim (12 tests)
- Update CI workflow to run tests on push/PR
The state was being cleared immediately on CursorMoved after a jump,
preventing lualine/statusline from reading reference info.

- Restore highlight_references toggle flag in highlight.lua
- Add highlight.is_active() to expose the flag
- Update state.is_active() to delegate to highlight.is_active()
- Fix disable() to use toggle pattern: first call flips flag, second clears
- Update tests to reflect new is_active() behavior
- Document counter.enable option in configuration
- Document RefjumpCounter highlight group
- Add statusline integration section with lualine example
@subev subev requested a review from mawkler January 3, 2026 21:23
@subev
Copy link
Author

subev commented Jan 3, 2026

Hey @mawkler, thanks for the feedback! I've addressed all your comments:
Changes made:

  1. Removed counter.hl_group option - Now always using RefjumpCounter highlight group, linked to WarningMsg by default if not set by the user
  2. Refactored find_reference_index() to use vim.iter - Cleaner functional style as you suggested
  3. Moved counter.enable check to jump.lua - Created a show_counter() helper function that wraps the logic
  4. Added state.lua module for statusline integration - As you suggested, I created a module to store per-buffer state and exposed get_reference_info() so users can display the counter in their statusline (e.g., lualine) instead of using virtual text
    Additional work:
  • Added test infrastructure with plenary.nvim (12 tests for the state module)
  • Updated CI workflow to run tests on push/PR
  • Updated README with the new counter option, highlight groups documentation, and a lualine integration example

Copy link
Owner

@mawkler mawkler left a comment

Choose a reason for hiding this comment

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

This looks very good! I have a couple of smaller thoughts on your changes though.

---Find the index of a reference in the references list
---@param reference RefjumpReference
---@param references RefjumpReference[]
---@return integer|nil
Copy link
Owner

Choose a reason for hiding this comment

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

This is a very minor nit, but everywhere where you have type | nil you can replace with type? which is slightly cleaner in my opinion

if not highlight_references then
vim.api.nvim_buf_clear_namespace(0, highlight_namespace, 0, -1)
require('refjump.counter').clear(0)
require('refjump.state').clear()
Copy link
Owner

Choose a reason for hiding this comment

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

The state shouldn't be cleared here, right? If the user just wants to disables the highlights, they might still want to repeat the same reference jump with demicolon.nvim, and so in that case it's still useful to reuse the state

You'll then have to change your statusline example in the README to use the is_active() method to check if the component should be displayed or not

Comment on lines +73 to +75
---Get info about current reference position (for statusline use)
---@param bufnr? integer Buffer number (defaults to current buffer)
---@return { index: integer|nil, total: integer }
Copy link
Owner

Choose a reason for hiding this comment

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

You don't need to repeat this documentation, it gets reused from the assigned require('refjump.state').get_reference_info, so you can just remove it here

Comment on lines +36 to +40
---Check if reference navigation is currently active
---@return boolean
function M.is_active()
return require('refjump.highlight').is_active()
end
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps this method should be moved to lua/refjump/init.lua instead since this is more of a user facing method

Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for adding tests! If you don't mind, could you add a couple of lines to the README that explains how to run the tests?

name: Pandoc to Vimdoc
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Copy link
Owner

@mawkler mawkler Jan 5, 2026

Choose a reason for hiding this comment

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

Is this conditional neccessary? Isn't this already covered by lines 3-4 in this file?

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