Feature: show diagnostics info summary in scrollbar area

neovim_0_5
ray-x 3 years ago
parent d034edbe0e
commit 2c11296b70

@ -204,6 +204,7 @@ require'navigator'.setup({
-- please check mapping.lua for all keymaps
treesitter_analysis = true, -- treesitter variable context
code_action_prompt = {enable = true, sign = true, sign_priority = 40, virtual_text = true},
diag_scroll_bar_sign = nil, -- experimental: set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area
icons = {
-- Code action
code_action_icon = " ",
@ -329,6 +330,15 @@ The plugin can be loaded lazily (packer `opt = true` ), And it will check if opt
The terminal will need to be able to output nerdfont and emoji correctly. I am using Kitty with nerdfont (Victor Mono).
## Integration with lspinstall
If you'd like to only use the lsp servers installed by lspinstall. Please set
```lua
lspinstall = false
```
In the config
## Usage
Please refer to lua/navigator/lspclient/mapping.lua on key mappings. Should be able to work out-of-box.

@ -27,6 +27,7 @@ _NgConfigValues = {
}
},
lspinstall = false, -- set to true if you would like use the lsp installed by lspinstall
diag_scroll_bar_sign = nil, -- set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area
icons = {
-- Code action
code_action_icon = "",

@ -1,19 +1,87 @@
local gui = require "navigator.gui"
local diagnostic_list = {}
_NG_VT_NS = vim.api.nvim_create_namespace("navigator_lua")
local util = require "navigator.util"
local log = util.log
local trace = require"guihua.log".trace
local error = util.error
local path_sep = require"navigator.util".path_sep()
local path_cur = require"navigator.util".path_cur()
diagnostic_list[vim.bo.filetype] = {}
local function error_marker(result, client_id)
if _NgConfigValues.diag_scroll_bar_sign == nil then
return
end
local first_line = vim.fn.line('w0')
local ft = vim.fn.expand('%:h:t') -- get the current file extension
local bufnr = vim.uri_to_bufnr(result.uri)
if bufnr ~= vim.fn.bufnr() then
-- log("not same buf", client_id, result.uri, bufnr, vim.fn.bufnr())
return
end
log(result, bufnr)
if result == nil or result.diagnostics == nil or #result.diagnostics == 0 then
local diag_cnt = vim.lsp.diagnostic.get_count(0, [[Error]])
+ vim.lsp.diagnostic.get_count(0, [[Warning]])
if diag_cnt == 0 then
vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1)
end
return
end
vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1)
-- total line num of current buffer
local winid = vim.fn.win_getid(vim.fn.winnr())
local total_num = vim.fn.getbufinfo(vim.fn.winbufnr(winid))[1].linecount
-- window size of current buffer
local wwidth = vim.fn.winwidth(winid)
local wheight = vim.fn.winheight(winid)
local pos = {}
-- pos of virtual text
for _, diag in pairs(result.diagnostics) do
if diag.range and diag.range.start and diag.range.start.line then
local p = diag.range.start.line
p = util.round(p * wheight / math.max(wheight, total_num))
if pos[#pos] and pos[#pos].line == p then
pos[#pos] = {
line = p,
sign = _NgConfigValues.diag_scroll_bar_sign[2],
severity = diag.severity
}
else
table.insert(pos, {
line = p,
sign = _NgConfigValues.diag_scroll_bar_sign[1],
severity = diag.severity
})
end
end
log("pos", pos, diag.range.start)
end
for i, s in pairs(pos) do
local hl = 'ErrorMsg'
if s.severity > 1 then
hl = 'WarningMsg'
end
vim.api.nvim_buf_set_extmark(bufnr, _NG_VT_NS, s.line + first_line, -1,
{virt_text = {{s.sign, hl}}, virt_text_pos = 'right_align'})
end
end
local diag_hdlr = function(err, method, result, client_id, bufnr, config)
-- log(result)
vim.lsp.diagnostic.on_publish_diagnostics(err, method, result, client_id, bufnr, config)
if err ~= nil then
log(err, config)
return
end
local cwd = vim.fn.getcwd(0)
local ft = vim.bo.filetype
@ -22,7 +90,10 @@ local diag_hdlr = function(err, method, result, client_id, bufnr, config)
end
-- vim.lsp.diagnostic.clear(vim.fn.bufnr(), client.id, nil, nil)
vim.lsp.diagnostic.on_publish_diagnostics(err, method, result, client_id, bufnr, config)
local uri = result.uri
-- log("diag: ", result, client_id)
if result and result.diagnostics then
local item_list = {}
for _, v in ipairs(result.diagnostics) do
@ -58,7 +129,12 @@ local diag_hdlr = function(err, method, result, client_id, bufnr, config)
end
-- local old_items = vim.fn.getqflist()
diagnostic_list[ft][uri] = item_list
error_marker(result, client_id)
else
vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1)
end
end
local M = {}
@ -120,4 +196,8 @@ M.set_diag_loclist = function()
end
end
function M.clear_blame_VT() -- important for clearing out the text when our cursor moves
vim.api.nvim_buf_clear_namespace(0, _NG_VT_NS, 0, -1)
end
return M

@ -23,6 +23,10 @@ M.path_cur = function()
end
end
M.round = function(x)
return math.floor(x + 0.5)
end
function M.get_data_from_file(filename, startLine)
local displayLine
if startLine < 3 then

Loading…
Cancel
Save