Skip to content

Commit 9c5d051

Browse files
committed
set up completion for :Magenta command
h/t to https://github.com/alvarosevilla95 for the initial PR #40
1 parent d6931a0 commit 9c5d051

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lua/magenta/init.lua

+26-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ M.start = function(silent)
5151
end
5252
end
5353

54+
local normal_commands = {
55+
"abort",
56+
"clear",
57+
"context-files",
58+
"provider",
59+
"start-inline-edit",
60+
"toggle",
61+
}
62+
63+
local visual_commands = {
64+
"start-inline-edit-selection",
65+
"paste-selection",
66+
}
67+
5468
M.bridge = function(channelId)
5569
vim.api.nvim_create_user_command(
5670
"Magenta",
@@ -60,7 +74,18 @@ M.bridge = function(channelId)
6074
{
6175
nargs = "+",
6276
range = true,
63-
desc = "Execute Magenta command"
77+
desc = "Execute Magenta command",
78+
complete = function(ArgLead, CmdLine)
79+
local commands = CmdLine:match("^'<,'>") and visual_commands or normal_commands
80+
81+
if ArgLead == '' then
82+
return commands
83+
end
84+
-- Filter based on ArgLead
85+
return vim.tbl_filter(function(cmd)
86+
return cmd:find('^' .. ArgLead)
87+
end, commands)
88+
end
6489
}
6590
)
6691

0 commit comments

Comments
 (0)