Created
April 7, 2020 14:35
-
-
Save jssee/bf01d988aef332839772ccd35e3e539d to your computer and use it in GitHub Desktop.
nvim lsp -> qf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local diagnostics_quickfix = function(_, _, result, _) | |
if not result then return end | |
local uri = result.uri | |
local bufnr = vim.uri_to_bufnr(uri) | |
local diagnostics = result.diagnostics | |
if not bufnr then | |
err_message("LSP.publishDiagnostics: Couldn't find buffer for ", uri) | |
return | |
end | |
for _, v in ipairs(diagnostics) do | |
v.uri = v.uri or result.uri | |
end | |
local locations = vim.lsp.util.locations_to_items(diagnostics) | |
vim.lsp.util.set_qflist(locations) | |
-- when errors are fixed, close qflist automatically | |
local qf = vim.fn.getqflist({["size"] = 0}) | |
if qf["size"] == 0 then | |
vim.api.nvim_command("cclose") | |
end | |
vim.api.nvim_command("autocmd! BufWritePost <buffer> doautocmd QuickFixCmdPost") | |
end | |
vim.lsp.callbacks["textDocument/publishDiagnostics"] = diagnostics_quickfix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment