From 56b00b83d5560e96b963500c37e7cf0933fb8747 Mon Sep 17 00:00:00 2001 From: ray-x Date: Tue, 5 Jul 2022 02:13:24 +1000 Subject: [PATCH] diagnostic func failed to keymap --- lua/navigator.lua | 5 ++- lua/navigator/diagnostics.lua | 65 +++++++++++++++++++---------------- lua/navigator/treesitter.lua | 3 +- lua/navigator/util.lua | 60 +++++++++++++++++--------------- 4 files changed, 74 insertions(+), 59 deletions(-) diff --git a/lua/navigator.lua b/lua/navigator.lua index b5cad47..f180ba1 100755 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -159,6 +159,8 @@ local extend_config = function(opts) if opts.debug then _NgConfigValues.debug = opts.debug end + -- enable logs + require('navigator.util').setup() for key, value in pairs(opts) do if _NgConfigValues[key] == nil then warn( @@ -246,7 +248,8 @@ M.setup = function(cfg) require('navigator.implementation') cfg.lsp = cfg.lsp or _NgConfigValues.lsp - if cfg.lsp.enable then + + if _NgConfigValues.lsp.enable then require('navigator.diagnostics').config(cfg.lsp.diagnostic) end if not _NgConfigValues.loaded then diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 2829026..1a52825 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -27,24 +27,7 @@ if vim.diagnostic then } end -local diagnostic_cfg = { - -- Enable underline, use default values - underline = _NgConfigValues.lsp.diagnostic.underline, - -- Enable virtual - -- Use a function to dynamically turn signs off - -- and on, using buffer local variables - signs = true, - update_in_insert = _NgConfigValues.lsp.diagnostic.update_in_insert or false, - severity_sort = _NgConfigValues.lsp.diagnostic.severity_sort, - float = { - focusable = false, - style = 'minimal', - border = 'rounded', - source = 'always', - header = '', - prefix = '', - }, -} +local diagnostic_cfg local function get_count(bufnr, level) if vim.diagnostic ~= nil then @@ -312,15 +295,41 @@ end -- end local M = {} +function M.setup() + if diagnostic_cfg ~= nil and diagnostic_cfg.float ~= nil then + return + end + diagnostic_cfg = { + -- Enable underline, use default values + underline = _NgConfigValues.lsp.diagnostic.underline, + -- Enable virtual + -- Use a function to dynamically turn signs off + -- and on, using buffer local variables + signs = true, + update_in_insert = _NgConfigValues.lsp.diagnostic.update_in_insert or false, + severity_sort = _NgConfigValues.lsp.diagnostic.severity_sort, + float = { + focusable = false, + style = 'minimal', + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, + } + diagnostic_cfg.virtual_text = _NgConfigValues.lsp.diagnostic.virtual_text + if type(_NgConfigValues.lsp.diagnostic.virtual_text) == 'table' then + diagnostic_cfg.virtual_text.prefix = _NgConfigValues.icons.diagnostic_virtual_text + end + -- vim.lsp.handlers["textDocument/publishDiagnostics"] + M.diagnostic_handler = vim.lsp.with(diag_hdlr, diagnostic_cfg) -diagnostic_cfg.virtual_text = _NgConfigValues.lsp.diagnostic.virtual_text -if type(_NgConfigValues.lsp.diagnostic.virtual_text) == 'table' then - diagnostic_cfg.virtual_text.prefix = _NgConfigValues.icons.diagnostic_virtual_text -end --- vim.lsp.handlers["textDocument/publishDiagnostics"] -M.diagnostic_handler = vim.lsp.with(diag_hdlr, diagnostic_cfg) + vim.diagnostic.config(diagnostic_cfg) -vim.diagnostic.config(diagnostic_cfg) + if _NgConfigValues.lsp.diagnostic_scrollbar_sign then + vim.cmd([[autocmd WinScrolled * lua require'navigator.diagnostics'.update_err_marker()]]) + end +end local function clear_diag_VT(bufnr) -- important for clearing out when no more errors bufnr = bufnr or vim.api.nvim_get_current_buf() @@ -443,10 +452,6 @@ function M.update_err_marker() marker(result, { bufnr = bufnr, method = 'textDocument/publishDiagnostics' }) end -if _NgConfigValues.lsp.diagnostic_scrollbar_sign then - vim.cmd([[autocmd WinScrolled * lua require'navigator.diagnostics'.update_err_marker()]]) -end - function M.get_line_diagnostic() local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1 return diagnostic.get(vim.api.nvim_get_current_buf(), { lnum = lnum }) @@ -507,7 +512,9 @@ function M.treesitter_and_diag_panel() end function M.config(cfg) + M.setup() cfg = cfg or {} + log('diag config', cfg) local default_cfg = { underline = true, virtual_text = true, diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index 951306b..ce2098c 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -351,7 +351,8 @@ local function get_all_nodes(bufnr, filter, summary) local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype') if not parsers.has_parser() then if not require('navigator.lspclient.clients').ft_disabled(ft) then - vim.notify('ts not loaded ' .. ft, vim.lsp.log_levels.Debug) + -- vim.notify('ts not loaded ' .. ft, vim.lsp.log_levels.Debug) + log('ts not loaded ' .. ft) end return {} end diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 63ed191..2023864 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -172,41 +172,45 @@ function M.get_relative_path(base_path, my_path) return data end -local level = 'error' -if _NgConfigValues.debug == true then - level = 'info' -elseif _NgConfigValues.debug == 'trace' then - level = 'trace' +M.log = function(...) + return { ... } +end +M.info = function(...) + return { ... } +end +M.trace = function(...) + return { ... } +end +M.warn = function(...) + return { ... } end -local default_config = { use_console = false, use_file = true, level = level } -if _NgConfigValues.debug_console_output then - default_config.use_console = true - default_config.use_file = false +M.error = function(...) + print(...) end -M._log = require('guihua.log').new(default_config, true) -if _NgConfigValues.debug then - -- add log to you lsp.log +local level = 'error' - M.trace = M._log.trace - M.info = M._log.info - M.warn = M._log.warn - M.error = M._log.error - M.log = M.info -else - M.log = function(...) - return { ... } - end - M.info = function(...) - return { ... } +function M.setup() + if _NgConfigValues.debug == true then + level = 'info' + elseif _NgConfigValues.debug == 'trace' then + level = 'trace' end - M.trace = function(...) - return { ... } + local default_config = { use_console = false, use_file = true, level = level } + if _NgConfigValues.debug_console_output then + default_config.use_console = true + default_config.use_file = false end - M.warn = function(...) - return { ... } + + M._log = require('guihua.log').new(default_config, true) + if _NgConfigValues.debug then + -- add log to you lsp.log + M.trace = M._log.trace + M.info = M._log.info + M.warn = M._log.warn + M.error = M._log.error + M.log = M.info end - M.error = M._log.error end function M.fmt(...)