Skip to content
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
30 changes: 21 additions & 9 deletions lua/cmp_cmdline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,30 @@ local definitions = {
-- cmp-cmdline corrects `no` prefix for option name.
local is_option_name_completion = OPTION_NAME_COMPLETION_REGEX:match_str(cmdline) ~= nil

local compltype = vim.fn.getcmdcompltype()
local is_path_completion = compltype == 'dir'
or compltype == 'file'
or compltype == 'file_in_path'
or compltype == 'runtime'

--- create items.
local items = {}
local escaped = cmdline:gsub([[\\]], [[\\\\]]);
for _, word_or_item in ipairs(vim.fn.getcompletion(escaped, 'cmdline')) 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)
if is_option_name_completion and is_boolean_option(word) then
table.insert(items, vim.tbl_deep_extend('force', {}, item, {
label = 'no' .. word,
filterText = word,
}))
local completion_ok, completion = pcall(vim.fn.getcompletion, escaped, 'cmdline')
if completion_ok then
for _, word_or_item in ipairs(completion) do
local word = type(word_or_item) == 'string' and word_or_item or word_or_item.word
if is_path_completion then
word = vim.fn.fnameescape(word)
end
local item = { label = word }
table.insert(items, item)
if is_option_name_completion and is_boolean_option(word) then
table.insert(items, vim.tbl_deep_extend('force', {}, item, {
label = 'no' .. word,
filterText = word,
}))
end
end
end

Expand Down