Skip to content

Crash with multiple languages in spelllang. #99

@kevincox

Description

@kevincox
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:

if g:grammarous#use_vim_spelllang
" Convert vim spelllang to languagetool spelllang
if len(split(&spelllang, '_')) == 1
let lang = split(&spelllang, '_')[0]
elseif len(split(&spelllang, '_')) == 2
let lang = split(&spelllang, '_')[0].'-'.toupper(split(&spelllang, '_')[1])
endif
else
let lang = a:0 == 1 ? g:grammarous#default_lang : a:1
endif

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions