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.
require("cosmic-ui").setup({
codeactions = {
enabled = true,
},
})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",
},
}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.
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
codeactionsis disabled - executes code action requests via the internal
cosmic-ui.codeactionsimplementation - 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)
- key hints (
Enter:apply q:close) are rendered as an in-buffer footer row - the menu opens below the cursor and flips above it when there is not enough screen space below
- keymaps:
j/k,<Down>/<Up>,<Tab>/<S-Tab>,<CR>/<Space>,<Esc>/<C-c>/q
require("cosmic-ui").codeactions.open()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,
})Requests code actions for the active visual selection.
Behavior:
- uses
opts.rangewhen provided - else uses
opts.paramswhen provided - else builds range from the active visual selection, or from the
'<and'>marks outside visual mode - warns and no-ops if
setup()has not run or module is disabled
vim.keymap.set("v", "<leader>ga", function()
require("cosmic-ui").codeactions.range()
end)require("cosmic-ui").codeactions.range({
range = { start = { 10, 0 }, ["end"] = { 12, 0 } },
})Optional command:
:CosmicCodeActionsopens the Cosmic code action panel.