diff --git a/doc/rustaceanvim.txt b/doc/rustaceanvim.txt index e07f8d82..e1454fc6 100644 --- a/doc/rustaceanvim.txt +++ b/doc/rustaceanvim.txt @@ -250,10 +250,22 @@ rustaceanvim.code-action.Opts *rustaceanvim.code-action.Opts* Fields: ~ {group_icon?} (string) - Text appended to a group action + Text appended to a group action {ui_select_fallback?} (boolean) - Whether to fall back to `vim.ui.select` if there are no grouped code actions. - Default: `false` + Whether to fall back to `vim.ui.select` if there are no grouped code actions. + Default: `false` + {keys} (rustaceanvim.code-action.Keys) + + +rustaceanvim.code-action.Keys *rustaceanvim.code-action.Keys* + + Fields: ~ + {confirm?} (string|string[]) + The key or keys with which to confirm a code action + Default: `""`. + {quit?} (string) + The key or keys with which to close a code action window + Default: `{ "q", "" }`. rustaceanvim.lsp_server_health_status *rustaceanvim.lsp_server_health_status* diff --git a/doc/tags b/doc/tags index 9ad3ad13..3d78e4d9 100644 --- a/doc/tags +++ b/doc/tags @@ -7,6 +7,7 @@ rustaceanvim.FloatWinConfig rustaceanvim.txt /*rustaceanvim.FloatWinConfig* rustaceanvim.LoadRASettingsOpts rustaceanvim.txt /*rustaceanvim.LoadRASettingsOpts* rustaceanvim.Opts rustaceanvim.txt /*rustaceanvim.Opts* rustaceanvim.RAInitializedStatus rustaceanvim.txt /*rustaceanvim.RAInitializedStatus* +rustaceanvim.code-action.Keys rustaceanvim.txt /*rustaceanvim.code-action.Keys* rustaceanvim.code-action.Opts rustaceanvim.txt /*rustaceanvim.code-action.Opts* rustaceanvim.config rustaceanvim.txt /*rustaceanvim.config* rustaceanvim.config.server rustaceanvim.txt /*rustaceanvim.config.server* diff --git a/lua/rustaceanvim/commands/code_action_group.lua b/lua/rustaceanvim/commands/code_action_group.lua index 6603958c..a3d0fd10 100644 --- a/lua/rustaceanvim/commands/code_action_group.lua +++ b/lua/rustaceanvim/commands/code_action_group.lua @@ -3,6 +3,11 @@ local config = require('rustaceanvim.config.internal') local compat = require('rustaceanvim.compat') local M = {} +local confirm_keys = config.tools.code_actions.keys.confirm +local quit_keys = config.tools.code_actions.keys.quit +confirm_keys = type(confirm_keys) == 'table' and confirm_keys or { confirm_keys } +quit_keys = type(quit_keys) == 'table' and quit_keys or { quit_keys } + ---@class rustaceanvim.RACodeAction ---@field kind string ---@field group? string @@ -194,10 +199,12 @@ local function on_code_action_results(results, ctx) vim.api.nvim_buf_set_lines(M.state.primary.bufnr, 0, 1, false, {}) - vim.keymap.set('n', '', on_primary_enter_press, { buffer = M.state.primary.bufnr, noremap = true, silent = true }) - - vim.keymap.set('n', 'q', on_primary_quit, { buffer = M.state.primary.bufnr, noremap = true, silent = true }) - vim.keymap.set('n', '', on_primary_quit, { buffer = M.state.primary.bufnr, noremap = true, silent = true }) + vim.iter(confirm_keys):each(function(key) + vim.keymap.set('n', key, on_primary_enter_press, { buffer = M.state.primary.bufnr, noremap = true, silent = true }) + end) + vim.iter(quit_keys):each(function(key) + vim.keymap.set('n', key, on_primary_quit, { buffer = M.state.primary.bufnr, noremap = true, silent = true }) + end) M.codeactionify_window_buffer(M.state.primary.winnr, M.state.primary.bufnr) @@ -318,10 +325,12 @@ function M.on_cursor_move() vim.api.nvim_buf_set_lines(M.state.secondary.bufnr, 0, 1, false, {}) M.codeactionify_window_buffer(M.state.secondary.winnr, M.state.secondary.bufnr) - - vim.keymap.set('n', '', on_secondary_enter_press, { buffer = M.state.secondary.bufnr }) - - vim.keymap.set('n', 'q', on_secondary_quit, { buffer = M.state.secondary.bufnr }) + vim.iter(confirm_keys):each(function(key) + vim.keymap.set('n', key, on_secondary_enter_press, { buffer = M.state.secondary.bufnr }) + end) + vim.iter(quit_keys):each(function(key) + vim.keymap.set('n', key, on_secondary_quit, { buffer = M.state.secondary.bufnr }) + end) return end diff --git a/lua/rustaceanvim/config/check.lua b/lua/rustaceanvim/config/check.lua index f29333e1..d27ed4d9 100644 --- a/lua/rustaceanvim/config/check.lua +++ b/lua/rustaceanvim/config/check.lua @@ -55,6 +55,23 @@ function M.validate(cfg) if not ok then return false, err end + local code_actions = tools.code_actions + ok, err = validate('tools.code_actions', { + group_icon = { code_actions.group_icon, 'string' }, + ui_select_fallback = { code_actions.ui_select_fallback, 'boolean' }, + keys = { code_actions.keys, 'table' }, + }) + if not ok then + return false, err + end + local keys = code_actions.keys + ok, err = validate('tools.code_actions.keys', { + confirm = { keys.confirm, { 'table', 'string' } }, + quit = { keys.quit, { 'table', 'string' } }, + }) + if not ok then + return false, err + end local float_win_config = tools.float_win_config ok, err = validate('tools.float_win_config', { auto_focus = { float_win_config.auto_focus, 'boolean' }, diff --git a/lua/rustaceanvim/config/init.lua b/lua/rustaceanvim/config/init.lua index be672d63..61c3d3ca 100644 --- a/lua/rustaceanvim/config/init.lua +++ b/lua/rustaceanvim/config/init.lua @@ -130,6 +130,18 @@ vim.g.rustaceanvim = vim.g.rustaceanvim ---Whether to fall back to `vim.ui.select` if there are no grouped code actions. ---Default: `false` ---@field ui_select_fallback? boolean +--- +---@field keys rustaceanvim.code-action.Keys + +---@class rustaceanvim.code-action.Keys +--- +---The key or keys with which to confirm a code action +---Default: `""`. +---@field confirm? string | string[] +--- +---The key or keys with which to close a code action window +---Default: `{ "q", "" }`. +---@field quit? string ---@alias rustaceanvim.lsp_server_health_status 'ok' | 'warning' | 'error' diff --git a/lua/rustaceanvim/config/internal.lua b/lua/rustaceanvim/config/internal.lua index fb6d7044..fdb96cdf 100644 --- a/lua/rustaceanvim/config/internal.lua +++ b/lua/rustaceanvim/config/internal.lua @@ -134,6 +134,14 @@ local RustaceanDefaultConfig = { --- whether to fall back to `vim.ui.select` if there are no grouped code actions ---@type boolean ui_select_fallback = false, + + ---@class rustaceanvim.internal.code_action.Keys + keys = { + ---@type string | string[] + confirm = { '' }, + ---@type string | string[] + quit = { 'q', '' }, + }, }, --- options same as lsp hover