diff --git a/README.md b/README.md index edbab21..06c526f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Easy code navigation through LSP and 🌲🏡Treesitter symbols, diagnostic errors. +![document symbol](https://github.com/ray-x/files/blob/master/img/navigator/doc_symbol.gif?raw=true) + # Features: - LSP easy setup. Support the most commonly used lsp clients setup. Dynamic lsp activation based on buffer type. @@ -133,7 +135,7 @@ colorscheme: [aurora](https://github.com/ray-x/aurora) # Current symbol highlight and jump backword/forward between symbols Document highlight provided by LSP. -Jump between symbols between symbols with treesitter +Jump between symbols between symbols with treesitter (with `]r` and `[r`) ![doc jump](https://github.com/ray-x/files/blob/master/img/navigator/doc_hl_jump.gif?raw=true) ### Diagnostic diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index dd119c6..307c9e1 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -252,7 +252,8 @@ local function load_cfg(ft, client, cfg, loaded) -- need to verify the lsp server is up end -local function wait_lsp_startup(ft) +local function wait_lsp_startup(ft, retry) + retry = retry or false local clients = vim.lsp.get_active_clients() or {} local loaded = {} for i = 1, 2 do @@ -265,6 +266,9 @@ local function wait_lsp_startup(ft) local cfg = setups[lspclient] or default_cfg load_cfg(ft, lspclient, cfg, loaded) end + if not retry or ft == nil then + return + end -- local timer = vim.loop.new_timer() local i = 0 @@ -273,7 +277,7 @@ local function wait_lsp_startup(ft) function() clients = vim.lsp.get_active_clients() or {} i = i + 1 - if i > 10 or #clients > 0 then + if i > 5 or #clients > 0 then timer:close() -- Always close handles to avoid leaks. log("active", #clients, i) _Loading = false @@ -286,32 +290,51 @@ local function wait_lsp_startup(ft) end end -vim.cmd([[autocmd filetype * lua require'navigator.lspclient.clients'.setup()]]) -- BufWinEnter BufNewFile,BufRead ? +vim.cmd([[autocmd FileType * lua require'navigator.lspclient.clients'.setup()]]) -- BufWinEnter BufNewFile,BufRead ? local function setup(user_opts) verbose(debug.traceback()) if _Loading == true then return end - - if lspconfig == nil then - error("lsp-config need installed and enabled") - return - end - - highlight.diagnositc_config_sign() - highlight.add_highlight() - local ft = vim.bo.filetype if ft == nil then ft = vim.api.nvim_buf_get_option(0, "filetype") end + if ft == nil or ft == "" then log("nil filetype") return end + log("loading for ft ", ft) + local retry = true + local disable_ft = { + "NvimTree", + "guihua", + "clap_input", + "clap_spinner", + "vista", + "TelescopePrompt", + "csv", + "txt", + "markdown", + "defx" + } + for i = 1, #disable_ft do + if ft == disable_ft[i] then + retry = false + end + end + if lspconfig == nil then + error("lsp-config need installed and enabled") + return + end + + highlight.diagnositc_config_sign() + highlight.add_highlight() _Loading = true - wait_lsp_startup(ft) + wait_lsp_startup(ft, retry) + _Loading = false end return {setup = setup, cap = cap} diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index 68b596f..3a13e59 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -172,7 +172,7 @@ local function get_all_nodes(bufnr) item.kind = node.kind item.node_scope = get_smallest_context(item.tsdata) local start_line_node, _, _ = item.tsdata:start() - item.node_text = ts_utils.get_node_tex(item.tsdata, bufnr)[1] + item.node_text = ts_utils.get_node_text(item.tsdata, bufnr)[1] if item.node_text == "_" then goto continue end diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 0325da6..d2d6b5c 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -95,7 +95,7 @@ local default_config = { plugin = "navigator", use_console = false, use_file = true, - level = "info" + level = "debug" } M._log = require("guihua.log").new({level = default_config.level}, true)