rhysd / vim-grammarous

A powerful grammar checker for Vim using LanguageTool.
1.1k stars 41 forks source link

Crash with multiple languages in `spelllang`. #99

Open kevincox opened 3 years ago

kevincox commented 3 years ago
Error detected while processing function grammarous#check_current_buffer[23]..<SNR>81_invoke_check:       
line   39:
E121: Undefined variable: lang
E116: Invalid arguments for function printf
E15: Invalid expression: printf(   '-c %s -l %s --api %s',   &fileencoding ? &fileencoding : &encoding,   lang,   s
ubstitute(tmpfile, '\\\s\@!', '\\\\', 'g') )
line   48:
E121: Undefined variable: cmdargs
E15: Invalid expression: '-d ' . join(disabled_rules, ',') . ' ' . cmdargs
line   67:
E121: Undefined variable: cmdargs
E116: Invalid arguments for function printf
E15: Invalid expression: printf('%s %s', g:grammarous#languagetool_cmd, cmdargs)
line   86:
E121: Undefined variable: cmd
E116: Invalid arguments for function jobstart
E15: Invalid expression: jobstart(cmd, opts)
line   87:
E121: Undefined variable: job

This appears to occur because there is a path through the function where lang does not get defined:

https://github.com/rhysd/vim-grammarous/blob/db46357465ce587d5325e816235b5e92415f8c05/autoload/grammarous.vim#L275-L284

It appears that there should be a fallback for =0 (use default_lang?) and >2 segments (raise an error?).

This problem seems to be occurring because I have multiple languages listed in my spelllang which is allowed.

:echo &spelllang
en_ca,en_us,en
:echo split(&spelllang, '_')
['en', 'ca,en', 'en']

I think the best solution is to only consider the first element of spelllang.