lifepillar/vim-mucomplete

Dict completion not working even though <c-x><c-k> does

prati0100 opened this issue · 5 comments

Hi,

I want spelling suggestions when writing emails or commit messages in vim. So, I made 'dict' the first priority in my completion chain. But it doesn't work and I never see any suggestions while typing a word.

When I press <c-x><c-k>, the completion works fine. So, something is wrong on MUcomplete's end. To investigate a bit further, I changed the following line in autoload/mucomplete.vim:

diff --git a/autoload/mucomplete.vim b/autoload/mucomplete.vim
index 3db5bdc..766e0ba 100644
--- a/autoload/mucomplete.vim
+++ b/autoload/mucomplete.vim
@@ -133,7 +133,7 @@ if has('lambda')
         \     'c-p' : s:fm(s:is_keyword),
         \     'cmd' : s:fm(s:is_keyword),
         \     'defs': s:fm(s:is_keyword),
-        \     'dict': s:fm({ t -> strlen(&l:dictionary) > 0 && (t =~# '\m\a\a$' || (g:mucomplete_with_key && t =~# '\m\a$')) }),
+        \     'dict': s:fm(s:is_keyword),
         \     'file': s:fm({ t -> t =~# '\m\%(\%(\f\&[^/\\]\)'.s:pathsep.'\|\%(^\|\s\|\f\|["'']\)'.s:pathsep.'\%(\f\&[^/\\]\)\+\)$'
         \              || (g:mucomplete_with_key && t =~# '\m\%(\~\|\%(^\|\s\|\f\|["'']\)'.s:pathsep.'\)\f*$') }),
         \     'incl': s:fm(s:is_keyword),

Dictionary completion works fine now. I'm not too well-versed in vimscript, so I'm not completely sure what's going on here, but from what I can gather, it checks for the length of the string 'dictionary'. So, I set my 'dictionary' to 'spell', and it still doesn't work. I can't make out what those other checks do.

The MUcomplete relevant config I have in my vimrc:

set completeopt+=menuone
set completeopt+=noselect
set previewheight=2
set shortmess+=c
set complete+=kspell
set dictionary+=spell
let g:mucomplete#chains = {
	\ 'tcl' : ['path', 'tags', 'c-n', 'c-p', 'incl'],
	\ 'gitcommit' : ['dict', 'file'],
	\ 'default' : ['dict']
	\ }

Is there something wrong with my config, or is this a bug in the plugin?

Thanks, I can reproduce that. The problem is that the activation condition testsl:dictionary (which is the local version of dictionary), but you are setting dictionary globally. I assumed that when you set an option globally its local version has the same value unless overridden, but apparently that's not true: the local value stays empty.

Until I fix this, a possible workaround consists in redefining the activation condition for the 'dict' method (as you have done): there is no need to modify the source code, just use g:mucomplete#can_complete. Alternatively, you may setlocal dict+=spell in each buffer where you need the spelling suggestions, instead of setting the option globally.

Just out of curiosity, why don't you just set spell and use the 'uspl' method instead (which is in the default chain btw)?

The current master should fix this. Feel free to reopen if necessary!

Thanks, I can reproduce that. The problem is that the activation condition testsl:dictionary (which is the local version of dictionary), but you are setting dictionary globally. I assumed that when you set an option globally its local version has the same value unless overridden, but apparently that's not true: the local value stays empty.

Until I fix this, a possible workaround consists in redefining the activation condition for the 'dict' method (as you have done): there is no need to modify the source code, just use g:mucomplete#can_complete. Alternatively, you may setlocal dict+=spell in each buffer where you need the spelling suggestions, instead of setting the option globally.

That does the trick. Thanks.

Just out of curiosity, why don't you just set spell and use the 'uspl' method instead (which is in the default chain btw)?

Because the suggestion quality is not very good (no offense meant).

As an example, I opened a commit message with 'uspl'. I type in "Meanwh". I expect to see "Meanwhile" as the first option. Instead I see:

  • Mean's
  • Means
  • Meant

and so on.

I do the same thing with 'dict' instead, I get:

  • Meanwhile
  • Meanwhile's

Much better!

IIUC, 'uspl' is trying too hard to correct spelling errors. So hard that it often misses suggesting the correct word. And since I don't make spelling mistakes very often, most of the suggestions end up being largely useless. All this is conjecture though, since I haven't looked at the implementation to accurately diagnose the root cause.

The current master should fix this. Feel free to reopen if necessary!

Yes, it fixes it. Thanks.

Thanks, the information you have provided may be useful to other users as well.

Because the suggestion quality is not very good (no offense meant).

MUcomplete acts as a bridge for Vim's completion algorithms, so at worst Vim is to blame ;)