fix(lsp): better coroutine logic when 'async=true' (#468)

main
bhagwan 2 years ago
parent 8c0408529a
commit d6691568b7

@ -643,7 +643,7 @@ open an issue and I'll be more than happy to help.**
}, },
bcommits = { bcommits = {
prompt = 'BCommits ', prompt = 'BCommits ',
-- default preview shows a git diff vs the preview commit -- default preview shows a git diff vs the previous commit
-- if you prefer to see the entire commit you can use: -- if you prefer to see the entire commit you can use:
-- git show --color {1} --rotate-to=<file> -- git show --color {1} --rotate-to=<file>
-- {1} : commit SHA (fzf field index expression) -- {1} : commit SHA (fzf field index expression)

@ -132,20 +132,21 @@ local function async_lsp_handler(co, handler, opts)
if err then if err then
utils.err(string.format("Error executing '%s': %s", handler.method, err)) utils.err(string.format("Error executing '%s': %s", handler.method, err))
utils.fzf_exit() utils.fzf_exit()
coroutine.resume(co, err) coroutine.resume(co, true, err)
elseif not result or vim.tbl_isempty(result) then else
-- Only close the window if all clients sent their results -- did all clients send back their responses?
if opts.num_callbacks == opts.num_clients and opts.num_results == 0 then local done = opts.num_callbacks == opts.num_clients
-- Do not close the window for 'live_workspace_symbols' -- only close the window if after all clients sent
-- their results we still have zero results
if done and opts.num_results == 0 then
-- Do not close the window in 'live_workspace_symbols'
if not opts.fn_reload then if not opts.fn_reload then
utils.info(string.format('No %s found', string.lower(handler.label))) utils.info(string.format('No %s found', string.lower(handler.label)))
utils.fzf_exit() utils.fzf_exit()
end end
coroutine.resume(co)
end end
else -- resume the coroutine
local done = opts.num_callbacks == opts.num_clients coroutine.resume(co, done, err, result, context, lspcfg)
coroutine.resume(co, err, result, context, lspcfg, done)
end end
end) end)
end end
@ -198,8 +199,8 @@ local function set_lsp_fzf_fn(opts)
opts.fzf_fn = {} opts.fzf_fn = {}
end end
elseif not (opts.jump_to_single_result and #results == 1) then elseif not (opts.jump_to_single_result and #results == 1) then
-- LSP request was synchronou but we can -- LSP request was synchronous but
-- still async the fzf feeding -- we still async the fzf feeding
opts.fzf_fn = function (fzf_cb) opts.fzf_fn = function (fzf_cb)
coroutine.wrap(function () coroutine.wrap(function ()
local co = coroutine.running() local co = coroutine.running()
@ -251,7 +252,7 @@ local function set_lsp_fzf_fn(opts)
-- process results from all LSP client -- process results from all LSP client
local err, result, context, lspcfg, done local err, result, context, lspcfg, done
repeat repeat
err, result, context, lspcfg, done = coroutine.yield() done, err, result, context, lspcfg = coroutine.yield()
if not err and type(result) == 'table' then if not err and type(result) == 'table' then
local cb = function(e) local cb = function(e)
fzf_cb(e, function() coroutine.resume(co) end) fzf_cb(e, function() coroutine.resume(co) end)
@ -260,7 +261,9 @@ local function set_lsp_fzf_fn(opts)
opts.lsp_handler.handler(opts, cb, opts.lsp_handler.handler(opts, cb,
opts.lsp_handler.method, result, context, lspcfg) opts.lsp_handler.method, result, context, lspcfg)
end end
until done or err or result == nil -- some clients may not always return results (null-ls?)
-- so don't terminate the loop when 'result == nil`
until done or err
-- no more results -- no more results
fzf_cb(nil) fzf_cb(nil)

Loading…
Cancel
Save