panel LSP symbols + diagnostic

pull/268/head
ray-x 1 year ago
parent badf6fd16a
commit 66d84151e9

@ -57,7 +57,7 @@ variable is:
also enables you to handle workspace with mixed types of codes (e.g. Go + javascript + yml). A better default setup is also enables you to handle workspace with mixed types of codes (e.g. Go + javascript + yml). A better default setup is
included for LSP clients. included for LSP clients.
- Out of box experience. 10 lines of minimum vimrc can turn your neovim into a full-featured LSP & Treesitter powered IDE - Out of box experience. 10 lines of minimum init.lua can turn your neovim into a full-featured LSP & Treesitter powered IDE
- UI with floating windows, navigator provides a visual way to manage and navigate through symbols, diagnostic errors, reference etc. It covers - UI with floating windows, navigator provides a visual way to manage and navigate through symbols, diagnostic errors, reference etc. It covers
all features(handler) provided by LSP from commonly used search reference, to less commonly used search for interface all features(handler) provided by LSP from commonly used search reference, to less commonly used search for interface

@ -1,5 +1,4 @@
local gui = require('navigator.gui') local gui = require('navigator.gui')
local diagnostic_list = {}
local diagnostic = vim.diagnostic or vim.lsp.diagnostic local diagnostic = vim.diagnostic or vim.lsp.diagnostic
-- local hide = diagnostic.hide or diagnostic.clear -- local hide = diagnostic.hide or diagnostic.clear
local util = require('navigator.util') local util = require('navigator.util')
@ -14,9 +13,10 @@ local api = vim.api
_NG_VT_DIAG_NS = api.nvim_create_namespace('navigator_lua_diag') _NG_VT_DIAG_NS = api.nvim_create_namespace('navigator_lua_diag')
if not util.nvim_0_6_1() then if not util.nvim_0_6_1() then
util.warn('Navigator 0.4+ only support nvim-0.6+, please use Navigator 0.3.x or a newer version of neovim') util.warn(
'Navigator 0.4+ only support nvim-0.6+, please use Navigator 0.3.x or a newer version of neovim'
)
end end
diagnostic_list[vim.bo.filetype] = {}
local diag_map = {} local diag_map = {}
if vim.diagnostic then if vim.diagnostic then
@ -38,6 +38,10 @@ local function get_count(bufnr, level)
end end
end end
local M = {}
M.diagnostic_list = {}
M.diagnostic_list[vim.bo.filetype] = {}
local function error_marker(result, ctx, config) local function error_marker(result, ctx, config)
if if
_NgConfigValues.lsp.diagnostic_scrollbar_sign == nil _NgConfigValues.lsp.diagnostic_scrollbar_sign == nil
@ -130,7 +134,8 @@ local function error_marker(result, ctx, config)
if pos[#pos] == bar then if pos[#pos] == bar then
bar = _NgConfigValues.lsp.diagnostic_scrollbar_sign[3] bar = _NgConfigValues.lsp.diagnostic_scrollbar_sign[3]
end end
pos[#pos] = { line = p, sign = bar, severity = math.min(diag.severity, pos[#pos].severity) } pos[#pos] =
{ line = p, sign = bar, severity = math.min(diag.severity, pos[#pos].severity) }
else else
table.insert(pos, { table.insert(pos, {
line = p, line = p,
@ -194,8 +199,8 @@ local diag_hdlr = function(err, result, ctx, config)
end end
local cwd = vim.loop.cwd() local cwd = vim.loop.cwd()
local ft = vim.bo.filetype local ft = vim.bo.filetype
if diagnostic_list[ft] == nil then if M.diagnostic_list[ft] == nil then
diagnostic_list[vim.bo.filetype] = {} M.diagnostic_list[vim.bo.filetype] = {}
end end
local client_id = ctx.client_id local client_id = ctx.client_id
@ -287,11 +292,11 @@ local diag_hdlr = function(err, result, ctx, config)
table.insert(item_list, item) table.insert(item_list, item)
end end
-- local old_items = vim.fn.getqflist() -- local old_items = vim.fn.getqflist()
if diagnostic_list[ft][uri] == nil then if M.diagnostic_list[ft][uri] == nil then
diagnostic_list[ft][uri] = {} M.diagnostic_list[ft][uri] = {}
end end
diagnostic_list[ft][uri][tostring(client_id)] = item_list M.diagnostic_list[ft][uri][tostring(client_id)] = item_list
trace(uri, ft, diagnostic_list) trace(uri, ft, M.diagnostic_list)
if not result.uri then if not result.uri then
result.uri = uri result.uri = uri
end end
@ -310,7 +315,6 @@ end
-- return debounce(100, diag_hdlr) -- return debounce(100, diag_hdlr)
-- end -- end
local M = {}
function M.setup() function M.setup()
if diagnostic_cfg ~= nil and diagnostic_cfg.float ~= nil then if diagnostic_cfg ~= nil and diagnostic_cfg.float ~= nil then
return return
@ -334,7 +338,9 @@ function M.setup()
}, },
} }
diagnostic_cfg.virtual_text = _NgConfigValues.lsp.diagnostic.virtual_text diagnostic_cfg.virtual_text = _NgConfigValues.lsp.diagnostic.virtual_text
if type(_NgConfigValues.lsp.diagnostic.virtual_text) == 'table' and _NgConfigValues.icons.icons then if
type(_NgConfigValues.lsp.diagnostic.virtual_text) == 'table' and _NgConfigValues.icons.icons
then
diagnostic_cfg.virtual_text.prefix = _NgConfigValues.icons.diagnostic_virtual_text diagnostic_cfg.virtual_text.prefix = _NgConfigValues.icons.diagnostic_virtual_text
end end
-- vim.lsp.handlers["textDocument/publishDiagnostics"] -- vim.lsp.handlers["textDocument/publishDiagnostics"]
@ -380,8 +386,8 @@ M.toggle_diagnostics = function()
end end
M.show_buf_diagnostics = function() M.show_buf_diagnostics = function()
if diagnostic_list[vim.bo.filetype] ~= nil then if M.diagnostic_list[vim.bo.filetype] ~= nil then
local results = diagnostic_list[vim.bo.filetype] local results = M.diagnostic_list[vim.bo.filetype]
local display_items = {} local display_items = {}
for _, client_items in pairs(results) do for _, client_items in pairs(results) do
for _, items in pairs(client_items) do for _, items in pairs(client_items) do
@ -394,7 +400,9 @@ M.show_buf_diagnostics = function()
if #display_items > 0 then if #display_items > 0 then
local listview = gui.new_list_view({ local listview = gui.new_list_view({
items = display_items, items = display_items,
api = _NgConfigValues.icons.diagnostic_file .. _NgConfigValues.icons.diagnostic_head .. ' Diagnostic ', api = _NgConfigValues.icons.diagnostic_file
.. _NgConfigValues.icons.diagnostic_head
.. ' Diagnostic ',
enable_preview_edit = true, enable_preview_edit = true,
}) })
if listview == nil then if listview == nil then
@ -415,7 +423,7 @@ M.setloclist = function(bufnr)
if diag_cnt == 0 then if diag_cnt == 0 then
log('great, no errors!') log('great, no errors!')
-- vim.fn.getloclist(0, {filewinid=0}) -- vim.fn.getloclist(0, {filewinid=0})
return vim.cmd('lclose') return vim.cmd('lclose')
end end
@ -508,44 +516,6 @@ function M.show_diagnostics(pos)
diagnostic.open_float(bufnr, opt) diagnostic.open_float(bufnr, opt)
end end
function M.treesitter_and_diag_panel()
local Panel = require('guihua.panel')
local ft = vim.bo.filetype
local results = diagnostic_list[ft]
log(diagnostic_list, ft)
local bufnr = api.nvim_get_current_buf()
local p = Panel:new({
header = 'treesitter',
render = function(b)
log('render for ', bufnr, b)
return require('navigator.treesitter').all_ts_nodes(b)
end,
})
p:add_section({
header = 'diagnostic',
render = function(buf)
log(buf, diagnostic)
if diagnostic_list[ft] ~= nil then
local display_items = {}
for _, client_items in pairs(results) do
for _, items in pairs(client_items) do
for _, it in pairs(items) do
log(it)
table.insert(display_items, it)
end
end
end
return display_items
else
return {}
end
end,
})
p:open(true)
end
function M.config(cfg) function M.config(cfg)
M.setup() M.setup()
cfg = cfg or {} cfg = cfg or {}

@ -128,6 +128,8 @@ local function set_cmds(_)
"command! -nargs=0 TSymbols lua require'navigator.treesitter'.side_panel()<CR>", "command! -nargs=0 TSymbols lua require'navigator.treesitter'.side_panel()<CR>",
"command! -nargs=0 NRefPanel lua require'navigator.reference'.side_panel()<CR>", "command! -nargs=0 NRefPanel lua require'navigator.reference'.side_panel()<CR>",
"command! -nargs=* Calltree lua require'navigator.hierarchy'.calltree(<f-args>)<CR>", "command! -nargs=* Calltree lua require'navigator.hierarchy'.calltree(<f-args>)<CR>",
"command! -nargs=* TsDiag lua require'navigator.sidepanel'.treesitter_and_diag_panel(<f-args>)<CR>",
"command! -nargs=* LspDiag lua require'navigator.sidepanel'.lsp_and_diag_panel(<f-args>)<CR>",
} }
for _, value in pairs(commands) do for _, value in pairs(commands) do

@ -0,0 +1,96 @@
local gui = require('navigator.gui')
local diagnostic = vim.diagnostic or vim.lsp.diagnostic
local diag = require('navigator.diagnostics')
local util = require('navigator.util')
local log = util.log
local api = vim.api
local M = {}
function M.treesitter_and_diag_panel()
local Panel = require('guihua.panel')
local ft = vim.bo.filetype
local results = diag.diagnostic_list[ft]
log(diag.diagnostic_list, ft)
local bufnr = api.nvim_get_current_buf()
local p = Panel:new({
header = 'treesitter',
render = function(b)
log('render for ', bufnr, b)
return require('navigator.treesitter').all_ts_nodes(b)
end,
})
p:add_section({
header = 'diagnostic',
render = function(buf)
log(buf, diagnostic)
if diag.diagnostic_list[ft] ~= nil then
local display_items = {}
for _, client_items in pairs(results) do
for _, items in pairs(client_items) do
for _, it in pairs(items) do
log(it)
table.insert(display_items, it)
end
end
end
return display_items
else
return {}
end
end,
})
p:open(true)
end
function M.lsp_and_diag_panel()
local Panel = require('guihua.panel')
local ft = vim.bo.filetype
local results = diag.diagnostic_list[ft]
log(diag.diagnostic_list, ft)
bufnr = bufnr or api.nvim_get_current_buf()
ft = vim.api.nvim_buf_get_option(bufnr, 'buftype') or vim.bo.filetype
if ft == 'nofile' or ft == 'guihua' or ft == 'prompt' then
return
end
local params = vim.lsp.util.make_range_params()
local sync_req = require('navigator.lspwrapper').call_sync
local lsp = sync_req(
'textDocument/documentSymbol',
params,
{ timeout = 2000, bufnr = bufnr, no_show = true },
vim.lsp.with(require('navigator.symbols').document_symbol_handler, { no_show = true })
)
local p = Panel:new({
header = 'symboles',
render = function(bufnr)
return lsp
end,
})
p:add_section({
header = 'diagnostic',
render = function(buf)
log(buf, diagnostic)
if diag.diagnostic_list[ft] ~= nil then
local display_items = {}
for _, client_items in pairs(results) do
for _, items in pairs(client_items) do
for _, it in pairs(items) do
log(it)
table.insert(display_items, it)
end
end
end
return display_items
else
return {}
end
end,
})
p:open(true)
end
return M
Loading…
Cancel
Save