Skip to content

Commit

Permalink
correctly handle apply option
Browse files Browse the repository at this point in the history
Jan Steinke committed Mar 27, 2024
1 parent ca09f27 commit 1b612f7
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lua/lsp-preview/config.lua
Original file line number Diff line number Diff line change
@@ -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]
5 changes: 2 additions & 3 deletions lua/lsp-preview/init.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1b612f7

Please sign in to comment.