From 88ac6268cf5bd38cfb978101e6b68f5166e88c26 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 May 2021 19:03:55 +1000 Subject: [PATCH] improve lsp loading and prevent muliple loading --- README.md | 6 +++--- lua/navigator/lspclient/clients.lua | 20 +++++++++++++------- lua/navigator/util.lua | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 97a1c67..f811623 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Navigator -- Easy code navigation through LSP and 🌲🏡Treesitter symbols; view diagnostic errors. +- Easy code navigation, view diagnostic errors, see relationships of functions, variables -- A plugin combine LSP and treesitter parser together. Not only providing a better highlight but also help you analyse symbol context effectively. +- A plugin combines power of LSP and 🌲🏡 treesitter together. Not only provids a better highlight but also help you analyse symbol context effectively. Here are examples #### Example: Javascripts closure -The following screenshot shows javascript call tree 🌲 of variable `browser` insides a closure. This feature is similar to incoming&outgoing calls from LSP. It is designed for the symbol analysis. +The following screenshot shows javascript call tree 🌲 of variable `browser` insides a closure. This feature is similar to incoming & outgoing calls from LSP. It is designed for the symbol analysis. ![js_closure_call_tree](https://user-images.githubusercontent.com/1681295/119120589-cee23700-ba6f-11eb-95c5-b9ac8d445c31.jpg) Explanation: diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index e3cf3ba..1ccc3ab 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -4,6 +4,7 @@ local trace = require"navigator.util".trace _Loading = false +_LoadedClients = {} if packer_plugins ~= nil then -- packer installed local loader = require"packer".loader @@ -288,15 +289,20 @@ local function wait_lsp_startup(ft, retry, lsp_opts) end local function setup(user_opts) - - log(user_opts) + local ft = vim.bo.filetype + if _LoadedClients[ft] then + trace("navigator is loaded for ft", ft) + return + end + if user_opts ~= nil then + log(user_opts) + end trace(debug.traceback()) user_opts = user_opts or _NgConfigValues -- incase setup was triggered from autocmd if _Loading == true then return end - local ft = vim.bo.filetype if ft == nil then ft = vim.api.nvim_buf_get_option(0, "filetype") end @@ -311,8 +317,8 @@ local function setup(user_opts) "csv", "txt", "markdown", "defx" } for i = 1, #disable_ft do - if ft == disable_ft[i] then - trace("navigator disabled for ft", ft) + if ft == disable_ft[i] or _LoadedClients[ft] then + trace("navigator disabled for ft or it is loaded", ft) return end end @@ -332,7 +338,7 @@ local function setup(user_opts) local lsp_opts = user_opts.lsp _Loading = true wait_lsp_startup(ft, retry, lsp_opts) - + _LoadedClients[ft] = true _Loading = false -- if not _NgConfigValues.loaded then @@ -340,4 +346,4 @@ local function setup(user_opts) -- _NgConfigValues.loaded = true -- end end -return {setup = setup, cap = cap} +return {setup = setup} diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index b71eaa1..8759f12 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -85,7 +85,7 @@ function M.get_relative_path(base_path, my_path) return data end -local default_config = {plugin = "navigator", use_console = false, use_file = true, level = "error"} +local default_config = {plugin = "navigator", use_console = false, use_file = true, level = "info"} M._log = require("guihua.log").new({level = default_config.level}, true)