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

Pass settings to server via notify #341

Closed
hurricanehrndz opened this issue Mar 23, 2018 · 21 comments
Closed

Pass settings to server via notify #341

hurricanehrndz opened this issue Mar 23, 2018 · 21 comments

Comments

@hurricanehrndz
Copy link

It seems like a lot of code has changed since the Next branch has become the defacto.

I'm trying to follow issue #139.
I have written the following function to that end:

function! LoadYamlAnsibleConfig()
        let config = json_decode(system("cat ~/.config/nvim/yaml/ansible.json"))
        call LanguageClient#Notify('workspace/didChangeConfiguration', { 'settings': config })
endfunction

Debug log has the following output which make me think it is not working:

2018-03-22T18:12:13.944742362-06:00 INFO languageclient::vim - <= {"method": "workspace/didChangeConfiguration", "jsonrpc": "2.0", "params": {"settings": {"yaml.schemas": {"https://raw.github
usercontent.com/shaded-enmity/ansible-schema-generator/master/examples/ansible.json": "/*.yml"}}}}                                                                                             
2018-03-22T18:12:13.944911658-06:00 WARN languageclient::rpchandler - Unknown notification: "workspace/didChangeConfiguration"

I'm trying to integrate the following language server.

Any guidance is welcome. Another issue from the server is that no trigger characters are returned so registration with NCM fails.

2018-03-22T18:11:30.827249189-06:00 DEBUG languageclient::languageclient - LanguageClient: failed to register as NCM source!: ErrorImpl { code: Message("missing field `triggerCharacters`"
    ), line: 0, column: 0 }

@autozimu
Copy link
Owner

You probably don't need to call the Notify function directly. See https://github.com/autozimu/LanguageClient-neovim/blob/next/doc/LanguageClient.txt#L155. You could either put language server settings into that file or override path of settings.

I will address the secondly issue shortly.

autozimu pushed a commit to gluon-lang/lsp-types that referenced this issue Mar 23, 2018
@hurricanehrndz
Copy link
Author

hurricanehrndz commented Mar 23, 2018 via email

@autozimu
Copy link
Owner

Yes, it should work.

You could add

let g:LanguageClient_loggingLevel = 'DEBUG'

in your vimrc to increase logging level.

Or follow github issue template to provide as much information as possible.

@hurricanehrndz
Copy link
Author

hurricanehrndz commented Mar 23, 2018 via email

autozimu pushed a commit that referenced this issue Mar 23, 2018
@autozimu
Copy link
Owner

I found out currently Notify() method is not working as expected. Sorry about that.

Will fix it soon.

@hurricanehrndz
Copy link
Author

hurricanehrndz commented Mar 23, 2018 via email

autozimu added a commit that referenced this issue Mar 23, 2018
autozimu added a commit that referenced this issue Mar 23, 2018
@4lex4nder
Copy link

C++ autocompletion (nvim-completion-manager) using cquery doesn't seem to work after the latest commit concerning this issue (cb57e19).

@hurricanehrndz
Copy link
Author

hurricanehrndz commented Mar 23, 2018

@autozimu,

Thank you for the update. I see the notify function is working properly. I'm still not seeing completion options from the yaml-language-server. Here is my minimal vim:

set nocompatible

syntax on
filetype plugin on
set background=dark

set runtimepath=~/.vim/min,$VIMRUNTIME,~/.vim/min/after
let &packpath = &runtimepath

" Try to load minpac (async plugin manager).
set loadplugins
silent! packadd minpac

if exists('*minpac#init')
    " minpac is available.
    call minpac#init()
    " completion manager
    call minpac#add('roxma/nvim-completion-manager')
    " Install language client
    call minpac#add('autozimu/LanguageClient-neovim', {'do': {-> system('bash install.sh')}})
endif

let g:python_host_prog = '/home/hurricanehrndz/.virtualenvs/neovim2/bin/python'
let g:python3_host_prog = '/home/hurricanehrndz/.virtualenvs/neovim3/bin/python'

let g:LanguageClient_loggingLevel = 'DEBUG'
let g:LanguageClient_serverCommands = {
    \ 'yaml': ['node', '~/.virtualenvs/neovim3/lib/node_modules/yaml-language-server/out/server/src/server.js', '--stdio'],
    \ }
let g:LanguageClient_loadSettings = 1

" function! yamllangserver#setschema(schema)
function! SetYamlLangServerSchema(schema)
        echom "Using " . a:schema . " schema"
        let config = json_decode(system("cat ~/.config/nvim/yaml/" . a:schema . ".json"))
        call LanguageClient#Notify('workspace/didChangeConfiguration', { 'settings': config })
endfunction

set shortmess+=c
" Force refresh
imap <c-g> <Plug>(cm_force_refresh)

command! PackUpdate call minpac#update()
command! PackClean call minpac#clean()
command! PackList echo join(minpac#getpackages("minpac", "start"), "\n")

After opening a Kubernetes (built-in to yaml-lang-server) file I run the following command:

call SetYamlLangServerSchema("kubernetes") 

kubernetes.json

{
    "yaml.schemas": {
        "kubernetes": "/*.yml"
    }   
}

LanguageClient.log
nvim_log_py3_cm_core.log

@autozimu
Copy link
Owner

doesn't seem to work

This is not helpful at all.

@autozimu
Copy link
Owner

@hurricanehrndz If you need help from my side, please follow github template to provide enough info (your env, reproduction steps, what expected and what happened).

@4lex4nder
Copy link

Sorry. Here are the log files on a small example.

cq.log
LanguageClient.log
LanguageServer.log

@hurricanehrndz
Copy link
Author

hurricanehrndz commented Mar 23, 2018

  • neovim/vim version
NVIM v0.2.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-_mzR4z/neovim-0.2.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG
-Wdate-time -D_FORTIFY_SOURCE=2 -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/build/neovim-_mzR4z/neovim-0.2.2/build/config -I/build/neovim-_mzR4z/neovim-0.2.2/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim-_mzR4z/neovim-0.2.2/build/src/nvim/auto -I/build/neovim-_mzR4z/neovim-0.2.2/build/include
Compiled by pkg-vim-maintainers@lists.alioth.debian.org

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

CheckHealth:

health#nvim#check                                                                                                                                                                              
========================================================================                                                                                                                       
## Configuration                                                                                                                                                                               
  - OK: no issues found                                                                                                                                                                        
                                                                                                                                                                                               
## Performance                                                                                                                                                                                 
  - OK: Build type: RelWithDebInfo                                                                                                                                                             
                                                                                                                                                                                               
## Remote Plugins                                                                                                                                                                              
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $XTERM_VERSION=''
  - INFO: $VTE_VERSION=''
  - INFO: $TERM_PROGRAM=''
  - INFO: $COLORTERM=''

## tmux
  - OK: escape-time: 10ms
  - INFO: $TERM: xterm-256color
  - INFO: default-terminal: tmux-256color
  - ERROR: $TERM differs from the tmux `default-terminal` setting. Colors might look wrong.
    - ADVICE:
      - $TERM may have been set by some rc (.bashrc, .zshrc, ...).

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: myClipboard

## Python 2 provider (optional)
  - OK: pyenv found: "/home/hurricanehrndz/.pyenv/libexec/pyenv"
  - INFO: Using: g:python_host_prog = "/home/hurricanehrndz/.virtualenvs/neovim2/bin/python"
  - INFO: Executable: /home/hurricanehrndz/.virtualenvs/neovim2/bin/python
  - INFO: Python2 version: 2.7.14
  - INFO: python-neovim version: 0.2.4
  - OK: Latest python-neovim is installed: 0.2.4

## Python 3 provider (optional)
  - OK: pyenv found: "/home/hurricanehrndz/.pyenv/libexec/pyenv"
  - INFO: Using: g:python3_host_prog = "/home/hurricanehrndz/.virtualenvs/neovim3/bin/python"
  - INFO: Executable: /home/hurricanehrndz/.virtualenvs/neovim3/bin/python
  - INFO: Python3 version: 3.6.4
  - INFO: python-neovim version: 0.2.4
  - OK: Latest python-neovim is installed: 0.2.4

## Ruby provider (optional)
  - INFO: Ruby: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
  - INFO: Host: /home/hurricanehrndz/.gem/ruby/2.5.0/bin/neovim-ruby-host
  - OK: Latest "neovim" gem is installed: 0.7.1

## Node provider (optional)
  - INFO: Node: v9.8.0
  - INFO: Host: /home/hurricanehrndz/.local/bin/neovim-node-host
  - OK: Latest "neovim" npm is installed: 3.5.2
set nocompatible

syntax on
filetype plugin on
set background=dark

set runtimepath=~/.vim/min,$VIMRUNTIME,~/.vim/min/after
let &packpath = &runtimepath

" Try to load minpac (async plugin manager).
set loadplugins
silent! packadd minpac

if exists('*minpac#init')
    " minpac is available.
    call minpac#init()
    " completion manager
    call minpac#add('roxma/nvim-completion-manager')
    " Install language client
    call minpac#add('autozimu/LanguageClient-neovim', {'do': {-> system('bash install.sh')}})
endif

let g:python_host_prog = '/home/hurricanehrndz/.virtualenvs/neovim2/bin/python'
let g:python3_host_prog = '/home/hurricanehrndz/.virtualenvs/neovim3/bin/python'

let g:LanguageClient_loggingLevel = 'DEBUG'
let g:LanguageClient_serverCommands = {
    \ 'yaml': ['node', '~/.virtualenvs/neovim3/lib/node_modules/yaml-language-server/out/server/src/server.js', '--stdio'],
    \ }
let g:LanguageClient_loadSettings = 1

" function! yamllangserver#setschema(schema)
function! SetYamlLangServerSchema(schema)
        echom "Using " . a:schema . " schema"
        let config = json_decode(system("cat ~/.config/nvim/yaml/" . a:schema . ".json"))
        call LanguageClient#Notify('workspace/didChangeConfiguration', { 'settings': config })
endfunction

set shortmess+=c
" Force refresh
imap <c-g> <Plug>(cm_force_refresh)

command! PackUpdate call minpac#update()
command! PackClean call minpac#clean()
command! PackList echo join(minpac#getpackages("minpac", "start"), "\n")
  • Language server Yaml-Language-Server
  • Reproduction steps (from clean state)
    1.Create minimal nvim env: mkdir -p ~/.vim/min
    2.Place minimal vimrc in ~/.vim/min/ named init.vim
    3.Install plugin manager minpac
mkdir -p ~/.vim/min/pack/minpac/opt
git clone https://github.com/k-takata/minpac.git ~/.vim/min/pack/minpac/opt/minpac
  1. Start nvim with minimal config VIMCONFIG="~/.vim/min" VIMDATA="~/.local/share/vmin" nvim --noplugin -u ~/.vim/min/init.vim
  2. Install plugins : PackUpdate
  3. Install a workspace json file in ~/.config/nvim/yaml/
    i.e. ansible.json
{
"yaml.schemas": {
        "https://raw.githubusercontent.com/shaded-enmity/ansible-schema-generator/master/examples/ansible.json": "/*.yml"
}
}
```
i.e. Kubernetes
{
yaml.schemas: {
    "kubernetes": "/*.yaml",
}
}

  7. Notify Language servers of schema in nvim
i.e.
```
:call SetYamlLangServerSchema("ansible") 
```
  8. Open kubernetes or ansible file 
i.e.
```
---
- name: Install docker
  y
  1. Refresh ncm
  2. Expect Completion suggestions. ("yum"). See: example in vscode.
  3. None received. Results.
  • Logs. Please see above.

@autozimu
Copy link
Owner

==> /tmp/LanguageClient.log <==
2018-03-23T12:58:58.424212-07:00 ERROR languageclient::vim - Error handling message. Message: {"jsonrpc":"2.0","id":18,"method":"custom/schema/request","params":"file:///Users/lijunfen/repo/LanguageClient-neovim/tests/data/sample-yaml/ansible.yaml"}. Error: ErrorMessage { msg: "Invalid message of id: Num(18)" }

stack backtrace:
   0:        0x108ec760e - backtrace::backtrace::trace::h58697a709aa9d1e0
   1:        0x108ec5bdc - backtrace::capture::Backtrace::new_unresolved::h5fa592668bd2ba39
   2:        0x108ec5471 - failure::backtrace::internal::InternalBacktrace::new::ha1a1fbc3a5765e50
   3:        0x108ec5634 - failure::backtrace::Backtrace::new::h81766d25b66fcd23
   4:        0x108d2fb5e - _$LT$failure..error..Error$u20$as$u20$core..convert..From$LT$F$GT$$GT$::from::h25f4446290eaabc5
   5:        0x108d3c5f7 - failure::error_message::err_msg::h8ad3ab2d6ff0ade1
   6:        0x108d853e7 - languageclient::vim::IVim::handle_message::h7c4c13a180385431
   7:        0x108d665eb - std::sys_common::backtrace::__rust_begin_short_backtrace::h4432b977b3cd0dbc
   8:        0x108d3db37 - _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h021498441bc90359
   9:        0x108d08e77 - std::panicking::try::do_call::h35361b7747ca742f
  10:        0x108f1864e - __rust_maybe_catch_panic
  11:        0x108d08daa - std::panicking::try::h3b4723c673301cc6
  12:        0x108d3dc9b - std::panic::catch_unwind::hcee835243addf1f1
  13:        0x108c84714 - _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h9b6fa256aaefe29a
  14:        0x108f0dc9b - std::sys::unix::thread::Thread::new::thread_start::hd05128bcd31cdc7d
  15:     0x7fffbf25f93a - _pthread_body
  16:     0x7fffbf25f886 - _pthread_start

This is because yaml language server added a protocol extension, custom/schema/request, which is not handled in this plugin.

@hurricanehrndz
Copy link
Author

Oh okay. I saw that in the logs and suspected as much, thank you so much for your time on this.

@hurricanehrndz
Copy link
Author

hurricanehrndz commented Mar 25, 2018

@autozimu

I have noticed with the latest release the following:

{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"buftype":"","languageId":"yaml","settings":{"yaml    .schemas":{"file:///home/hurricanehrndz/.config/nvim/yaml/schemas/ansible.json":"/*.yml"}}}}

Notice the parms have been extended and buftype and languageid are included, as per the recent changes in code.

Theses seems different than what the language server specifications state here.

Now I'm very new to the specifications so I might be completely wrong.

@autozimu
Copy link
Owner

These two parameters are consumed this plugin.

Although those two extra properties will be passed further down the language servers, it shouldn't matter much as most json deserialization will just ignore unknown fields.

@hurricanehrndz
Copy link
Author

@autozimu

I suspected as much, thank you for the clarification. I know it is not your job to breakdown the specification for me, so I really appreciate how far above and beyond you have gone.

@hurricanehrndz
Copy link
Author

version 0.0.7 of yaml-language-server works perfectly with this LanguageClient

@hurricanehrndz
Copy link
Author

I will document my process on the wiki. Thanks again.

@languitar
Copy link

@hurricanehrndz did you have any success with getting this working?

@hurricanehrndz
Copy link
Author

hurricanehrndz commented Aug 27, 2018 via email

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

4 participants