2021-04-19 02:56:32 +00:00
|
|
|
local gui = require "navigator.gui"
|
|
|
|
local diagnostic_list = {}
|
2021-04-24 09:55:48 +00:00
|
|
|
|
|
|
|
local util = require "navigator.util"
|
|
|
|
local log = util.log
|
2021-05-22 00:54:10 +00:00
|
|
|
local error = util.error
|
2021-04-24 09:55:48 +00:00
|
|
|
|
2021-04-19 02:56:32 +00:00
|
|
|
diagnostic_list[vim.bo.filetype] = {}
|
|
|
|
|
|
|
|
local diag_hdlr = function(err, method, result, client_id, br, config)
|
|
|
|
-- log(result)
|
|
|
|
vim.lsp.diagnostic.on_publish_diagnostics(err, method, result, client_id, br, config)
|
2021-05-22 00:54:10 +00:00
|
|
|
if err ~= nil then
|
|
|
|
log(err, config)
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
local cwd = vim.fn.getcwd(0)
|
|
|
|
local ft = vim.bo.filetype
|
2021-05-22 00:54:10 +00:00
|
|
|
if diagnostic_list[ft] == nil then
|
|
|
|
diagnostic_list[vim.bo.filetype] = {}
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
-- vim.lsp.diagnostic.clear(vim.fn.bufnr(), client.id, nil, nil)
|
|
|
|
|
|
|
|
local uri = result.uri
|
|
|
|
if result and result.diagnostics then
|
|
|
|
local item_list = {}
|
|
|
|
|
|
|
|
for _, v in ipairs(result.diagnostics) do
|
|
|
|
local item = v
|
|
|
|
item.filename = assert(vim.uri_to_fname(uri))
|
|
|
|
item.display_filename = item.filename:gsub(cwd .. "/", "./", 1)
|
|
|
|
item.lnum = v.range.start.line + 1
|
|
|
|
item.col = v.range.start.character + 1
|
|
|
|
item.uri = uri
|
2021-06-15 20:46:04 +00:00
|
|
|
local head = _NgConfigValues.icons.diagnostic_head
|
2021-05-22 00:54:10 +00:00
|
|
|
if v.severity == 1 then
|
2021-06-15 20:46:04 +00:00
|
|
|
head = _NgConfigValues.icons.diagnostic_head_severity_1
|
2021-05-22 00:54:10 +00:00
|
|
|
end
|
|
|
|
if v.severity == 2 then
|
2021-06-15 20:46:04 +00:00
|
|
|
head = _NgConfigValues.icons.diagnostic_head_severity_2
|
2021-05-22 00:54:10 +00:00
|
|
|
end
|
|
|
|
if v.severity > 2 then
|
2021-06-15 20:46:04 +00:00
|
|
|
head = _NgConfigValues.icons.diagnostic_head_severity_3
|
2021-05-22 00:54:10 +00:00
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
local bufnr = vim.uri_to_bufnr(uri)
|
|
|
|
vim.fn.bufload(bufnr)
|
|
|
|
local pos = v.range.start
|
|
|
|
local row = pos.line
|
|
|
|
local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
|
2021-05-22 00:54:10 +00:00
|
|
|
if line ~= nil then
|
2021-06-15 20:46:04 +00:00
|
|
|
item.text = head .. line .. _NgConfigValues.icons.diagnostic_head_description .. v.message
|
2021-05-22 00:54:10 +00:00
|
|
|
table.insert(item_list, item)
|
|
|
|
else
|
|
|
|
error("diagnostic result empty line", v, item)
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
|
|
|
-- local old_items = vim.fn.getqflist()
|
|
|
|
diagnostic_list[ft][uri] = item_list
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
-- vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
2021-05-14 09:23:57 +00:00
|
|
|
M.diagnostic_handler = vim.lsp.with(diag_hdlr, {
|
|
|
|
-- Enable underline, use default values
|
|
|
|
underline = true,
|
|
|
|
-- Enable virtual text, override spacing to 0
|
|
|
|
virtual_text = {
|
|
|
|
spacing = 0,
|
2021-06-15 20:46:04 +00:00
|
|
|
prefix = _NgConfigValues.icons.diagnostic_virtual_text
|
2021-05-14 09:23:57 +00:00
|
|
|
},
|
|
|
|
-- Use a function to dynamically turn signs off
|
|
|
|
-- and on, using buffer local variables
|
|
|
|
signs = true,
|
|
|
|
-- Disable a feature
|
|
|
|
update_in_insert = false
|
|
|
|
})
|
2021-04-25 04:44:05 +00:00
|
|
|
|
2021-04-19 02:56:32 +00:00
|
|
|
M.show_diagnostic = function()
|
2021-04-24 09:55:48 +00:00
|
|
|
vim.lsp.diagnostic.get_all()
|
|
|
|
|
|
|
|
local bufs = vim.api.nvim_list_bufs()
|
|
|
|
for _, buf in ipairs(bufs) do
|
|
|
|
local bname = vim.fn.bufname(buf)
|
|
|
|
if #bname > 0 and not util.exclude(bname) then
|
2021-05-22 00:54:10 +00:00
|
|
|
if vim.api.nvim_buf_is_loaded(buf) then
|
|
|
|
vim.lsp.diagnostic.get(buf, nil)
|
|
|
|
end
|
2021-04-24 09:55:48 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
if diagnostic_list[vim.bo.filetype] ~= nil then
|
2021-04-24 11:31:31 +00:00
|
|
|
-- log(diagnostic_list[vim.bo.filetype])
|
2021-04-19 02:56:32 +00:00
|
|
|
-- vim.fn.setqflist({}, " ", {title = "LSP", items = diagnostic_list[vim.bo.filetype]})
|
|
|
|
local results = diagnostic_list[vim.bo.filetype]
|
|
|
|
local display_items = {}
|
|
|
|
for _, items in pairs(results) do
|
2021-05-22 00:54:10 +00:00
|
|
|
for _, it in pairs(items) do
|
|
|
|
table.insert(display_items, it)
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
2021-04-24 09:55:48 +00:00
|
|
|
-- log(display_items)
|
2021-04-19 02:56:32 +00:00
|
|
|
if #display_items > 0 then
|
2021-06-13 04:03:01 +00:00
|
|
|
gui.new_list_view({
|
|
|
|
items = display_items,
|
2021-06-15 20:46:04 +00:00
|
|
|
api = _NgConfigValues.icons.diagnostic_file .. _NgConfigValues.icons.diagnostic_head .. " Diagnostic ",
|
2021-06-13 04:03:01 +00:00
|
|
|
enable_preview_edit = true
|
|
|
|
})
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|