From ab7c79ff0b88a147c1818d926fcc1f65785c9aa5 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 14 May 2021 19:23:57 +1000 Subject: [PATCH] disable diagnostic when insert --- lua/navigator/diagnostics.lua | 60 ++++++++++++----------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 78077dd..8aed460 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -9,14 +9,10 @@ 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) - if err ~= nil then - log(err, config) - end + if err ~= nil then log(err, config) end local cwd = vim.fn.getcwd(0) local ft = vim.bo.filetype - if diagnostic_list[ft] == nil then - diagnostic_list[vim.bo.filetype] = {} - end + if diagnostic_list[ft] == nil then diagnostic_list[vim.bo.filetype] = {} end -- vim.lsp.diagnostic.clear(vim.fn.bufnr(), client.id, nil, nil) local uri = result.uri @@ -31,15 +27,9 @@ local diag_hdlr = function(err, method, result, client_id, br, config) item.col = v.range.start.character + 1 item.uri = uri local head = "🐛" - if v.severity == 1 then - head = "🈲" - end - if v.severity == 2 then - head = "☣️" - end - if v.severity > 2 then - head = "👎" - end + if v.severity == 1 then head = "🈲" end + if v.severity == 2 then head = "☣️" end + if v.severity > 2 then head = "👎" end local bufnr = vim.uri_to_bufnr(uri) vim.fn.bufload(bufnr) local pos = v.range.start @@ -55,24 +45,20 @@ end local M = {} -- vim.lsp.handlers["textDocument/publishDiagnostics"] = -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, - prefix = "🦊" --' ,   - }, - -- Use a function to dynamically turn signs off - -- and on, using buffer local variables - signs = true, - -- Disable a feature - update_in_insert = false - } -) +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, + prefix = "🦊" -- ' ,   + }, + -- Use a function to dynamically turn signs off + -- and on, using buffer local variables + signs = true, + -- Disable a feature + update_in_insert = false +}) M.show_diagnostic = function() vim.lsp.diagnostic.get_all() @@ -81,9 +67,7 @@ M.show_diagnostic = function() for _, buf in ipairs(bufs) do local bname = vim.fn.bufname(buf) if #bname > 0 and not util.exclude(bname) then - if vim.api.nvim_buf_is_loaded(buf) then - vim.lsp.diagnostic.get(buf, nil) - end + if vim.api.nvim_buf_is_loaded(buf) then vim.lsp.diagnostic.get(buf, nil) end end end if diagnostic_list[vim.bo.filetype] ~= nil then @@ -92,9 +76,7 @@ M.show_diagnostic = function() 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) - end + for _, it in pairs(items) do table.insert(display_items, it) end end -- log(display_items) if #display_items > 0 then