Skip to content

Commit

Permalink
Merge pull request #99 from uga-rosa/fix/98
Browse files Browse the repository at this point in the history
Ignore range only cmdline
  • Loading branch information
hrsh7th committed Jun 8, 2023
2 parents 5af1bb7 + 02ec99c commit 8ee981b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lua/cmp_cmdline/init.lua
Expand Up @@ -41,6 +41,12 @@ local COUNT_RANGE_REGEX = create_regex({
[=[\s*\%(\d\+\|\$\)\s*]=],
}, true)

local ONLY_RANGE_REGEX = create_regex({
[=[^\s*\%(\d\+\|\$\)\%[,\%(\d\+\|\$\)]\s*$]=],
[=[^\s*'\%[<,'>]\s*$]=],
[=[^\s*\%(\d\+\|\$\)\s*$]=],
}, true)

local OPTION_NAME_COMPLETION_REGEX = create_regex({
[=[se\%[tlocal][^=]*$]=],
}, true)
Expand Down Expand Up @@ -72,6 +78,11 @@ local definitions = {
kind = cmp.lsp.CompletionItemKind.Variable,
isIncomplete = true,
exec = function(option, arglead, cmdline, force)
-- Ignore range only cmdline. (e.g.: 4, '<,'>)
if not force and ONLY_RANGE_REGEX:match_str(cmdline) then
return {}
end

local _, parsed = pcall(function()
local target = cmdline
local s, e = COUNT_RANGE_REGEX:match_str(target)
Expand Down Expand Up @@ -110,11 +121,6 @@ local definitions = {
fixed_input = string.sub(arglead, 1, suffix_pos or #arglead)
end

-- Ignore prefix only cmdline. (e.g.: 4, '<,'>)
if not force and cmdline == '' then
return {}
end

-- The `vim.fn.getcompletion` does not return `*no*cursorline` option.
-- cmp-cmdline corrects `no` prefix for option name.
local is_option_name_completion = OPTION_NAME_COMPLETION_REGEX:match_str(cmdline) ~= nil
Expand Down

0 comments on commit 8ee981b

Please sign in to comment.