From f16a04482d67ef84f5a47e9bb120754262017117 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 12 Aug 2021 12:25:15 +1000 Subject: [PATCH] add config for showing error in quickfix --- README.md | 5 ++++- lua/navigator.lua | 3 ++- lua/navigator/diagnostics.lua | 21 +++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 56f660c..939f80a 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,6 @@ require'navigator'.setup({ -- please check mapping.lua for all keymaps treesitter_analysis = true, -- treesitter variable context code_action_prompt = {enable = true, sign = true, sign_priority = 40, virtual_text = true}, - diag_scroll_bar_sign = nil, -- experimental: set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area icons = { -- Code action code_action_icon = " ", @@ -217,6 +216,10 @@ require'navigator'.setup({ lsp = { format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) + diag_scroll_bar_sign = nil, -- experimental: set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area + + disply_diagnostic_qf = true, -- always show quickfix if there are diagnostic errors, set to false if you want to + ignore it tsserver = { filetypes = {'typescript'} -- disable javascript etc, -- set to {} to disable the lspclient for all filetypes diff --git a/lua/navigator.lua b/lua/navigator.lua index 81b41e6..b055638 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -16,6 +16,8 @@ _NgConfigValues = { treesitter_analysis = true, -- treesitter variable context lsp = { format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) + disply_diagnostic_qf = true, -- always show quickfix if there are diagnostic errors + diag_scroll_bar_sign = nil, -- set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area tsserver = { -- filetypes = {'typescript'} -- disable javascript etc, -- set to {} to disable the lspclient for all filetype @@ -27,7 +29,6 @@ _NgConfigValues = { } }, lspinstall = false, -- set to true if you would like use the lsp installed by lspinstall - diag_scroll_bar_sign = nil, -- set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area icons = { -- Code action code_action_icon = " ", diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 082a889..4d49e29 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -12,7 +12,7 @@ local path_cur = require"navigator.util".path_cur() diagnostic_list[vim.bo.filetype] = {} local function error_marker(result, client_id) - if _NgConfigValues.diag_scroll_bar_sign == nil then -- not enabled or already shown + if _NgConfigValues.lsp.diag_scroll_bar_sign == nil then -- not enabled or already shown return end local first_line = vim.fn.line('w0') @@ -60,13 +60,13 @@ local function error_marker(result, client_id) if pos[#pos] and pos[#pos].line == p then pos[#pos] = { line = p, - sign = _NgConfigValues.diag_scroll_bar_sign[2], + sign = _NgConfigValues.lsp.diag_scroll_bar_sign[2], severity = diag.severity } else table.insert(pos, { line = p, - sign = _NgConfigValues.diag_scroll_bar_sign[1], + sign = _NgConfigValues.lsp.diag_scroll_bar_sign[1], severity = diag.severity }) end @@ -200,7 +200,7 @@ end M.set_diag_loclist = function() if not vim.tbl_isempty(vim.lsp.buf_get_clients(0)) then local err_cnt = vim.lsp.diagnostic.get_count(0, [[Error]]) - if err_cnt > 0 then + if err_cnt > 0 and _NgConfigValues.lsp.disply_diagnostic_qf then vim.lsp.diagnostic.set_loclist() else vim.cmd("lclose") @@ -231,11 +231,20 @@ function M.update_err_marker() -- redraw vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1) local errors = vim.lsp.diagnostic.get(bufnr) - local result = {diagnostics = errors} + if #errors == 0 then + return + end + local result = {diagnostics = errors, uri = errors[1].uri} error_marker(result) end -- TODO: update the marker --- vim.cmd [[autocmd WinScrolled * lua require'navigator.diagnostics'.update_err_marker()]] +if _NgConfigValues.diag_scroll_bar_sign then + print("config deprecated, set lsp.diag_scroll_bar_sign instead") +end + +if _NgConfigValues.lsp.diag_scroll_bar_sign then + vim.cmd [[autocmd WinScrolled * lua require'navigator.diagnostics'.update_err_marker()]] +end return M