Skip to content

Instantly share code, notes, and snippets.

@jssee
Created April 7, 2020 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jssee/bf01d988aef332839772ccd35e3e539d to your computer and use it in GitHub Desktop.
Save jssee/bf01d988aef332839772ccd35e3e539d to your computer and use it in GitHub Desktop.
nvim lsp -> qf
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