Add side panel; bugfix for ctags

pull/197/head
ray-x 2 years ago
parent 356ba3746b
commit ee76222997

@ -5,7 +5,9 @@
- A plugin combines the power of LSP and 🌲🏡 Treesitter together. Not only provids a better highlight but also help you analyse symbol context effectively.
- Fuzzy search & build ctags symbols
- ctags fuzzy search & build ctags symbols
-
- [![a short intro of navigator](https://user-images.githubusercontent.com/1681295/147378905-51eede5f-e36d-48f4-9799-ae562949babe.jpeg)](https://youtu.be/P1kd7Y8AatE)
@ -94,7 +96,9 @@ variable is:
- ccls call hierarchy (Non-standard `ccls/call` API) supports
- Syntax folding based on treesitter or LSP_fold folding algorithm. (It behaves similar to vs-code)
- Syntax folding based on treesitter or LSP_fold folding algorithm. (It behaves similar to vs-code); comment folding
- Treesitter symbols sidebar, LSP document symbole sidebar. Both with preview and folding
- Fully support LSP CodeAction, CodeLens, CodeLens action. Help you improve code quality.
@ -673,6 +677,13 @@ Using treesitter and LSP to view the symbol definition
![image](https://user-images.githubusercontent.com/1681295/139771978-bbc970a5-be9f-42cf-8942-3477485bd89c.png)
### Sidebar, folding, outline
Treesitter outline and Diagnostics
<img width="708" alt="image" src="https://user-images.githubusercontent.com/1681295/174791609-0023e68f-f1f4-4335-9ea2-d2360e9f0bfd.png">
<img width="733" alt="image" src="https://user-images.githubusercontent.com/1681295/174804579-26f87fbf-426b-46d0-a7a3-a5aab69c032f.png">
### GUI and multigrid support
You can load a different font size for floating win

@ -54,6 +54,8 @@ end
local function ctags_gen()
local cmd = 'ctags' -- -x -n -u -f - ' .. vfn.expand('%:p')
local output = _NgConfigValues.ctags.tagfile
-- rm file first
util.rm_file(output)
local options = '-R --exclude=.git --exclude=node_modules --exclude=test --exclude=vendor --excmd=number '
if _NgConfigValues.ctags then
cmd = _NgConfigValues.ctags.cmd
@ -64,6 +66,7 @@ local function ctags_gen()
options = options .. '--language=' .. lang
cmd = cmd .. ' ' .. options
cmd = string.format('%s -f %s %s --language=%s', cmd, output, options, lang)
cmd = vim.split(cmd, ' ')
log(cmd)
vfn.jobstart(cmd, {
on_stdout = function(_, _, _)
@ -72,7 +75,7 @@ local function ctags_gen()
on_exit = function(_, data, _) -- id, data, event
-- log(vim.inspect(data) .. "exit")
if data and data.code ~= 0 then
if data and data ~= 0 then
return vim.notify(cmd .. ' failed ' .. tostring(data), vim.lsp.log_levels.ERROR)
else
vim.notify('ctags generated')
@ -108,10 +111,10 @@ local function ctags_symbols()
local ft = vim.o.ft
local result = symbols_to_items(items)
log(result)
if next(result) == nil then
return vim.notify('no symbols found')
end
log(result[1])
local opt = {
api = '',
ft = ft,

@ -350,8 +350,6 @@ end
M.show_buf_diagnostics = function()
if diagnostic_list[vim.bo.filetype] ~= nil then
-- log(diagnostic_list[vim.bo.filetype])
-- vim.fn.setqflist({}, " ", {title = "LSP", items = diagnostic_list[vim.bo.filetype]})
local results = diagnostic_list[vim.bo.filetype]
local display_items = {}
for _, client_items in pairs(results) do
@ -369,7 +367,7 @@ M.show_buf_diagnostics = function()
enable_preview_edit = true,
})
if listview == nil then
return log("nil listview")
return log('nil listview')
end
trace('new buffer', listview.bufnr)
if listview.bufnr then
@ -471,6 +469,43 @@ function M.show_diagnostics(pos)
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 = vim.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(bufnr)
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)
cfg = cfg or {}
local default_cfg = {

@ -24,7 +24,25 @@ end
local util = lspconfig.util
local config = require('navigator').config_values()
local disabled_ft = {
'NvimTree',
'guihua',
'clap_input',
'clap_spinner',
'vista',
'vista_kind',
'TelescopePrompt',
'guihua_rust',
'csv',
'txt',
'defx',
'packer',
'gitcommit',
'windline',
'notify',
'nofile',
'',
}
-- local cap = vim.lsp.protocol.make_client_capabilities()
local on_attach = require('navigator.lspclient.attach').on_attach
-- gopls["ui.completion.usePlaceholders"] = true
@ -708,6 +726,14 @@ local function get_cfg(client)
end
end
local function ft_disabled(ft)
for i = 1, #disabled_ft do
if ft == disabled_ft[i] then
return true
end
end
end
local function setup(user_opts, cnt)
user_opts = user_opts or {}
local ft = vim.bo.filetype
@ -744,28 +770,10 @@ local function setup(user_opts, cnt)
log('navigator was loaded for ft', ft, bufnr)
return
end
local disable_ft = {
'NvimTree',
'guihua',
'clap_input',
'clap_spinner',
'vista',
'vista_kind',
'TelescopePrompt',
'guihua_rust',
'csv',
'txt',
'defx',
'packer',
'gitcommit',
'windline',
'notify',
}
for i = 1, #disable_ft do
if ft == disable_ft[i] then
trace('navigator disabled for ft or it is loaded', ft)
return
end
if ft_disabled(ft) then
trace('navigator disabled for ft or it is loaded', ft)
return
end
if _NgConfigValues.lsp.servers then
add_servers(_NgConfigValues.lsp.servers)
@ -840,4 +848,12 @@ local function on_filetype()
setup({ bufnr = bufnr })
end
return { setup = setup, get_cfg = get_cfg, lsp = servers, add_servers = add_servers, on_filetype = on_filetype }
return {
setup = setup,
get_cfg = get_cfg,
lsp = servers,
add_servers = add_servers,
on_filetype = on_filetype,
disabled_ft = disabled_ft,
ft_disabled = ft_disabled,
}

@ -63,11 +63,13 @@ local key_maps = {
}
local commands = {
[[command! -nargs=* Nctags lua require("navigator.ctags").ctags({<f-args>})]],
[[command! -nargs=* Nctags lua require("navigator.ctags").ctags(<f-args>)]],
"command! -nargs=0 LspLog lua require'navigator.lspclient.config'.open_lsp_log()",
"command! -nargs=0 LspRestart lua require'navigator.lspclient.config'.reload_lsp()",
"command! -nargs=0 LspToggleFmt lua require'navigator.lspclient.mapping'.toggle_lspformat()<CR>",
"command! -nargs=0 LspKeymaps lua require'navigator.lspclient.mapping'.get_keymaps_help()<CR>",
"command! -nargs=0 LspSymbols lua require'navigator.symbols'.side_panel()<CR>",
"command! -nargs=0 TSymbols lua require'navigator.treesitter'.side_panel()<CR>",
}
local key_maps_help = {}

@ -151,7 +151,6 @@ function M.side_panel()
if ft == 'nofile' or ft == 'guihua' or ft == 'prompt' then
return
end
print(ft)
local params = vim.lsp.util.make_range_params()
local sync_req = require('navigator.lspwrapper').call_sync
return sync_req(

@ -290,8 +290,12 @@ local function get_all_nodes(bufnr, filter, summary)
vim.notify('get_all_node invalide bufnr', vim.lsp.log_levels.WARN)
end
summary = summary or false
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
if not parsers.has_parser() then
vim.notify('ts not loaded', vim.lsp.log_levels.Debug)
if not require('navigator.lspclient.clients').ft_disabled(ft) then
vim.notify('ts not loaded ' .. ft, vim.lsp.log_levels.Debug)
end
return {}
end
local path_sep = require('navigator.util').path_sep()
@ -394,7 +398,7 @@ local function get_all_nodes(bufnr, filter, summary)
and (
parent:type() == 'function_name'
-- or parent:type() == 'function'
-- or parent:type() == 'function_declaration'
-- or parent:type() == 'function_declaration' -- this bring in too much info
or parent:type() == 'method_name'
or parent:type() == 'function_name_field'
)
@ -463,7 +467,7 @@ local function get_all_nodes(bufnr, filter, summary)
local sp = string.match(line_text, '(%s*)')
log(line_text, #sp)
if sp then
local indent_level = #sp / (vim.o.shiftwidth or 4)
local indent_level = #sp / (vim.o.shiftwidth or 4) + 1
item.indent_level = math.max(item.indent_level, indent_level)
end
end
@ -504,7 +508,7 @@ end
function M.buf_func(bufnr)
local ft = vim.api.nvim_buf_get_option(bufnr, 'buftype')
if vim.api.nvim_buf_get_option(bufnr, 'buftype') ~= 'nofile' then
if vim.api.nvim_buf_get_option(bufnr, 'buftype') == 'nofile' then
return
end
if not ok or ts_locals == nil then
@ -568,6 +572,7 @@ function M.side_panel()
Panel = require('guihua.panel')
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)

@ -71,6 +71,9 @@ function M.io_read(filename, total)
return content
end
function M.rm_file(filename)
return os.remove(filename)
end
function M.file_exists(name)
local f = io.open(name, "r")

Loading…
Cancel
Save