This commit is contained in:
pmcc committed 2026-10-17 17:49:09 -04:00
1 parent b2d375f484
commit 1349e3b76f
7 files changed
+186 -14

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
vim.pack.add({
{ src = "https://github.com/petertriho/nvim-scrollbar" },
})
-- Show illuminated word matches as scrollbar marks. nvim-scrollbar's render
-- autocmds (BufWinEnter/WinEnter/TextChanged/VimResized/WinScrolled) do not fire
-- on CursorMoved, which is when illuminate refreshes its references, so hook
-- those events directly, mirroring how the built-in diagnostic handler works.
-- illuminate also refreshes its own refs ~(delay 100ms) after CursorMoved, so
-- re-run the highlight refresh on a small debounce for snappy bars.
local utils = require("scrollbar.utils")
local render = require("scrollbar").throttled_render
local function update_illuminate_marks()
local bufnr = vim.api.nvim_get_current_buf()
local config = require("scrollbar.config").get()
if
config.show == false
or not vim.api.nvim_buf_is_valid(bufnr)
or vim.tbl_contains(config.excluded_buftypes, vim.bo[bufnr].buftype)
or vim.tbl_contains(config.excluded_filetypes, vim.bo[bufnr].filetype)
then
return
end
local ok, reference = pcall(require, "illuminate.reference")
if not ok then
return
end
-- illuminate stores refs as { {0-indexed line, col}, {0-indexed line, col} },
-- sorted. Several refs can share a line, so keep one mark per line.
local illuminate_marks = {}
local last_line = -1
for _, ref in ipairs(reference.buf_get_references(bufnr)) do
local line = ref[1][1]
if line ~= last_line then
last_line = line
illuminate_marks[#illuminate_marks + 1] = {
line = line,
text = "≡",
type = "Illuminate",
level = 1,
}
end
end
local marks = utils.get_scrollbar_marks(bufnr)
marks.Illuminate = illuminate_marks
utils.set_scrollbar_marks(bufnr, marks)
render()
end
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorHold", "TextChanged", "BufEnter", "WinEnter" }, {
group = vim.api.nvim_create_augroup("scrollbar_illuminate", { clear = true }),
callback = function(args)
update_illuminate_marks()
if args.event == "CursorMoved" or args.event == "TextChanged" then
vim.defer_fn(update_illuminate_marks, 250)
end
end,
})
require("scrollbar").setup({
excluded_filetypes = { "neo-tree" },
handle = {
highlight = "PmenuSbar",
},
marks = {
Illuminate = { text = "≡", priority = 8, highlight = "Special" },
Search = { highlight = "DiagnosticVirtualTextInfo" },
Error = { highlight = "DiagnosticFloatingError" },
Warn = { highlight = "DiagnosticFloatingWarn" },
Info = { highlight = "DiagnosticFloatingInfo" },
Hint = { highlight = "DiagnosticFloatingHint" },
GitAdd = { highlight = "GitSignsAdd" },
GitChange = { highlight = "GitSignsChange" },
GitDelete = { highlight = "GitSignsDelete" },
},
handlers = {
search = false, -- requires hlslens
diagnostic = true,
gitsigns = true,
},
})