nvf icon indicating copy to clipboard operation
nvf copied to clipboard

blink-cmp default's cmdline doesn't work, needs flags to turn on

Open mnpqraven opened this issue 9 months ago • 4 comments

⚠️ Please verify that this bug has NOT been reported before.

  • [x] I checked all existing issues and didn't find a similar issue

Description

right now enabling blink-cmp with the default options works fine with normal completions, but cmdline won't work at all unless we have these flags:

nvf.settings.vim.autocomplete.blink-cmp = {
  setupOpts = {
    cmdline.sources = null;
    cmdline.keymap.preset = "default";
    cmdline.completion.menu.auto_show = true; # not really needed but helps 
  };
};

here are the reasons of why each flag is needed to my understanding:

  • cmdline.sources the default option has this as an empty list (no source) instead of null (default source), so cmdline basically doesn't have source to look for. Should we have null as the default ?
  • cmdline.keymap.preset the default none preset doesn't have any keys so we can't trigger the complete window. The plugin's default is defined as well. Should we update the preset or have the default be inherit to have the same keys already defined in vim.autocomplete.blink-cmp.keymaps
  • cmdline.completion.menu.auto_show this flag helped alot whilst i was debugging the other 2 flags because i had no idea that the keys i assigned weren't applied to the cmdline and also that the cmdline has no source

👟 Reproduction steps

{lib, ...}: {
  programs.nvf.settings.vim.autocomplete = {
    blink-cmp = {
      enable = true;
      friendly-snippets.enable = true;
    };
  };
}

👀 Expected behavior

cmdline fuzzy searching should work ootb

😓 Actual Behavior

cmdline not working

💻 Metadata

  • system: "x86_64-linux" - host os: Linux 6.6.85, NixOS, 24.11 (Vicuna), 24.11.20250405.7819a0d - multi-user?: yes - sandbox: yes - version: nix-env (Nix) 2.24.13 - nixpkgs: /nix/store/v79jbgwmxgiy8m01rhmj4yzn5y507z2c-source

📝 Relevant log output

-- Run with `nvim -u repro.lua`

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

---@diagnostic disable-next-line: missing-fields
require("lazy.minit").repro({
  spec = {
    {
      "saghen/blink.cmp",
      -- please test on `main` if possible
      -- otherwise, remove this line and set `version = '*'`
      build = "cargo build --release",
      config = function()
        require("blink.cmp").setup({
        -- DEFAULT GENERATED BY NVF, UNCOMMENTING THIS LINE MAKES CMDLINE
        -- WORKS
          ["cmdline"] = { ["keymap"] = { ["preset"] = "none" } },
          ["completion"] = {
            ["documentation"] = { ["auto_show"] = true, ["auto_show_delay_ms"] = 200 },
            ["menu"] = {
              ["auto_show"] = true,
              ["draw"] = {
                ["columns"] = { { "label", "label_description", ["gap"] = 4 }, { "kind_icon", "kind" } },
              },
            },
          },
          ["fuzzy"] = {
            ["implementation"] = "prefer_rust_with_warning",
            ["prebuilt_binaries"] = { ["download"] = false },
          },
          ["keymap"] = {
            ["<C-Space>"] = { "show", "fallback" },
            ["<C-d>"] = { "scroll_documentation_down", "fallback" },
            ["<C-e>"] = { "accept", "fallback" },
            ["<C-h>"] = { "cancel" },
            ["<C-n>"] = {
              "select_next",
              "snippet_forward",
              function(cmp)
                local line, col = unpack(vim.api.nvim_win_get_cursor(0))
                has_words_before = col ~= 0
                    and vim.api
                    .nvim_buf_get_lines(0, line - 1, line, true)[1]
                    :sub(col, col)
                    :match("%s")
                    == nil

                if has_words_before then
                  return cmp.show()
                end
              end,
              "fallback",
            },
            ["<C-p>"] = { "select_prev", "snippet_backward", "fallback" },
            ["<C-u>"] = { "scroll_documentation_up", "fallback" },
            ["<CR>"] = { "accept", "fallback" },
            ["preset"] = "none",
          },
          ["signature"] = { ["enabled"] = true },
          ["sources"] = {
            ["default"] = { "lsp", "path", "snippets", "buffer", "buffer", "nvim-cmp", "path" },
            ["providers"] = {
              ["buffer"] = { ["module"] = "blink.compat.source", ["name"] = "buffer" },
              ["nvim-cmp"] = { ["module"] = "blink.compat.source", ["name"] = "nvim-cmp" },
              ["path"] = { ["module"] = "blink.compat.source", ["name"] = "path" },
            },
          },
        })
      end,
    },
    {
      "neovim/nvim-lspconfig",
      opts = {
        servers = {
          lua_ls = {},
        },
      },
      config = function(_, opts)
        local lspconfig = require("lspconfig")
        for server, config in pairs(opts.servers) do
          -- passing config.capabilities to blink.cmp merges with the capabilities in your
          -- `opts[server].capabilities, if you've defined it
          config.capabilities = require("blink.cmp").get_lsp_capabilities()
          lspconfig[server].setup(config)
        end
      end,
    },
  },
})

mnpqraven avatar Apr 07 '25 18:04 mnpqraven

As far as I know, blink-cmp does not enable cmdline by default. At least, that is how it was last time I checked the documentation.

Are you asking for the defaults to be updated so that we enable cmdline completion while blink is enabled as a module?

NotAShelf avatar Apr 09 '25 10:04 NotAShelf

Yeah, i think we should because at this current state it's rather confusing to actually got it enabled, that took me a full day of trials and errors to figure out that the cmdline option needs to have its sources configured. I think at the very least cmdline.sources should be null by default instead of empty array so the autocomplete is actually loaded like blink.cmp by default

mnpqraven avatar Apr 09 '25 17:04 mnpqraven

I don't use blink myself, nor can I make a good decision on what is a sane default and what is not. let's see what @horriblename thinks about this.

NotAShelf avatar Apr 09 '25 17:04 NotAShelf

cmdline.sources the default option has this as an empty list (no source) instead of null (default source)

that definitely is a mistake, will fix

cmdline.keymap.preset the default none preset doesn't have any keys so we can't trigger the complete window.

I set the preset to "none" so that it won't interfere with our blink-cmp.mappings,

but seeing as our default is not exactly sane, perhaps we can deprecate blink-cmp.mappings and let users set the mappings themselves.

I'll just duplicate the keymap config to cmdline for now, since it's relatively harmless

horriblename avatar Apr 09 '25 21:04 horriblename