Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined variable: g:LanguageClient_serverCommands #11

Open
cprn opened this issue Oct 16, 2018 · 3 comments
Open

Undefined variable: g:LanguageClient_serverCommands #11

cprn opened this issue Oct 16, 2018 · 3 comments

Comments

@cprn
Copy link

cprn commented Oct 16, 2018

Hi there,

1st of all, this wrapper is awesome and saves tons of time and this issue is really minor.

It seems the g:LanguageClient_serverCommands variable is being set too late therefore function that sets the bindings described in :help LanguageClient doesn't work and opening any buffer complains about missing variable. Calling same function after the buffer opens works fine. Can you somehow register the server commands earlier and, if not, can you recommend other general condition for detecting whether the server will run for given buffer or not?

Testing vimrc (please note the if statement):

" modeline {
" vim:set ft=vim sw=4 ts=4 sts=4 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker nowrap:
" }

" vim-plug + plugins {
    call plug#begin('~/tmp/testvim')
    Plug 'autozimu/LanguageClient-neovim',  {'branch': 'next', 'do': 'bash install.sh'}
    Plug 'roxma/LanguageServer-php-neovim', {'for': 'php', 'do': 'php ~/bin/composer install && php ~/bin/composer run-script parse-stubs'}
    call plug#end()
" }

" copied from `:help LanguageClient` {
    function LC_maps()
      if has_key(g:LanguageClient_serverCommands, &filetype)
        nnoremap <buffer> <silent> K :call LanguageClient#textDocument_hover()<cr>
        nnoremap <buffer> <silent> gd :call LanguageClient#textDocument_definition()<CR>
        nnoremap <buffer> <silent> <leader>rn :call LanguageClient#textDocument_rename()<CR>
      endif
    endfunction

    autocmd FileType * call LC_maps()
" }

Error message:

Error detected while processing function LC_maps:
line    1:
E121: Undefined variable: g:LanguageClient_serverCommands
E116: Invalid arguments for function has_key
E15: Invalid expression: has_key(g:LanguageClient_serverCommands, &filetype)
Press ENTER or type command to continue

Calling it after the buffer opens works fine:

:call LC_maps()

I'll cross post this issue on LanguageClient tracker as I'm not sure where it belongs. Maybe they can just change documentation or the way server commands register.

@roxma
Copy link
Owner

roxma commented Oct 17, 2018

You may need to add let g:LanguageClient_serverCommands = {} in your vimrc

@cprn
Copy link
Author

cprn commented Oct 17, 2018

An empty dictionary? Doesn't LanguageClient_registerServerCommands() create it? After the buffer opens same condition works perfectly fine and I'm not setting g:LanguageClient_serverCommands anywhere myself.

@roxma
Copy link
Owner

roxma commented Oct 18, 2018

Doesn't LanguageClient_registerServerCommands() create it?

It does. But the code is executed in ftplugin/php.vim, which may not be executed before autocmd FileType * call LC_maps(). Read :help ftplugin for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants