hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.06k stars 399 forks source link

Lazyloading & Updating nvim-cmp will generate multiple completions for a single word #799

Closed glyh closed 2 years ago

glyh commented 2 years ago

FAQ

Issues

Neovim Version

NVIM v0.7.0-dev+1048-gdba1df635

Minimal reproducible config

This is based on other templates, but also will work

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
    local path_sep = on_windows and "\\" or "/"
    local result = table.concat({ ... }, path_sep)
    return result
end

vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir
if on_windows then
    temp_dir = vim.loop.os_getenv("TEMP")
else
    temp_dir = "/tmp"
end

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local function load_plugins()
    -- only add other plugins if they are necessary to reproduce the issue
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            { 'hrsh7th/nvim-cmp',
              config = function()
            local cmp = require("cmp")
            cmp.setup.cmdline(':', {
                  sources = cmp.config.sources({
                  }, {
                    { name = 'cmdline' }
                  })
                })

          end,
          event = {'InsertEnter', 'CmdlineEnter'},
            },

            { 'hrsh7th/cmp-cmdline', after = 'nvim-cmp' }

        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end

vim.cmd([[ set completeopt=menu,menuone,noselect]])

Description

Lazyloading & Updating nvim-cmp will generate multiple completions for a single word

Steps to reproduce

After all plugin installed, type : to enter command mode and type help, you'll notice multiple helps there.

Expected behavior

No redundant completion items.

Actual behavior

Redundant completion items.

Additional context

None.

hrsh7th commented 2 years ago

Sorry. I can't reproduce this. Could you reproduce with PackerCompile/PackerSync?

rgnkn commented 2 years ago

I have the same issue.

Each call of PackerSync seems to add all entries once again.

n.b.: I lazy load on event = "BufReadPost".

glyh commented 2 years ago

@hrsh7th Sorry for this very late response, I can reproduce with PackerCompile.