From 1b612f7f33df5916a3a9434b48a6ac15fdd00641 Mon Sep 17 00:00:00 2001 From: Jan Steinke Date: Wed, 27 Mar 2024 19:48:10 +0100 Subject: [PATCH] correctly handle apply option --- lua/lsp-preview/config.lua | 7 +++++++ lua/lsp-preview/init.lua | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/lsp-preview/config.lua b/lua/lsp-preview/config.lua index bcf090f..efd579a 100644 --- a/lua/lsp-preview/config.lua +++ b/lua/lsp-preview/config.lua @@ -3,10 +3,13 @@ local M = {} ---@class Options ---Automatically apply code-actions if there is only 1 available. ---@field apply boolean +---Preview all changes per default. +---@field previe boolean ---Configuration provided to vim.diff (see `:h vim.diff()`) ---@field diff table local default_config = { apply = true, + preview = false, diff = { ctxlen = 5, }, @@ -19,6 +22,10 @@ function M.setup(config) user_config = vim.tbl_deep_extend("force", default_config, config) end +function M.adhoc_merge(config) + return vim.tbl_deep_extend("force", user_config, config) +end + setmetatable(M, { __index = function(_, key) return user_config[key] diff --git a/lua/lsp-preview/init.lua b/lua/lsp-preview/init.lua index 9dbce17..ed23778 100644 --- a/lua/lsp-preview/init.lua +++ b/lua/lsp-preview/init.lua @@ -15,7 +15,7 @@ function M.setup(opts) end M.rename = function(new_name, opts) - opts = vim.tbl_deep_extend("force", config, opts or {}) + opts = config.adhoc_merge(opts or {}) -- Reset it to the original before every operation in case of a failure. ---@diagnostic disable-next-line: duplicate-set-field @@ -40,7 +40,7 @@ M.rename_preview = function(new_name, opts) end M.code_action = function(opts) - opts = vim.tbl_deep_extend("force", config, opts or {}) + opts = config.adhoc_merge(opts or {}) -- Reset it to the original before every operation in case of a failure. ---@diagnostic disable-next-line: duplicate-set-field @@ -56,7 +56,6 @@ M.code_action = function(opts) util.apply_workspace_edit = lWorkspaceEdit.make_apply_workspace_edit(apply_workspace_edit) -- automatically trigger Telescope when there is only one action - opts.apply = true vim.lsp.buf.code_action(opts) end