diagnostic func failed to keymap

bugfix171
ray-x 2 years ago
parent 3fe9a876c4
commit 56b00b83d5

@ -159,6 +159,8 @@ local extend_config = function(opts)
if opts.debug then if opts.debug then
_NgConfigValues.debug = opts.debug _NgConfigValues.debug = opts.debug
end end
-- enable logs
require('navigator.util').setup()
for key, value in pairs(opts) do for key, value in pairs(opts) do
if _NgConfigValues[key] == nil then if _NgConfigValues[key] == nil then
warn( warn(
@ -246,7 +248,8 @@ M.setup = function(cfg)
require('navigator.implementation') require('navigator.implementation')
cfg.lsp = cfg.lsp or _NgConfigValues.lsp cfg.lsp = cfg.lsp or _NgConfigValues.lsp
if cfg.lsp.enable then
if _NgConfigValues.lsp.enable then
require('navigator.diagnostics').config(cfg.lsp.diagnostic) require('navigator.diagnostics').config(cfg.lsp.diagnostic)
end end
if not _NgConfigValues.loaded then if not _NgConfigValues.loaded then

@ -27,24 +27,7 @@ if vim.diagnostic then
} }
end end
local diagnostic_cfg = { 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 function get_count(bufnr, level) local function get_count(bufnr, level)
if vim.diagnostic ~= nil then if vim.diagnostic ~= nil then
@ -312,15 +295,41 @@ end
-- end -- end
local M = {} 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 vim.diagnostic.config(diagnostic_cfg)
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) 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 local function clear_diag_VT(bufnr) -- important for clearing out when no more errors
bufnr = bufnr or vim.api.nvim_get_current_buf() 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' }) marker(result, { bufnr = bufnr, method = 'textDocument/publishDiagnostics' })
end 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() function M.get_line_diagnostic()
local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1 local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
return diagnostic.get(vim.api.nvim_get_current_buf(), { lnum = lnum }) return diagnostic.get(vim.api.nvim_get_current_buf(), { lnum = lnum })
@ -507,7 +512,9 @@ function M.treesitter_and_diag_panel()
end end
function M.config(cfg) function M.config(cfg)
M.setup()
cfg = cfg or {} cfg = cfg or {}
log('diag config', cfg)
local default_cfg = { local default_cfg = {
underline = true, underline = true,
virtual_text = true, virtual_text = true,

@ -351,7 +351,8 @@ local function get_all_nodes(bufnr, filter, summary)
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype') local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
if not parsers.has_parser() then if not parsers.has_parser() then
if not require('navigator.lspclient.clients').ft_disabled(ft) 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 end
return {} return {}
end end

@ -172,41 +172,45 @@ function M.get_relative_path(base_path, my_path)
return data return data
end end
local level = 'error' M.log = function(...)
if _NgConfigValues.debug == true then return { ... }
level = 'info' end
elseif _NgConfigValues.debug == 'trace' then M.info = function(...)
level = 'trace' return { ... }
end
M.trace = function(...)
return { ... }
end
M.warn = function(...)
return { ... }
end end
local default_config = { use_console = false, use_file = true, level = level } M.error = function(...)
if _NgConfigValues.debug_console_output then print(...)
default_config.use_console = true
default_config.use_file = false
end end
M._log = require('guihua.log').new(default_config, true) local level = 'error'
if _NgConfigValues.debug then
-- add log to you lsp.log
M.trace = M._log.trace function M.setup()
M.info = M._log.info if _NgConfigValues.debug == true then
M.warn = M._log.warn level = 'info'
M.error = M._log.error elseif _NgConfigValues.debug == 'trace' then
M.log = M.info level = 'trace'
else
M.log = function(...)
return { ... }
end
M.info = function(...)
return { ... }
end end
M.trace = function(...) local default_config = { use_console = false, use_file = true, level = level }
return { ... } if _NgConfigValues.debug_console_output then
default_config.use_console = true
default_config.use_file = false
end 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 end
M.error = M._log.error
end end
function M.fmt(...) function M.fmt(...)

Loading…
Cancel
Save