From 59de53fbbe083081168d0cd1ad31a24c3ee5ba63 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Tue, 1 Mar 2022 15:51:43 -0800 Subject: [PATCH] lsp_code_actions: 'deepcopy' fallback, 'ui_select' control opt (#353) --- README.md | 1 + doc/fzf-lua.txt | 1 + lua/fzf-lua/config.lua | 1 + lua/fzf-lua/core.lua | 4 ++-- lua/fzf-lua/providers/lsp.lua | 2 +- lua/fzf-lua/utils.lua | 9 +++++++++ 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac4fa94..9d1d9ec 100644 --- a/README.md +++ b/README.md @@ -636,6 +636,7 @@ require'fzf-lua'.setup { git_icons = false, lsp_icons = true, severity = "hint", + ui_select = true, -- use 'vim.ui.select' for code actions icons = { ["Error"] = { icon = "", color = "red" }, -- error ["Warning"] = { icon = "", color = "yellow" }, -- warning diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index d541de8..46cc314 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -678,6 +678,7 @@ Consult the list below for available settings: git_icons = false, lsp_icons = true, severity = "hint", + ui_select = true, -- use 'vim.ui.select' for code actions icons = { ["Error"] = { icon = "", color = "red" }, -- error ["Warning"] = { icon = "", color = "yellow" }, -- warning diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index bde3a91..cdd937c 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -433,6 +433,7 @@ M.globals.lsp = { git_icons = false, lsp_icons = true, cwd_only = false, + ui_select = true, async_or_timeout = 5000, _actions = function() return M.globals.actions.files end, icons = { diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 9c22fb5..7e25100 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -56,8 +56,8 @@ M.fzf = function(opts, contents) -- support global resume? if opts.global_resume then config.__resume_data = config.__resume_data or {} - config.__resume_data.opts = vim.deepcopy(opts) - config.__resume_data.contents = contents and vim.deepcopy(contents) or nil + config.__resume_data.opts = utils.deepcopy(opts) + config.__resume_data.contents = contents and utils.deepcopy(contents) or nil if not opts.__resume then -- since the shell callback isn't called -- until the user first types something diff --git a/lua/fzf-lua/providers/lsp.lua b/lua/fzf-lua/providers/lsp.lua index 53df23d..dc8a072 100644 --- a/lua/fzf-lua/providers/lsp.lua +++ b/lua/fzf-lua/providers/lsp.lua @@ -370,7 +370,7 @@ M.code_actions = function(opts) -- use `vim.ui.select` for neovim > 0.6 -- the original method is now deprecated - if vim.fn.has('nvim-0.6') == 1 then + if opts.ui_select and 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 {} diff --git a/lua/fzf-lua/utils.lua b/lua/fzf-lua/utils.lua index 4ff94ed..97efea9 100644 --- a/lua/fzf-lua/utils.lua +++ b/lua/fzf-lua/utils.lua @@ -210,6 +210,15 @@ M.read_file_async = function(filepath, callback) end +function M.deepcopy(t) + local ok, res = pcall(vim.deepcopy, t) + if ok then + return res + else + return M.tbl_deep_clone(t) + end +end + function M.tbl_deep_clone(t) if not t then return end local clone = {}