uga-rosa / cmp-dictionary

A dictionary completion source for nvim-cmp
MIT License
250 stars 16 forks source link

can't work with packer lazyload #14

Closed fcying closed 2 years ago

fcying commented 2 years ago

If i not use lazyload in packer, cmp-dictionary work fine. after I open lazyload local lazyload = 1, cmp-dictionary can't work. I saw cmp-dictionary config is load. print('config dict')

test init.lua

local fn, cmd = vim.fn, vim.cmd
local root_dir = fn.fnamemodify(fn.resolve(fn.expand('<sfile>:p')), ':h')

cmd('set packpath=' .. root_dir .. '/plugged')
cmd('set runtimepath^=' .. root_dir .. '/plugged')
local install_path = root_dir .. '/plugged/pack/packer/opt/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
    Bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
end

cmd([[
    set mouse=n
    packadd packer.nvim
    nnoremap <space>pu :PackerSync<CR>
    nnoremap <space>pi :PackerInstall<CR>
    nnoremap <space>pr :PackerClean<CR>
    nnoremap <space>pc :PackerCompile<CR>
]])

function Cmp()
    local cmp = require('cmp')
    cmp.setup({
        sources = cmp.config.sources({
            { name = 'path' },
            { name = 'dictionary' },
        }),
    })
end

function Dict()
    print('config dict')
    require("cmp_dictionary").setup({
        dic = {
            ['*'] = {root_dir .. '/dictionary'},
        },
        exact = 2,
        async = false,
        capacity = 5,
        debug = false,
    })
end

local packer = require('packer')
local use = packer.use

local lazyload = 1

packer.init({
    package_root = root_dir .. '/plugged/pack',
    compile_path  = root_dir .. '/plugged/plugin/packer_compiled.lua',
    plugin_package = 'packer',
    auto_clean = false,
})

use({'wbthomason/packer.nvim', opt = true})

if lazyload == 1 then
    use {'hrsh7th/nvim-cmp', event='InsertEnter', config='Cmp()'}
    use {'hrsh7th/cmp-path', after='nvim-cmp'}
    use {'uga-rosa/cmp-dictionary', after='nvim-cmp', config='Dict()'}
else
    use {'hrsh7th/nvim-cmp'}
    use {'hrsh7th/cmp-path'}
    use {'uga-rosa/cmp-dictionary'}
end

if Bootstrap then
    packer.sync()
end

if lazyload == 0 then
    Cmp()
    Dict()
end

test dictionary

Release
Debug
uga-rosa commented 2 years ago

Hmm. I see that the first update is not called. I wonder why. If you move it to another buffer and fire BufEnter, it will work.

uga-rosa commented 2 years ago

Please update to the latest version. It should be fixed now.

fcying commented 2 years ago

It can work now, thanks~