uga-rosa / cmp-dictionary

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

source loaded but no completion #42

Closed madsonic closed 1 year ago

madsonic commented 1 year ago

source is loaded but I am not getting any completion from cmp-dictionary. I am aware of the v2 changes and am not using any .setup()

This is my only reference to cmp-dictionary in my config file.

# cmp.lua
cmp.setup {
  sources = {
    { name = "dictionary" },
    ...
  },
  ...
}

:CmpStatus
# ready source names
- dictionary
- ...
uga-rosa commented 1 year ago

Do you have 'dictionary' set? You can specify the dictionaries you want to always use as global value, and the ones you want to use only under certain conditions as buffer-local (switcher is useful). See help for details; :h cmp-dictionary and :h cmp-dictionary-utilities-switcher.

Example:

vim.opt_global.dictionary = "/path/to/en.dict"

local dict = require("cmp_dictionary")
dict.switcher({
  filetype = {
    lua = "/path/to/lua.dict",
    javascript = { "/path/to/js.dict", "/path/to/js2.dict" },
  },
})
madsonic commented 1 year ago

Thanks for your response. setting the dictionary opt didnt seem to do anything for me. using the switcher did fix the problem but ideally I won't want to set the dictionary for each file type.

madsonic commented 1 year ago

hmm seems like should_update() was not called. i had to manually call CmpDictionaryUpdate along with setting vim.opt_global.dictionary and everything started working.

madsonic commented 1 year ago

without the switcher, i get no debug logs

but with this switcher config, i get the following logs

require('cmp_dictionary').switcher {
  filetype = {
    ["*"] = "/usr/share/dict/words",
  }
}

[cmp-dictionary] Dictionaries for the current buffer:^I{}
[cmp-dictionary] check to need to load >>>
[cmp-dictionary] <<<
[cmp-dictionary] Dictionaries for the current buffer:^I{}
[cmp-dictionary] check to need to load >>>
[cmp-dictionary] <<<
[cmp-dictionary] Dictionaries for the current buffer:^I{ "/usr/share/dict/words" }
[cmp-dictionary] check to need to load >>>
[cmp-dictionary] This file needs to be loaded: /usr/share/dict/words
[cmp-dictionary] <<<
[cmp-dictionary] `/usr/share/dict/words` are loaded
[cmp-dictionary] Run synchronously
[cmp-dictionary] Create cache: ^I/usr/share/dict/words
[cmp-dictionary] All Dictionaries are loaded.
uga-rosa commented 1 year ago

Please update. Is it fixed?

Joarell commented 1 year ago

Hi! I try to run the command CmpDictinaryUpdate, and I've got this error:

Error executing Lua callback: .../packer/start/cmp-dictionary/lua/cmp_dictionary/util.lua:40: handle 0x55fac3b41390 is already closing stack traceback: [C]: in function 'close' .../packer/start/cmp-dictionary/lua/cmp_dictionary/util.lua:40: in function 'debounce' ...acker/start/cmp-dictionary/lua/cmp_dictionary/caches.lua:135: in function 'update' .../packer/start/cmp-dictionary/lua/cmp_dictionary/init.lua:8: in function <.../packer/start/cmp-dictionary/lua/cmp_dictionary/init.lua:7>

Here is my config:

dict.setup({
    spelllang = {
        ["*"] = "~/dotfiles/en.dict",
    },
    exact = 3,
    first_case_insensitive = false,
    document = false,
    document_command = "wn %s -over",
    async = false,
    max_items = -1,
    capacity = 5,
    debug = false,
})

Could anyone give me some light to sort this issue? Thank you in advance!

uga-rosa commented 1 year ago

@Joarell Sorry, it's bug. I fixed. Also, your config is wrong. The dictionary specification has now been separated from setup. Please check the latest version of the doc.

Joarell commented 1 year ago

Thank you a lot for your prompt reply! Now I can run CmpDictinaryUpdate, perfectly. But... when I start neovim I got this warning:

Error executing vim.schedule lua callback: .../packer/start/cmp-dictionary/lua/cmp_dictionary/util.lua:48: attempt to index upvalue 'timer' (a nil value) stack traceback: .../packer/start/cmp-dictionary/lua/cmp_dictionary/util.lua:48: in function '' vim/_editor.lua: in function <vim/_editor.lua:0>

dict.setup({
    exact = 3,
    first_case_insensitive = false,
    document = false,
    document_command = "wn %s -over",
    async = false,
    max_items = -1,
    capacity = 5,
    debug = false,
})
dict.switcher({
    spelllang = {
        en = "~/dotfiles/en.dict",
    },
    filepath = {
        ["*"] = "~/dotfiles/en.dict",
    },
})

Now it's working perfectly! Thank you for this great plugin! Even with the warning when I start neovim, it's working with no problems.

uga-rosa commented 1 year ago

@Joarell You cannot use * for spelllang. If you have a dictionary that you want to always use, set values to a global 'dictionary'.

vim.opt_global.dictionary = "/path/to/en.dict"

And I could not reproduce that error on my end. Please start a new issue and let me know the detailed minimum configuration.

madsonic commented 1 year ago

Please update. Is it fixed?

I would say it's not fixed for me but it's working by setting filetype as a workaround.

My impression from reading the docs and your suggestion is that the plugin should work just by setting vim.opt_global.dictionary but that is not the case for me.

uga-rosa commented 1 year ago

If you can give me as small an init.lua as possible that can reproduce the problem and the steps to reproduce it, I may be able to solve it.

madsonic commented 1 year ago

My minimal config. My plugin installation is done via nix darwin home-manager which I assume is not common and irrelevant so it is omitted

local cmp = require('cmp')
vim.opt_global.dictionary = "/usr/share/dict/words"

cmp.setup({
  sources = {
    { name = "dictionary" },
  },
})

With this config, :CmpStatus shows that Dictionary is correctly loaded but I do not get any completion.

# ready source names
- dictionary

If I then explicitly call :CmpDictionaryUpdate, Dictionary completion starts showing.

Let me know if you need other info. Thanks!

uga-rosa commented 1 year ago

Unfortunately, I tried that setting and could not reproduce it. Could you try the following init.vim to see if you can reproduce it? If you use prerelease version, place this file as ~/.config/minimal/init.vim and strart with NVIM_APPNAME=minimal nvim.

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/autoload/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'uga-rosa/cmp-dictionary'
call plug#end()
PlugInstall | quit

lua <<EOF
local cmp = require('cmp')
vim.opt_global.dictionary = "/usr/share/dict/words"

cmp.setup({
  sources = {
    { name = "dictionary" },
  },
})
EOF
uga-rosa commented 1 year ago

@madsonic Since I haven't received any replies, it's time to close this issue. you can reopen it.