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

LSP client does not send initialized notification #2295

Closed
lnicola opened this issue Feb 14, 2019 · 23 comments
Closed

LSP client does not send initialized notification #2295

lnicola opened this issue Feb 14, 2019 · 23 comments
Labels

Comments

@lnicola
Copy link

lnicola commented Feb 14, 2019

...as of e882436.

Possibly related to #1786.

cc @dimbleby

@dimbleby
Copy link
Contributor

Possibly related to #1786.

Sounds plausible, thanks. (Though I have long since switched to a different client, for this and other reasons)

@dimbleby
Copy link
Contributor

Looks like there's a function ale#lsp#message#Initialized(), but so far as I can see it never gets called...

@w0rp
Copy link
Member

w0rp commented Feb 14, 2019

Okay, finally this makes sense. The are two messages in the protocol, one is initialize, which ALE does send, and the other is initialized, which is a separate message that is easy to confuse with the first one, which ALE doesn't currently send. Almost all servers don't follow the protocol and don't require you to send the initialized message, which is why this problem was only found with the yang-lsp server, which does follow the protocol.

I can fix this over the next few days.

@lnicola
Copy link
Author

lnicola commented Feb 14, 2019

Exactly. Found using rust-analyzer.

@w0rp
Copy link
Member

w0rp commented Feb 14, 2019

What's annoying is that this bug was hard to catch, because most servers don't follow the spec and work even if you don't send initialized.

@w0rp w0rp closed this as completed in 0d10653 Feb 15, 2019
@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Okay, I should have fixed this now. Try it out.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

I can't confirm that it works.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Cool, thank you for reporting the issue. It helped me finally figure out what was wrong.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

Umm, it still doesn't work for me, but I don't have an easy way to sniff the server-client communication to be certain.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Oh, you "can't confirm." Sorry, I read that as "I can confirm."

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Which language server are you testing this with? I can confirm that the initialized message is sent before any other messages now. If you can run ALE in Vim, use :call ch_logfile(expand('~/channel.log'), 'w') and look at the messages going back and forth.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

E117: Unknown function: ch_logfile

I've tested it with rust-analyzer:

 let g:ale_rust_rls_executable = 'ra_lsp_server'
 let g:ale_rust_rls_toolchain = ''

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

The function isn't defined in NeoVim, you'll have to test this with Vim instead.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

See this NeoVim issue where I requested that they implement something similar: neovim/neovim#9010 The only way to log channel messages at the moment in NeoVim is to compile NeoVim differently.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

I think they plan on implementing a similar function eventually.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

I could try, but it might take a while until I find time to set up Vim.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Cool, let me know how it goes.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

If you want to try that language server, use env RUST_LOG=1 RA_INTERNAL_MODE=1 and look into a log subdirectory.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

==== start log session ====
  6.260437 : Starting job: /usr/bin/zsh  -c  'ra_lsp_server'
  6.260577 on 0: Created channel
  6.263415 SEND on 0(in): 'Content-Length: 196^M
^M
{"method":"initialize","jsonrpc":"2.0","id":1,"params":{"initializationOptions":{},"rootUri":"file:///home/grayshade/hello","capabilities":{},"rootPath":"/home/grayshade/hello","processId":12501}}'
  6.265667 : looking for messages on channels
  6.279038 RECV on 0(err): 'INFO [ra_lsp_server] lifecycle: server started
'
  6.279054 on 0: Dropping message 'INFO [ra_lsp_server] lifecycle: server started
'
  6.279458 RECV on 0(err): 'INFO [gen_lsp_server] lsp server initializes
'
  6.279466 : looking for messages on channels
  6.279503 on 0: Dropping message 'INFO [gen_lsp_server] lsp server initializes
'
  6.280426 RECV on 0(out): 'Content-Length: 739^M
^M
{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"codeActionProvider":true,"codeLensProvider":{"resolveProvider":true},"completionProvider":{"triggerCharacters":[":","."]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"=","moreTriggerCharacter":["."]},"documentSymbolProvider":true,"executeCommandProvider":{"commands":["apply_code_action"]},"foldingRangeProvider":true,"hoverProvider":true,"implementationProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"signatureHelpProvider":{"triggerCharacters":["(",",",")"]},"textDocumentSync":{"change":1,"openClose":true},"workspaceSymbolProvider":true}}}'
  6.280445 : looking for messages on channels
  6.280575 on 0: Invoking channel callback <SNR>44_VimOutputCallback
  6.282211 SEND on 0(in): 'Content-Length: 40^M
^M
{"method":"initialized","jsonrpc":"2.0"}'
  6.283433 SEND on 0(in): 'Content-Length: 218^M
^M
{"method":"textDocument/didOpen","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///home/grayshade/hello/src/main.rs","version":1,"languageId":"rust","text":"fn main() {\n    println!(\"Hello, world!\");\n}\n"}}}'
  6.283661 RECV on 0(err): 'INFO [ra_lsp_server] lifecycle: terminating process with Err(ErrorMessage { msg: "expected initialized notification" }

'
  6.284513 on 0: Dropping message 'INFO [ra_lsp_server] lifecycle: terminating process with Err(ErrorMessage { msg: "expected initialized notification" }

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

That's very strange. The message is sent, and then the server says it isn't. I bet it's expecting an empty object to be sent in params.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Okay, git pull again and give that a try. Now an empty object will be sent as the params, which the spec does say is required.

@lnicola
Copy link
Author

lnicola commented Feb 15, 2019

Yeah, that works, thanks.

@w0rp
Copy link
Member

w0rp commented Feb 15, 2019

Nice! Thank you for your help with testing this.

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

No branches or pull requests

3 participants