From 419a57a78f816038be08628b9f648d6a20bb2d4b Mon Sep 17 00:00:00 2001 From: bhagwan Date: Sun, 5 Dec 2021 09:31:06 -0800 Subject: [PATCH] LSP: set 'async = false' on all but workspace/document symbols --- README.md | 2 +- doc/fzf-lua.txt | 2 +- lua/fzf-lua/config.lua | 2 +- lua/fzf-lua/providers/lsp.lua | 29 ++++++++++++++++++++++------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 50b627f..f4ed8c8 100644 --- a/README.md +++ b/README.md @@ -567,7 +567,7 @@ require'fzf-lua'.setup { prompt = '❯ ', -- cwd = vim.loop.cwd(), cwd_only = false, -- LSP/diagnostics for cwd only? - async_or_timeout = true, -- timeout(ms) or false for blocking calls + async_or_timeout = 5000, -- timeout(ms) or 'true' for async calls file_icons = true, git_icons = false, lsp_icons = true, diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index a5214a8..69d92e7 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -601,7 +601,7 @@ Consult the list below for available settings: prompt = '❯ ', -- cwd = vim.loop.cwd(), cwd_only = false, -- LSP/diagnostics for cwd only? - async_or_timeout = true, -- timeout(ms) or false for blocking calls + async_or_timeout = 5000, -- timeout(ms) or 'true' for async calls file_icons = true, git_icons = false, lsp_icons = true, diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index a0f4ace..a44f1c4 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -418,7 +418,7 @@ M.globals.lsp = { lsp_icons = true, severity = "hint", cwd_only = false, - async_or_timeout = true, + async_or_timeout = 5000, actions = M.globals.files.actions, icons = { ["Error"] = { icon = "", color = "red" }, -- error diff --git a/lua/fzf-lua/providers/lsp.lua b/lua/fzf-lua/providers/lsp.lua index 434fd9b..da54549 100644 --- a/lua/fzf-lua/providers/lsp.lua +++ b/lua/fzf-lua/providers/lsp.lua @@ -177,6 +177,16 @@ local function set_lsp_fzf_fn(opts) opts.num_callbacks = 0 opts.num_clients = utils.tbl_length(vim.lsp.buf_get_clients(0)) + -- consider 'async_or_timeout' only if + -- 'sync|async' wasn't manually set + if opts.sync == nil and opts.async == nil then + if type(opts.async_or_timeout) == 'number' then + opts.async = false + elseif type(opts.async_or_timeout) == 'boolean' then + opts.async = opts.async_or_timeout + end + end + if opts.sync or opts.async == false then local timeout = 5000 if type(opts.async_or_timeout) == "number" then @@ -247,16 +257,20 @@ local function set_lsp_fzf_fn(opts) return opts end +local set_async_default = function(opts, bool) + if not opts then opts = {} end + if opts.sync == nil and + opts.async == nil and + type(opts.async_or_timeout) == 'number' then + opts.async = bool + end + return opts +end + local normalize_lsp_opts = function(opts, cfg) opts = config.normalize_opts(opts, cfg) if not opts then return end - -- function async params override global config - if opts.async == nil and opts.sync == nil - and opts.async_or_timeout ~= true then - opts.async = false - end - if not opts.cwd then opts.cwd = vim.loop.cwd() end if not opts.prompt or opts.prompt == config.globals.lsp.prompt then opts.prompt = opts.lsp_handler.label .. cfg.prompt @@ -306,7 +320,7 @@ M.implementations = function(opts) end M.document_symbols = function(opts) - if not opts then opts = {} end + opts = set_async_default(opts, true) -- TODO: filename hiding -- since single document opts.ignore_filename = true @@ -314,6 +328,7 @@ M.document_symbols = function(opts) end M.workspace_symbols = function(opts) + opts = set_async_default(opts, true) opts = normalize_lsp_opts(opts, config.globals.lsp) if not opts then return end opts.lsp_params = {query = opts.query or ''}