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

Use title to determine wheather to update the quickfix/location list #3

Open
piotr-machura opened this issue Aug 28, 2021 · 2 comments

Comments

@piotr-machura
Copy link
Contributor

The plugin sets a flag on QuickFixCmdPre to signify that the quickfix has been populated by something other than the diagnostics. This unfortunatelly conflicts with non-builtin functions utilizing quickfix (like vim.lsp.buf.workspace_symbol() or vim.lsp.buf.references()).

Both this and the current issue of not respecting foregin location lists can be fixed using setqflist() (and getqflist(), setloclist(), getloclist()), perhaps by specifying the lists' ID or even just the title. The lsp_diagnostic_hook can then check if current quickfix list has a specific title (say "Diagnostics") and only then update. If the user wants to force the update they can do so with open_all_diagnostics() or open_buffer_diagnostics().

I would try making a PR myself, but the above are vimscript functions and I have no clue how to nicely use them from lua.

@piotr-machura
Copy link
Contributor Author

To expand on this: neovim 0.6 nightly fetaures a handy setqflist in addition to the already available setloclist, which adds workspace diagnostics to the quickfix list (similar to what this plugin does).

I am currently using something like this in my personal config:

function update_diagnostics(global_too)
    if not vim.lsp.buf.server_ready() then
        return
    end
    if vim.fn.getloclist(vim.fn.winnr(), { title = 0 }).title == 'Buffer diagnostics' then
        vim.diagnostic.setloclist{ open = false, title = 'Buffer diagnostics' }
    end
    if global_too and vim.fn.getqflist{ title = 0 }.title == 'Workspace diagnostics' then
        vim.diagnostic.setqflist{ open = false,  title = 'Workspace diagnostics' }
    end
end

and in my setup.on_attach callback I have

vim.api.nvim_command('autocmd BufWinEnter * lua update_diagnostics(false)')
vim.api.nvim_command('autocmd User DiagnosticsChanged lua update_diagnostics(true)')
vim.api.nvim_buf_set_keymap(0, 'n', '<C-k>k','<CMD>silent! lua vim.diagnostic.setloclist{ title = "Buffer diagnostics" }<CR>', {noremap=true})
vim.api.nvim_buf_set_keymap(0, 'n', '<C-k><C-k>','<CMD>silent! lua vim.diagnostic.setqflist{ title = "Workspace diagnostics" }<CR>', {noremap=true})

This allows me to use all kinds of non-standard quickfix/location lists (references, implementations, symbols etc.) and populate them with auto-updating diagnostics using a keymap.

Something similar (but much more polished) could be integrated into this plugin (although the "release" neovim 0.5.1 does not have setqflist yet).

@onsails
Copy link
Owner

onsails commented Jan 8, 2022

Hi @piotr-machura , I finally found time to fully adapt plugin to 0.6.x and test your idea. Apparently it works well so master now uses title to identify foreign quickfix! Thank you for the great idea and wonderful examples.

Foreign loclist is still to be done.

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

2 participants