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?

local counter_hl_name = 'RefjumpCounter'

---Create fallback highlight group if it doesn't exist
function M.create_fallback_hl_group(fallback_hl)
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer if we always use the RefjumpCounter highlight group, and just link it to WarningMsg if it isn't set (that highlight group should always exist). You can thereby remove the counter.hl_group option.

Comment on lines 66 to 79
---Find the index of a reference in the references list
---@param reference RefjumpReference
---@param references RefjumpReference[]
---@return integer|nil
local function find_reference_index(reference, references)
for i, ref in ipairs(references) do
if ref.range.start.line == reference.range.start.line
and ref.range.start.character == reference.range.start.character then
return i
end
end
return nil
end

Copy link
Owner

Choose a reason for hiding this comment

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

You should be able to refactor this to use vim.iter instead for a less imperative implementation, something like this (I haven't actually tried running it though):

local function find_reference_index(reference, references)
  local idx, _ = vim.iter(references):enumerate():find(function(i, ref)
    return ref.range.start.line == reference.range.start.line
       and ref.range.start.character == reference.range.start.character
  end)

  return idx
end

Comment on lines 92 to 98
-- Display current index and total count
local current_index = find_reference_index(next_reference, references)
if current_index then
local total_count = #references
local bufnr = vim.api.nvim_get_current_buf()
require('refjump.counter').show(current_index, total_count, bufnr)
end
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer if we did the check for counter.enable here before doing all this logic, instead of in require('refjump.counter').show(). And maybe break out this whole block to its own function, that you can wrap in if not require('refjump').get_options().counter.enable.

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

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