Skip to content

Commit

Permalink
feat(API): fzf_exec returns coroutine object (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Aug 9, 2024
1 parent 2c4f76a commit f3d04fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ M.fzf_exec = function(contents, opts)
opts = M.setup_fzf_interactive_wrap(opts)
contents = opts.__fzf_init_cmd
end
return M.fzf_wrap(opts, contents)()
return M.fzf_wrap(opts, contents)
end

---@param contents fun(query: string): string|string[]|function
Expand All @@ -217,10 +217,11 @@ end
---@param opts table
---@param contents content
---@param fn_selected function?
---@return function
---@return thread
M.fzf_wrap = function(opts, contents, fn_selected)
opts = opts or {}
return coroutine.wrap(function()
coroutine.wrap(function()
opts._co = coroutine.running()
opts.fn_selected = opts.fn_selected or fn_selected
local selected = M.fzf(contents, opts)
if opts.fn_selected then
Expand All @@ -237,7 +238,8 @@ M.fzf_wrap = function(opts, contents, fn_selected)
utils.err("fn_selected threw an error: " .. debug.traceback(err, 1))
end)
end
end)
end)()
return opts._co
end

-- conditionally update the context if fzf-lua
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ M.live_workspace_symbols = function(opts)
opts.fn_pre_fzf = function() gen_sym2style_map(opts) end
opts.fn_post_fzf = function() M._sym2style = nil end
end
core.fzf_exec(nil, opts)
return core.fzf_exec(nil, opts)
end

-- Converts 'vim.diagnostic.get' to legacy style 'get_line_diagnostics()'
Expand Down Expand Up @@ -984,7 +984,7 @@ local function wrap_fn(key, fn)
end

-- Call the original method
fn(opts)
return fn(opts)
end
end

Expand Down

0 comments on commit f3d04fa

Please sign in to comment.