nvim-scrollbar
nvim-scrollbar copied to clipboard
Get diagnostics from location list and quickfix list
Is your feature request related to a problem? Please describe. Currently diagnostics only seem to be fetched from LSP. However, I also use ALE and all those diagnostics don't appear in the scrollbar.
Describe the solution you'd like Include entries from the location and quckfix list into the sidebar.
I did a quick research on how to accomplish that.
You can call getloclist()
and getqflist()
, which will return a list of dicts. Each dict contains a "type" key that can be "I", "W", or "E", and an "lnum" key for the line number. For getqflist
you probably also have to compare the "bufnr" key to the current buffer. getloclist
accepts an argument to specifiy the current window.
Then proceed as usual to add a marker.
Should be rather easy once #26 is merged, either as a handler in your configs or in the project, if @petertriho wants to include this.
Yep, sorry been a little busy. Will test and merge it over the weekend
Now that custom handlers exist, I wrote a simple handler to support entries in the location list.
require("scrollbar.handlers").register("locationlist", function(bufnr)
local winnr = vim.fn.get(vim.fn.win_findbuf(bufnr), 0, -1)
if winnr == -1 then
return {}
end
local ll = vim.fn.getloclist(winnr)
local marks = {}
for _, entry in pairs(ll) do
table.insert(marks, { line = entry.lnum, type = mark_type_map[entry.type]})
end
return marks
end)
Should I create another pull request and add this as an example in the readme or create a dedicated handler script?
Unfortunately, there is no autocmd for when the location list was updated, so the markers don't refresh automatically until one of the configured autocmds is triggered, e.g. scrolling.
I also tried the following, but that also didn't work.
augroup scrollbar_loclist
autocmd!
autocmd User ALELintPost,ALEFixPost,CocDiagnosticChange lua require('scrollbar.handlers').show();require('scrollbar').render()
augroup END
This is something I definitely want to add as a in-built handler and, eventually, add a wiki for other things.
I'll investigate further over the weekend, but have you tried:
" quickfix
autocmd QuickFixCmdPost [^l]* lua require('scrollbar.handlers').show();require('scrollbar').render()
" location
autocmd QuickFixCmdPost l* lua require('scrollbar.handlers').show();require('scrollbar').render()
Probably should refactor require('scrollbar.handlers').show()
to accept an optional handler name + buffer number to only update that handler
I've tried QuickFixCmdPost
but it doesn't work, too. According to the docs it only applies to the quick fix list.
Looks like we'll need to handle both QuickFixCmdPost
and Filetype qf
autocmds to support qf/location list but the scrollbar render implementation needs to change since it only works with current buffer/window
local function qf_test()
local winid = vim.api.nvim_get_current_win()
local info = vim.fn.getwininfo(winid)
local winnr = info[1].winnr
local loclist = vim.fn.getloclist(winnr)
end
vim.api.nvim_add_user_command("QuickfixTest", qf_test, {})
-- autocmd Filetype qf QuickfixTest
Ok, to be more precise, the autocmds get called, but the location list has not been updated at this point. I haven't implemented a quickfix list handler, yet.