From 59fdcdc3e0e9a6603242be4abfac1d4fd755d7eb Mon Sep 17 00:00:00 2001 From: bhagwan Date: Thu, 20 Jan 2022 14:12:46 -0800 Subject: [PATCH] always use 'vim.ui.select' for code actions when neovim > 0.6 --- lua/fzf-lua/providers/lsp.lua | 14 ++++++++++++++ lua/fzf-lua/providers/ui_select.lua | 30 +++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lua/fzf-lua/providers/lsp.lua b/lua/fzf-lua/providers/lsp.lua index 482c36c..977b5b4 100644 --- a/lua/fzf-lua/providers/lsp.lua +++ b/lua/fzf-lua/providers/lsp.lua @@ -343,6 +343,20 @@ end M.code_actions = function(opts) opts = normalize_lsp_opts(opts, config.globals.lsp) if not opts then return end + -- use `vim.ui.select` for neovim > 0.6 + -- the original method is now deprecated + if vim.fn.has('nvim-0.6') == 1 then + local ui_select = require'fzf-lua.providers.ui_select' + opts.previewer = false + opts.actions = opts.actions or {} + opts.actions.default = nil + opts.post_action_cb = function() + ui_select.deregister({}, true, true) + end + ui_select.register(opts, true) + vim.lsp.buf.code_action() + return + end -- irrelevant for code actions and can cause -- single results to be skipped with 'async = false' opts.jump_to_single_result = false diff --git a/lua/fzf-lua/providers/ui_select.lua b/lua/fzf-lua/providers/ui_select.lua index d45ec5b..d03c176 100644 --- a/lua/fzf-lua/providers/ui_select.lua +++ b/lua/fzf-lua/providers/ui_select.lua @@ -8,24 +8,35 @@ local M = {} local _opts = nil local _old_ui_select = nil -M.deregister = function() +M.deregister = function(_, silent, noclear) if not _old_ui_select then - utils.info("vim.ui.select in not registered to fzf-lua") + if not silent then + utils.info("vim.ui.select in not registered to fzf-lua") + end + return false end vim.ui.select = _old_ui_select _old_ui_select = nil - _opts = nil + -- do not empty _opts incase when + -- resume from `lsp_code_actions` + if not noclear then + _opts = nil + end + return true end -M.register = function(opts) +M.register = function(opts, silent) if vim.ui.select == M.ui_select then -- already registered - utils.info("vim.ui.select already registered to fzf-lua") - return + if not silent then + utils.info("vim.ui.select already registered to fzf-lua") + end + return false end _opts = opts _old_ui_select = vim.ui.select vim.ui.select = M.ui_select + return true end M.ui_select = function(items, opts, on_choice) @@ -96,10 +107,13 @@ M.ui_select = function(items, opts, on_choice) if not selected then on_choice(nil, nil) - return + else + actions.act(_opts.actions, selected, _opts) end - actions.act(_opts.actions, selected, _opts) + if _opts.post_action_cb then + _opts.post_action_cb() + end end)()