uga-rosa / cmp-dictionary

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

Russian spelllang dictionary #31

Closed 0rtz closed 1 year ago

0rtz commented 1 year ago

Hello, thank you for the plugin. Can you please hint me on how to set up suggestions from russian dictionary? I have the following init.vim:

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

call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'uga-rosa/cmp-dictionary'
call plug#end()

if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
    echom 'Some modules are missing, running :PlugInstall'
    PlugInstall --sync
endif

lua <<EOF

local cmp = require('cmp')

require("cmp_dictionary").setup({
    dic = {
        spelllang = {
            en = "/path/to/en.dict",
            ru = "/path/to/ru.dict",
        },
    },
})

cmp.setup{
  mapping = {
        ["<C-j>"] = cmp.mapping(function(fallback)
            if cmp.visible() then
                cmp.select_next_item()
            end
        end, { "i", "s" }),
        ["<C-k>"] = cmp.mapping(function(fallback)
            if cmp.visible() then
                cmp.select_prev_item()
            end
        end, { "i", "s" }),
        ['<C-l>'] = cmp.mapping({
            i = cmp.mapping.confirm({ select = false }),
        }),
    },

    sources = {
        {
            name = "dictionary",
            keyword_length = 2,
        },
    }
}

EOF

set keymap=russian-jcuken
set spelllang=ru

But I do not get any completions as I type in russian: image Executing CmpDictionaryUpdate after entering buffer also does not help.

While english seems to work fine: image

I use aspell-en and aspell-ru packages on archlinux and the following command to get dictionaries:

aspell -d en dump master | aspell -l en expand > en.dict
aspell -d ru dump master | aspell -l ru expand > ru.dict 
uga-rosa commented 1 year ago

I think the problem is related to multibyte characters. Please wait while I investigate.

uga-rosa commented 1 year ago

Fixed in 94cadf96140dca39920a7115c3b86f1312b361ab. Please update the latest version and test it.

0rtz commented 1 year ago

Yeah, I see it works now, thank you. Tho, completion is really slow, can I speed up it somehow? I see that russian dictionary in aspell after expansion is really huge, is it possible to truncate it? Peek 2022-08-27 13-35

uga-rosa commented 1 year ago

The candidate acquisition itself is done by bisection search, so I don't think it will be that slow. I think that a large number of candidates are passed to the main body of cmp, and the subsequent sorting and display process may be taking time. I will try to create a mechanism to limit the number of candidates returned to the main body.

uga-rosa commented 1 year ago

Can you try #32?

0rtz commented 1 year ago

Well, it doesn't lag, but results of completion seems odd

uga-rosa commented 1 year ago

That's right. If we return all the candidates, it would be too laggy, so to avoid that, we reduce the number of candidates to be returned. You can increase the number of max_items in setup, and/or increase the number of exact, or set it to -1 (the candidates returned by this plugin to the main body are those looked for by prefix exact match for the number of exact only, and fuzzy match is the job of the main body).

require("cmp_dictionary").setup({
    --- other settings
    max_items = 1000, -- Default: 100
    exact = -1, -- Prefix exact match
})
uga-rosa commented 1 year ago

Please try and let me know how much these should be set to just the right numbers, as I would like to determine the appropriate default settings. Is it less at 100?

uga-rosa commented 1 year ago

PR for max_items has been merged. The default value is set to -1 (unlimited). Please make good use of options max_items and exact.

0rtz commented 1 year ago

Thank you

max_items = 2000,
exact = -1,

works decent for Russian language