uga-rosa / cmp-dictionary

A dictionary completion source for nvim-cmp
MIT License
237 stars 17 forks source link

Error with text filetype when multiple dictionaries defined for ["*"] #16

Closed pfries closed 2 years ago

pfries commented 2 years ago

When I define multiple dictionaries for ["*"]

        dic = {
            ["*"] = { "/usr/share/dict/words", "/usr/share/dict/american-english"},
        },

then I get the following exception when triggering completion in a "text" filetype. Dictionary completion works for other filetypes (e.g., py, md).

Error detected while processing TextChangedI Autocommands for "*":                                                                                                                                                   
E5108: Error executing lua ...packer/start/cmp-dictionary/lua/cmp_dictionary/merge.lua:160: attempt to get length of field 'array' (a nil value)                                                                     
stack traceback:                                                                                                                                                                                                     
        ...packer/start/cmp-dictionary/lua/cmp_dictionary/merge.lua:160: in function 'merge'                                                                                                                         
        .../packer/start/cmp-dictionary/lua/cmp_dictionary/init.lua:38: in function 'get_candidate'                                                                                                                  
        .../packer/start/cmp-dictionary/lua/cmp_dictionary/init.lua:53: in function 'complete'                                                                                                                       
        .../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:290: in function 'complete'                                                                                                                      
        ...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:250: in function 'complete'                                                                                                                      
        ...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:163: in function 'callback'                                                                                                                      
        ...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:213: in function 'autoindent'                                                                                                                    
        ...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:155: in function 'on_change'                                                                                                                     
        ...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/init.lua:301: in function 'callback'                                                                                                                      
        ...ite/pack/packer/start/nvim-cmp/lua/cmp/utils/autocmd.lua:31: in function 'emit'                                                                                                                           
        [string ":lua"]:1: in main chun
uga-rosa commented 2 years ago

I've checked. It's weird... changing the dictionary I use may or may not reproduce the bug. If I stop using my own merge function and use table.sort, the performance is a little worse (I'm sure it won't bother you), but the bug doesn't seem to occur. I created a branch (remove-merge), try it.

pfries commented 2 years ago

Branch fixes the error. Not sure how important this fix is if there's a trade-off since, while testing your branch, I saw that /usr/share/dict/words is ultimately just a symlink to /usr/share/dict/american-english on my system.

I did try it again on master with /usr/share/dict/british-english as the second dictionary but still got the exception.

uga-rosa commented 2 years ago

It may be possible to solve this problem without any trade-offs. I'm a little busy in the New Year, but I'll try it when I have time.

uga-rosa commented 2 years ago

If it is not fixed, please reopen this.