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

Incorrect behaviour in cmdline completion #1117

Open
2 tasks done
yoursvivek opened this issue Jan 30, 2025 · 3 comments
Open
2 tasks done

Incorrect behaviour in cmdline completion #1117

yoursvivek opened this issue Jan 30, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@yoursvivek
Copy link

Make sure you have done the following

  • Updated to the latest version of blink.cmp
  • Searched for existing issues and documentation (try <C-k> on https://cmp.saghen.dev)

Bug Description

When completing cmdline with :set foldmethod= completion shows up but when select_next/select_prev is issued using <C-N> or <DOWN> (or <C-P> or <UP>), existing word foldmethod= gets removed. Other keys like <C-Space>, <C-E>, etc work fine and don't remove existing word.

Bug is reproducible with only blink.cmp and lazy.nvim being only two plugins enabled.

Example:

Just after typing :set foldmethod=
Image

After further typing <C-N>
Image

Relevant configuration

---@module "blink.cmp"
---@type blink.cmp.Config
opts = {
  appearance = {
    use_nvim_cmp_as_default = true,
  },
  completion = {
    menu = {
      draw = {
        treesitter = { "lsp" },
        columns = { { 'kind_icon' }, { 'label', 'label_description', gap = 1 }, { "source_name", gap = 1 } },
      },
    },
    documentation = {
      auto_show = true,
    },
  },
  sources = {
    default = { "lsp", "path", "snippets", "buffer" },
  },
  signature = { enabled = true },
}

neovim version

NVIM v0.10.3 Build type: Release LuaJIT 2.1.1736781742 Run "nvim -V1 -v" for more info

blink.cmp version

commit b6f11a0

@yoursvivek yoursvivek added the bug Something isn't working label Jan 30, 2025
@emxxjnm
Copy link

emxxjnm commented Feb 5, 2025

same issue

2025-02-05.11.32.40.mov

@yoursvivek
Copy link
Author

yoursvivek commented Feb 5, 2025

This also happens when one starts with V-Line mode and select suggestions, :'<,'> range gets removed entirely and replaced by suggestion.

@Saghen, if you could point me to suspected region in code base, I can take a stab at patching this.

@someoneinjd
Copy link

This bug was introduced by commit 9854978 :

@@ -81,14 +81,14 @@ function cmdline:get_completions(context, callback)

        -- remove prefix from the filter text
        local filter_text = completion
-       if has_prefix then filter_text = completion:sub(#current_arg_prefix + 1) end
+       if has_prefix and cmd == 'lua' then filter_text = completion:sub(#current_arg_prefix + 1) end

        -- for lua, use the filter text as the label since it doesn't include the prefix
        local label = cmd == 'lua' and filter_text or completion

        -- add prefix to the newText
        local new_text = completion
-       if not has_prefix then new_text = current_arg_prefix .. completion end
+       if not has_prefix and cmd == 'lua' then new_text = current_arg_prefix .. completion end

        table.insert(items, {
          label = label,

In this commit, to resolve #1075, the prefixes for all non :lua commands were ignored, which resulted in the various issues mentioned above. A more suitable approach might be to determine whether to ignore the prefix based on different completion types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants