Add error check for config, Allow show additional info for diagnostic

neovim_0.6
ray-x 3 years ago
parent 49fb9032d8
commit 83b66dbea1

@ -664,3 +664,11 @@ end
- Async (some of the requests is slow on large codebases and might be good to use co-rountine)
- More clients. I use go, python, js/ts, java, c/cpp, lua most of the time. Did not test other languages (e.g dart, swift etc)
- Configuration options
# Errors and Bug Reporting
- Please double check your setup and check if minium setup works or not
- It should works for 0.5.1, neovim 0.6.x prefered.
- Check console output
- Check `LspInfo` and treesitter status with `checkhealth`
- Turn on log and attach the log to your issue if possible you can remove any personal/company info in the log

@ -1,6 +1,19 @@
local M = {}
local function warn(msg)
vim.api.nvim_echo({{"WRN: " .. msg, "WarningMsg"}}, true, {})
end
local function error(msg)
vim.api.nvim_echo({{"ERR: " .. msg, "ErrorMsg"}}, true, {})
end
local function info(msg)
vim.api.nvim_echo({{"Info: " .. msg}}, true, {})
end
_NgConfigValues = {
debug = false, -- log output not implemented
debug = false, -- log output
width = 0.62, -- valeu of cols
height = 0.38, -- listview height
preview_height = 0.38,
@ -12,10 +25,9 @@ _NgConfigValues = {
border = "single", -- border style, can be one of 'none', 'single', 'double', "shadow"
combined_attach = "both", -- both: use both customized attach and navigator default attach, mine: only use my attach defined in vimrc
on_attach = nil,
-- function(client, bufnr)
-- -- your on_attach will be called at end of navigator on_attach
-- end,
on_attach = function(client, bufnr)
-- your on_attach will be called at end of navigator on_attach
end,
ts_fold = false,
-- code_action_prompt = {enable = true, sign = true, sign_priority = 40, virtual_text = true},
-- code_lens_action_prompt = {enable = true, sign = true, sign_priority = 40, virtual_text = true},
@ -25,7 +37,6 @@ _NgConfigValues = {
lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator
-- setup here. if it is nil, navigator will not init signature help
lsp = {
code_action = {
enable = true,
sign = true,
@ -42,7 +53,7 @@ _NgConfigValues = {
},
format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc)
disable_format_cap = {}, -- a list of lsp disable file format (e.g. if you using efm or vim-codeformat etc), empty by default
disable_lsp = nil, -- a list of lsp server disabled for your project, e.g. denols and tsserver you may
disable_lsp = {}, -- a list of lsp server disabled for your project, e.g. denols and tsserver you may
code_lens = false,
-- only want to enable one lsp server
disply_diagnostic_qf = true, -- always show quickfix if there are diagnostic errors
@ -127,10 +138,10 @@ local extend_config = function(opts)
return
end
for key, value in pairs(opts) do
-- if _NgConfigValues[key] == nil then
-- error(string.format("[] Key %s not valid", key))
-- return
-- end
if _NgConfigValues[key] == nil then
error(string.format("[] Key %s not valid", key))
-- return
end
if type(_NgConfigValues[key]) == "table" then
for k, v in pairs(value) do
-- level 3
@ -143,6 +154,17 @@ local extend_config = function(opts)
_NgConfigValues[key][k] = v
end
else
if _NgConfigValues[key][k] == nil then
if key == 'lsp' then
local lsp = require('navigator.lspclient.clients').lsp
if not vim.tbl_contains(lsp or {}, k) and k ~= 'efm' then
warn(string.format("[] LSP %s not valid", k))
end
else
warn(string.format("[] Key %s %s not valid", key, k))
end
-- return
end
_NgConfigValues[key][k] = v
end
end

@ -12,7 +12,6 @@ local path_sep = require"navigator.util".path_sep()
local mk_handler = require"navigator.util".mk_handler
local path_cur = require"navigator.util".path_cur()
diagnostic_list[vim.bo.filetype] = {}
local function clear_diag_VT(bufnr) -- important for clearing out when no more errors
log(bufnr, _NG_VT_DIAG_NS)
if bufnr == nil or _NG_VT_DIAG_NS == nil then
@ -172,7 +171,7 @@ end
local update_err_marker_async = function()
local debounce = require'navigator.debounce'.debounce_trailing
return debounce(200, error_marker)
return debounce(400, error_marker)
end
local diag_hdlr = mk_handler(function(err, result, ctx, config)
@ -194,6 +193,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
end
local client_id = ctx.client_id
local bufnr = ctx.bufnr or 0
if result.diagnostics ~= nil and result.diagnostics ~= {} then
trace('diagnostic', result.diagnostics, ctx, config)
end
@ -206,6 +206,13 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
vim.lsp.diagnostic.on_publish_diagnostics(err, _, result, ctx.client_id, _, config)
end
local uri = result.uri
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]])
if result.diagnostics == {} and diag_cnt > 0 then
log("no result? ", diag_cnt)
return
end
-- trace("diag: ", mode, result, ctx, config)
if result and result.diagnostics then
local item_list = {}
@ -216,7 +223,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
item.lnum = v.range.start.line + 1
item.col = v.range.start.character + 1
item.uri = uri
trace(item)
-- trace(item)
local head = _NgConfigValues.icons.diagnostic_head
if v.severity == 1 then
head = _NgConfigValues.icons.diagnostic_head_severity_1
@ -227,6 +234,16 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
if v.severity > 2 then
head = _NgConfigValues.icons.diagnostic_head_severity_3
end
if v.relatedInformation and v.relatedInformation[1] then
local info = v.relatedInformation[1]
-- trace(info)
if info.message then
v.releated_msg = info.message
end
if info.location and info.location.range then
v.releated_lnum = info.location.range.start.line
end
end
local bufnr1 = vim.uri_to_bufnr(uri)
local loaded = vim.api.nvim_buf_is_loaded(bufnr1)
if _NgConfigValues.diagnostic_load_files then
@ -239,18 +256,29 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
local line = (vim.api.nvim_buf_get_lines(bufnr1, row, row + 1, false) or {""})[1]
if line ~= nil then
item.text = head .. line .. _NgConfigValues.icons.diagnostic_head_description .. v.message
table.insert(item_list, item)
else
error("diagnostic result empty line", v, row, bufnr1)
end
else
item.text = head .. _NgConfigValues.icons.diagnostic_head_description .. v.message
table.insert(item_list, item)
end
if v.releated_msg then
item.text = item.text .. '; ' .. item.releated_msg
end
if v.releated_lnum then
item.text = item.text .. ":" .. tostring(item.releated_lnum)
end
table.insert(item_list, item)
end
-- local old_items = vim.fn.getqflist()
diagnostic_list[ft][uri] = item_list
trace(uri, ft, item_list)
if diagnostic_list[ft][uri] == nil then
diagnostic_list[ft][uri] = {}
end
diagnostic_list[ft][uri][tostring(client_id)] = item_list
trace(uri, ft, diagnostic_list)
if not result.uri then
result.uri = uri
end
@ -265,6 +293,11 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
end)
local diag_hdlr_async = function()
local debounce = require'navigator.debounce'.debounce_trailing
return debounce(100, diag_hdlr)
end
local M = {}
local diagnostic_cfg = {
-- Enable underline, use default values
@ -307,9 +340,11 @@ M.show_buf_diagnostics = function()
-- 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
for _, it in pairs(items) do
table.insert(display_items, it)
for _, client_items in pairs(results) do
for _, items in pairs(client_items) do
for _, it in pairs(items) do
table.insert(display_items, it)
end
end
end
-- log(display_items)

@ -617,4 +617,4 @@ local function setup(user_opts)
-- _LoadedFiletypes[ft] = vim.tbl_extend("keep", _LoadedFiletypes[ft] or {}, {ft})
end
return {setup = setup, get_cfg = get_cfg}
return {setup = setup, get_cfg = get_cfg, lsp = servers}

Loading…
Cancel
Save