Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @ cmdtype completion for input() function #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lua/cmp_cmdline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ local definitions = {
target = target:sub(e + 1)
end
-- nvim_parse_cmd throw error when the cmdline contains range specifier.
return vim.api.nvim_parse_cmd(target, {}) or {}
return vim.api.nvim_parse_cmd(target, { mods = { silent = true } }) or {}
end)
parsed = parsed or {}

Expand Down Expand Up @@ -126,8 +126,18 @@ local definitions = {
local is_option_name_completion = OPTION_NAME_COMPLETION_REGEX:match_str(cmdline) ~= nil

local items = {}

local escaped = cmdline:gsub([[\\]], [[\\\\]]);
for _, word_or_item in ipairs(vim.fn.getcompletion(escaped, 'cmdline')) do
local cmdtype = 'cmdline'
if vim.fn.getcmdtype() == '@' then
-- Invoke getcmdcompltype() only when getcmdtype() == '@'.
-- Because once getcmdcompltype() was executed, press <Up> <Down> for ':e ./' will get wrong result on command line.
local cpl = vim.fn.getcmdcompltype()
if cpl ~= '' then
cmdtype = cpl
end
end
for _, word_or_item in ipairs(vim.fn.getcompletion(escaped, cmdtype)) do
local word = type(word_or_item) == 'string' and word_or_item or word_or_item.word
local item = { label = word }
table.insert(items, item)
Expand Down