ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.38k stars 151 forks source link

Bug: nvim-cmp auto-loading breaks blink.cmp #1522

Closed OmegaLambda1998 closed 2 weeks ago

OmegaLambda1998 commented 2 weeks ago

RTFM Checklist

Operating system

Linux

Shell

zsh

Neovim version (nvim --version)

NVIM v0.10.2 --- Build type: RelWithDebInfo --- LuaJIT 2.1.1727870382

Fzf version (fzf --version)

0.55.0 (fc693080)

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

Fzf-lua configuration

local M = {"ibhagwan/fzf-lua"}

local u = require("OL.utils")

--- catppuccin integration
M.cs_integration = {name = "fzf", opts = {enabled = true}}

M.cmd = {"FzfLua"}

M.opts = {}
M.dependencies = {"nvim-lua/plenary.nvim"}

M.opts.fzf_colors = true
M.opts.fzf_opts = {["--no-scrollbar"] = true}

M.opts.defaults = {formatter = "path.filename_first"}

M.opts.winopts = {
    width = 0.9,
    height = 0.9,
    row = 0.5,
    col = 0.5,
    preview = {scrollchars = {"┃", ""}}
}

M.opts.ui_select = function(fzf_opts, items)
    return vim.tbl_deep_extend("force", fzf_opts, {
        prompt = " ",
        winopts = {
            title = " " ..
                vim.trim((fzf_opts.prompt or "Select"):gsub("%s*:%s*$", "")) ..
                " ",
            title_pos = "center"
        }
    }, fzf_opts.kind == "codeaction" and {
        winopts = {
            layout = "vertical",
            -- height is number of items minus 15 lines for the preview, with a max of 80% screen height
            height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) +
                                    0.5) + 16,
            width = 0.5,
            preview = not vim.tbl_isempty(
                vim.lsp.get_clients({bufnr = 0, name = "vtsls"})) and
                {
                    layout = "vertical",
                    vertical = "down:15,border-top",
                    hidden = "hidden"
                } or {layout = "vertical", vertical = "down:15,border-top"}
        }
    } or {
        winopts = {
            width = 0.5,
            -- height is number of items, with a max of 80% screen height
            height = math.floor(math.min(vim.o.lines * 0.8, #items + 2) + 0.5)
        }
    })
end

function M.config(_, opts)
    local fzf = require("fzf-lua")

    fzf.setup(opts)
    vim.ui.select = function(...)
        fzf.register_ui_select(opts.ui_select or nil)
        return vim.ui.select(...)
    end
end

return M

Describe the bug / steps to reproduce

When fzf-lua cmdline completion is attempted before loading blink, everything is fine. The first time cmdline completion is attempted after loading blink, I get the following error:

Error executing vim.schedule lua callback: Vim:E5108: Error executing Lua function: ...a/.local/share/nvim/lazy/fzf-lua/lua/f
zf-lua/cmp_src.lua:68: module 'cmp.config' not found:
        no field package.preload['cmp.config']
...
stack traceback:
        [C]: in function 'require'
        .../.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/cmp_src.lua:68: in function '_register_cmdline'
        .../.local/share/nvim/lazy/fzf-lua/plugin/fzf-lua.lua:19: in function <.../.local/share/nvim/lazy/fzf-lua
/plugin/fzf-lua.lua:16>

Note that I use the blink.compat plugin to (experimentally) allow nvim-cmp sources to be used with blink, which I believe is why the local ok, cmp = pcall(require, "cmp") check passes but local cmdline_cfg = require("cmp.config").cmdline fails.

Every cmdline completion after the first doesn't error, nor are there any issues with blink or fzf-lua following the first attempt. I think just having a pcall around the cmdline_cfg is gonna be a quick fix until blink officially adds cmdline completion functionality.

ibhagwan commented 2 weeks ago

Note that I use the blink.compat plugin to (experimentally) allow nvim-cmp sources to be used with blink

That’s probably the issue, the compact mode doesn’t include cmp.config.

ibhagwan commented 2 weeks ago

https://github.com/ibhagwan/fzf-lua/commit/9503aff787bfb278ab7b067a426187f97babc209, should fix this issue.

OmegaLambda1998 commented 2 weeks ago

Yup, that worked, well done!