add diagnostic toggle, adjust width of preview window

neovim_0.6
ray-x 3 years ago
parent 5a84868481
commit f43b0aba0e

@ -357,6 +357,7 @@ require'navigator'.setup({
| n | gG | show diagnostic for all buffers |
| n | ]d | next diagnostic |
| n | [d | previous diagnostic |
| n | \<Leader\> dt | diagnostic toggle(enable/disable) |
| n | ]r | next treesitter reference/usage |
| n | [r | previous treesitter reference/usage |
| n | \<Sapce\> wa | add workspace folder |

@ -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)

@ -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"

@ -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])

@ -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

@ -33,6 +33,7 @@ local key_maps = {
{key = "<Space>D", func = "type_definition()"},
{key = "gL", func = "require('navigator.diagnostics').show_diagnostics()"},
{key = "gG", func = "require('navigator.diagnostics').show_buf_diagnostics()"},
{key = "<Leader>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()"},

Loading…
Cancel
Save