Skip to content

Commit

Permalink
set up completion for :Magenta command
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed Feb 4, 2025
1 parent d6931a0 commit 9c5d051
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lua/magenta/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ M.start = function(silent)
end
end

local normal_commands = {
"abort",
"clear",
"context-files",
"provider",
"start-inline-edit",
"toggle",
}

local visual_commands = {
"start-inline-edit-selection",
"paste-selection",
}

M.bridge = function(channelId)
vim.api.nvim_create_user_command(
"Magenta",
Expand All @@ -60,7 +74,18 @@ M.bridge = function(channelId)
{
nargs = "+",
range = true,
desc = "Execute Magenta command"
desc = "Execute Magenta command",
complete = function(ArgLead, CmdLine)
local commands = CmdLine:match("^'<,'>") and visual_commands or normal_commands

if ArgLead == '' then
return commands
end
-- Filter based on ArgLead
return vim.tbl_filter(function(cmd)
return cmd:find('^' .. ArgLead)
end, commands)
end
}
)

Expand Down

0 comments on commit 9c5d051

Please sign in to comment.