# codeactions Code actions module for `cosmic-ui`. This module validates setup/module enable state and runs code action requests directly. Lua API is primary; `:CosmicCodeActions` is an optional wrapper. ## Setup ```lua require("cosmic-ui").setup({ codeactions = { enabled = true, }, }) ``` ## ⚙️ Config ```lua codeactions = { enabled = true, min_width = nil, border = { bottom_hl = "FloatBorder", highlight = "FloatBorder", style = nil, -- falls back to vim.o.winborder title = "Code Actions", title_align = "center", title_hl = "FloatBorder", }, } ``` ## Types ### `opts` Optional request options passed to the code action core module. | Field | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | `params` | `table\|nil` | No | `nil` | Complete LSP `CodeActionParams` replacement. | | `range` | `table\|nil` | No | `nil` | Optional range `{ start, end }`. | | `range.start` | `{integer, integer}\|nil` | No | `nil` | Optional start position `{line, col}`. | | `range.end` | `{integer, integer}\|nil` | No | `nil` | Optional end position `{line, col}`. | `params` replaces automatic position construction, so it must include `textDocument` and `range`. Its optional `context` is preserved, and missing diagnostics are populated by cosmic-ui. Build cursor positions with the target client's offset encoding. ## Module ### `require("cosmic-ui").codeactions.open(opts?)` Requests and opens code actions at the current cursor context. Behavior: - warns and no-ops if `setup()` has not run - warns and no-ops if `codeactions` is disabled - executes code action requests via the internal `cosmic-ui.codeactions` implementation - opens a native floating menu (no NUI dependency) - menu groups are ordered deterministically by client name (tie-break: client id) - actions within each client group keep server response order - group headers are rendered as plain section rows - selection index/count is shown in the float border footer (right-aligned) - keymaps: `j`/`k`, ``/``, ``/``, ``/``, ``/`` ```lua require("cosmic-ui").codeactions.open() ``` ```lua local bufnr = vim.api.nvim_get_current_buf() local target_client = assert(vim.lsp.get_clients({ bufnr = bufnr, method = "textDocument/codeAction", })[1]) local params = vim.lsp.util.make_range_params(0, target_client.offset_encoding) params.context = { only = { "quickfix" } } require("cosmic-ui").codeactions.open({ params = params, }) ``` ### `require("cosmic-ui").codeactions.range(opts?)` Requests code actions for the active visual selection. Behavior: - uses `opts.range` when provided - else uses `opts.params` when provided - else builds range from visual marks `'<` and `'>` - warns and no-ops if `setup()` has not run or module is disabled ```lua vim.keymap.set("v", "ga", function() require("cosmic-ui").codeactions.range() end) ``` ```lua require("cosmic-ui").codeactions.range({ range = { start = { 10, 0 }, ["end"] = { 12, 0 } }, }) ``` Optional command: - `:CosmicCodeActions` opens the Cosmic code action panel.