From f16893fc4fde3eca744e3f9075a8c53f98cf8b8f Mon Sep 17 00:00:00 2001 From: ray-x Date: Mon, 5 Jul 2021 08:52:48 +1000 Subject: [PATCH] Revert "improve launching time" This reverts commit b08bfd68396b4f0afe6bffe6939760d876e487ea. --- lua/navigator/lspclient/clients.lua | 74 +++++++++++++++-------------- lua/navigator/lspclient/mapping.lua | 3 +- lua/navigator/lspwrapper.lua | 2 +- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 552347e..97dfd81 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -288,47 +288,49 @@ local function wait_lsp_startup(ft, retry, lsp_opts) local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true - for _, client in ipairs(clients) do - if client ~= nil then - table.insert(loaded, client.name) - end - end - for _, lspclient in ipairs(servers) do - if lsp_opts[lspclient] ~= nil and lsp_opts[lspclient].filetypes ~= nil then - if not vim.tbl_contains(lsp_opts[lspclient].filetypes, ft) then - trace("ft", ft, "disabled for", lspclient) - goto continue + for _ = 1, 2 do + for _, client in ipairs(clients) do + if client ~= nil then + table.insert(loaded, client.name) end end - local cfg = setups[lspclient] or default_cfg - -- if user provides override values + for _, lspclient in ipairs(servers) do + if lsp_opts[lspclient] ~= nil and lsp_opts[lspclient].filetypes ~= nil then + if not vim.tbl_contains(lsp_opts[lspclient].filetypes, ft) then + trace("ft", ft, "disabled for", lspclient) + goto continue + end + end + local cfg = setups[lspclient] or default_cfg + -- if user provides override values - cfg.capabilities = capabilities - if lsp_opts[lspclient] ~= nil then - -- log(lsp_opts[lspclient], cfg) - cfg = vim.tbl_deep_extend("force", cfg, lsp_opts[lspclient]) - end + cfg.capabilities = capabilities + if lsp_opts[lspclient] ~= nil then + -- log(lsp_opts[lspclient], cfg) + cfg = vim.tbl_deep_extend("force", cfg, lsp_opts[lspclient]) + end - load_cfg(ft, lspclient, cfg, loaded) - ::continue:: - end - if not retry or ft == nil then - return - end - -- - local timer = vim.loop.new_timer() - local i = 0 - timer:start(1000, 200, function() - clients = vim.lsp.get_active_clients() or {} - i = i + 1 - if i > 5 or #clients > 0 then - timer:close() -- Always close handles to avoid leaks. - log("active", #clients, i) - _Loading = false - return true + load_cfg(ft, lspclient, cfg, loaded) + ::continue:: + end + if not retry or ft == nil then + return end - _Loading = false - end) + -- + local timer = vim.loop.new_timer() + local i = 0 + vim.wait(1000, function() + clients = vim.lsp.get_active_clients() or {} + i = i + 1 + if i > 5 or #clients > 0 then + timer:close() -- Always close handles to avoid leaks. + log("active", #clients, i) + _Loading = false + return true + end + _Loading = false + end, 300) + end end local function setup(user_opts) diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index 43e8aa2..20b0a4a 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -115,11 +115,12 @@ local function set_mapping(user_opts) end if ccls then - -- log("override ccls", ccls_mappings) + log("override ccls", ccls_mappings) for _, value in pairs(ccls_mappings) do f = "lua " .. value.func .. "" local k = value.key local m = value.mode or "n" + log(f, k, m) set_keymap(m, k, f, opts) end end diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index 3f87cad..4fd9c17 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -268,7 +268,7 @@ function M.locations_to_items(locations) item.range = locations[i].range if is_win then - log(item.uri) -- file:///C:/path/to/file + log(item.uri) log(cwd) end -- only load top 30 file.