Skip to content

Commit 1b612f7

Browse files
author
Jan Steinke
committed
correctly handle apply option
1 parent ca09f27 commit 1b612f7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lua/lsp-preview/config.lua

+7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ local M = {}
33
---@class Options
44
---Automatically apply code-actions if there is only 1 available.
55
---@field apply boolean
6+
---Preview all changes per default.
7+
---@field previe boolean
68
---Configuration provided to vim.diff (see `:h vim.diff()`)
79
---@field diff table
810
local default_config = {
911
apply = true,
12+
preview = false,
1013
diff = {
1114
ctxlen = 5,
1215
},
@@ -19,6 +22,10 @@ function M.setup(config)
1922
user_config = vim.tbl_deep_extend("force", default_config, config)
2023
end
2124

25+
function M.adhoc_merge(config)
26+
return vim.tbl_deep_extend("force", user_config, config)
27+
end
28+
2229
setmetatable(M, {
2330
__index = function(_, key)
2431
return user_config[key]

lua/lsp-preview/init.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function M.setup(opts)
1515
end
1616

1717
M.rename = function(new_name, opts)
18-
opts = vim.tbl_deep_extend("force", config, opts or {})
18+
opts = config.adhoc_merge(opts or {})
1919

2020
-- Reset it to the original before every operation in case of a failure.
2121
---@diagnostic disable-next-line: duplicate-set-field
@@ -40,7 +40,7 @@ M.rename_preview = function(new_name, opts)
4040
end
4141

4242
M.code_action = function(opts)
43-
opts = vim.tbl_deep_extend("force", config, opts or {})
43+
opts = config.adhoc_merge(opts or {})
4444

4545
-- Reset it to the original before every operation in case of a failure.
4646
---@diagnostic disable-next-line: duplicate-set-field
@@ -56,7 +56,6 @@ M.code_action = function(opts)
5656
util.apply_workspace_edit = lWorkspaceEdit.make_apply_workspace_edit(apply_workspace_edit)
5757

5858
-- automatically trigger Telescope when there is only one action
59-
opts.apply = true
6059
vim.lsp.buf.code_action(opts)
6160
end
6261

0 commit comments

Comments
 (0)