diff --git a/README.md b/README.md index 27f44a1..a543243 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,7 @@ require'navigator'.setup({ | n | gG | show diagnostic for all buffers | | n | ]d | next diagnostic | | n | [d | previous diagnostic | +| n | \ dt | diagnostic toggle(enable/disable) | | n | ]r | next treesitter reference/usage | | n | [r | previous treesitter reference/usage | | n | \ wa | add workspace folder | diff --git a/lua/navigator.lua b/lua/navigator.lua index 60bbc63..8c554bf 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -159,7 +159,7 @@ end M.setup = function(cfg) extend_config(cfg) - vim.cmd([[autocmd FileType * lua require'navigator.lspclient.clients'.setup()]]) -- BufWinEnter BufNewFile,BufRead ? + vim.cmd([[autocmd FileType,BufEnter * lua require'navigator.lspclient.clients'.setup()]]) -- BufWinEnter BufNewFile,BufRead ? -- local log = require"navigator.util".log -- log(debug.traceback()) -- log(cfg, _NgConfigValues) diff --git a/lua/navigator/definition.lua b/lua/navigator/definition.lua index 1e175ae..666e321 100644 --- a/lua/navigator/definition.lua +++ b/lua/navigator/definition.lua @@ -104,9 +104,8 @@ local function def_preview(timeout_ms) local width = 40 for key, value in pairs(definition) do -- log(key, value, width) - width = math.max(width, #value) - width = math.min(90, width) - + width = math.max(width, #value + 4) + width = math.min(120, width) end definition = vim.list_extend({"  [" .. get_symbol() .. "] Definition: "}, definition) local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") @@ -116,7 +115,7 @@ local function def_preview(timeout_ms) relative = "cursor", style = "minimal", ft = filetype, - width = width, + rect = {width = width, height = #definition + 2}, data = definition, enter = true, border = _NgConfigValues.border or "shadow" diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 430af0b..a260da1 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -287,6 +287,15 @@ M.hide_diagnostic = function() end end +M.toggle_diagnostics = function() + if M.diagnostic_enabled then + M.diagnostic_enabled = false + return vim.diagnostic.disable() + end + vim.diagnostic.enable() + M.diagnostic_enabled = true +end + M.show_buf_diagnostics = function() if diagnostic_list[vim.bo.filetype] ~= nil then -- log(diagnostic_list[vim.bo.filetype]) diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 9b4a30c..8c8cda6 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -546,6 +546,10 @@ local function setup(user_opts) log("navigator user setup", user_opts) end trace(debug.traceback()) + if #vim.lsp.buf_get_clients() > 0 and user_opts == nil then + log("already setup") + return + end user_opts = user_opts or config -- incase setup was triggered from autocmd if ft == nil then diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index 8b4c0a2..241665d 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -33,6 +33,7 @@ local key_maps = { {key = "D", func = "type_definition()"}, {key = "gL", func = "require('navigator.diagnostics').show_diagnostics()"}, {key = "gG", func = "require('navigator.diagnostics').show_buf_diagnostics()"}, + {key = "dt", func = "require('navigator.diagnostics').toggle_diagnostics()"}, {key = "]d", func = "diagnostic.goto_next({ border = 'rounded', max_width = 80})"}, {key = "[d", func = "diagnostic.goto_prev({ border = 'rounded', max_width = 80})"}, {key = "]r", func = "require('navigator.treesitter').goto_next_usage()"},