Skip to content

Commit

Permalink
docs: explain nvim_parse_cmd reasoning
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Jan 11, 2025
1 parent 706bac4 commit 66860d3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lua/blink/cmp/sources/cmdline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ function cmdline:get_completions(context, callback)
local keyword = context.get_bounds(keyword_config.range)
local current_arg_prefix = current_arg:sub(1, keyword.start_col - #text_before_argument - 1)

-- Parse the command to ignore modifiers like :vert help
-- Fails in some cases, like context.line = ':vert' so we fallback to the first argument
local valid_cmd, parsed = pcall(vim.api.nvim_parse_cmd, context.line, {})
local cmd = (valid_cmd and parsed.cmd) or arguments[1] or ''

local task = async.task
.empty()
:map(function()
local cmd = (valid_cmd and parsed.cmd) or arguments[1] or ''
-- Special case for help where we read all the tags ourselves
if vim.tbl_contains(constants.help_commands, cmd) then
return require('blink.cmp.sources.cmdline.help').get_completions(current_arg_prefix)
Expand Down

0 comments on commit 66860d3

Please sign in to comment.