From 555ba5e2f10626d16d07c58bc5953867505b899e Mon Sep 17 00:00:00 2001 From: ColdMacaroni <57285804+ColdMacaroni@users.noreply.github.com> Date: Mon, 15 Apr 2024 02:46:57 +1200 Subject: [PATCH] feat(config): customisable group action icon (#347) Co-authored-by: sofa Co-authored-by: Marc Jakobi Co-authored-by: Marc Jakobi --- CHANGELOG.md | 7 +++++++ doc/rustaceanvim.txt | 1 + lua/rustaceanvim/commands/code_action_group.lua | 4 ++-- lua/rustaceanvim/config/init.lua | 1 + lua/rustaceanvim/config/internal.lua | 4 ++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b50cd14..8aba877f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.22.0] - 2024-04-14 + +### Added + +- Config: Customise group action icon with `tools.code_actions.group_icon`. + Thanks [@ColdMacaroni](https://github.com/ColdMacaroni)! + ## [4.21.2] - 2024-04-13 ### Fixed diff --git a/doc/rustaceanvim.txt b/doc/rustaceanvim.txt index 667c05a7..2a154763 100644 --- a/doc/rustaceanvim.txt +++ b/doc/rustaceanvim.txt @@ -189,6 +189,7 @@ RustaceanHoverActionsOpts *RustaceanHoverActionsOpts* RustaceanCodeActionOpts *RustaceanCodeActionOpts* Fields: ~ + {group_icon?} (string) Text appended to a group action. Default: `" ▶"` {ui_select_fallback?} (boolean) Whether to fall back to `vim.ui.select` if there are no grouped code actions. Default: `false` diff --git a/lua/rustaceanvim/commands/code_action_group.lua b/lua/rustaceanvim/commands/code_action_group.lua index adfe33db..df468d98 100644 --- a/lua/rustaceanvim/commands/code_action_group.lua +++ b/lua/rustaceanvim/commands/code_action_group.lua @@ -74,7 +74,7 @@ local function compute_width(action_tuples, is_group) local text = action.title if is_group and action.group then - text = action.group .. ' ▶' + text = action.group .. config.tools.code_actions.group_icon end local len = string.len(text) if len > width then @@ -180,7 +180,7 @@ local function on_code_action_results(results, ctx) local idx = 1 for key, value in pairs(M.state.actions.grouped) do value.idx = idx - vim.api.nvim_buf_set_lines(M.state.primary.bufnr, -1, -1, false, { key .. ' ▶' }) + vim.api.nvim_buf_set_lines(M.state.primary.bufnr, -1, -1, false, { key .. config.tools.code_actions.group_icon }) idx = idx + 1 end diff --git a/lua/rustaceanvim/config/init.lua b/lua/rustaceanvim/config/init.lua index 30f18857..aabf4547 100644 --- a/lua/rustaceanvim/config/init.lua +++ b/lua/rustaceanvim/config/init.lua @@ -84,6 +84,7 @@ vim.g.rustaceanvim = vim.g.rustaceanvim ---@field replace_builtin_hover? boolean Whether to replace Neovim's built-in `vim.lsp.buf.hover` with hover actions. Default: `true` ---@class RustaceanCodeActionOpts +---@field group_icon? string Text appended to a group action ---@field ui_select_fallback? boolean Whether to fall back to `vim.ui.select` if there are no grouped code actions. Default: `false` ---@alias lsp_server_health_status 'ok' | 'warning' | 'error' diff --git a/lua/rustaceanvim/config/internal.lua b/lua/rustaceanvim/config/internal.lua index f1d79203..ae44397e 100644 --- a/lua/rustaceanvim/config/internal.lua +++ b/lua/rustaceanvim/config/internal.lua @@ -128,6 +128,10 @@ local RustaceanDefaultConfig = { }, code_actions = { + --- text appended to a group action + ---@type string + group_icon = ' ▶', + --- whether to fall back to `vim.ui.select` if there are no grouped code actions ---@type boolean ui_select_fallback = false,