Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get diagnostics from location list and quickfix list #24

Open
mphe opened this issue Jan 10, 2022 · 7 comments
Open

Get diagnostics from location list and quickfix list #24

mphe opened this issue Jan 10, 2022 · 7 comments

Comments

@mphe
Copy link
Contributor

mphe commented Jan 10, 2022

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.

@tbung
Copy link
Contributor

tbung commented Jan 12, 2022

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.

@petertriho
Copy link
Owner

Yep, sorry been a little busy. Will test and merge it over the weekend

@mphe
Copy link
Contributor Author

mphe commented Feb 27, 2022

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

@petertriho
Copy link
Owner

petertriho commented Feb 28, 2022

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

@mphe
Copy link
Contributor Author

mphe commented Feb 28, 2022

I've tried QuickFixCmdPost but it doesn't work, too. According to the docs it only applies to the quick fix list.

@petertriho
Copy link
Owner

petertriho commented Mar 1, 2022

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

@mphe
Copy link
Contributor Author

mphe commented Mar 1, 2022

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.

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

No branches or pull requests

3 participants