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

Doesn't work with rls (Rust Language Server) #16

Closed
vorner opened this issue Jun 25, 2017 · 10 comments
Closed

Doesn't work with rls (Rust Language Server) #16

vorner opened this issue Jun 25, 2017 · 10 comments
Assignees

Comments

@vorner
Copy link

vorner commented Jun 25, 2017

Hello

When I try to use vim-lsc with rls (rust language server), I get this error:

Error detected while processing function lsc#server#channelCallback[3]..lsc#protocol#consumeMessage[20]..lsc#dispatch#message:
line    1:
E715: Dictionary required

I think the rls is installed correctly, because it works in neovim with autozimu/LanguageClient-neovim, but I'd actually prefer to use the original vim over neovim. I don't have any other language server installed right now, so I can't check if it is broken with some other one.

How should I debug this further?

@natebosch
Copy link
Owner

Most likely RLS uses a different structure than I expected for some response. I'll see if I can get it installed and look for a repro, if I can't I'll update with some info on debugging so we can narrow it down.

@natebosch natebosch self-assigned this Jun 26, 2017
@natebosch
Copy link
Owner

Ok, I tracked down the first issue - vim-lsc uses expects no space between the : and the content length value in the headers - this is clearly a bug as the protocol specifies there should be a space. This is easy to fix and I'll get an update out soon.

I see the plugin sending the initialize, the server responding to that, then the plugin sending didOpen and didChange but it doesn't ever give me any diagnostics, not sure if its something with my setup.

I think I have a second bug here where a completion request that gets back an empty list might put us in a state where we never ask for completions again. Will dig in to that.

natebosch added a commit that referenced this issue Jun 27, 2017
Partial fix for #16

- Add a space after the `Content-Length:` header since it is what the
  spec calls for and strict servers expect this.
- Correct index for header end to not include a trailing `\r` in the
  last header.
- Check that the decoded content is a dict. In this case it was v:none
- Only call dispatch on a correctly parsed response, don't default to
  `{}`.
- Strip a leading space from the length header value.
@natebosch
Copy link
Owner

I've pushed a fix for the first issue - can you pull it down and try it out? I'll keep digging on the possible problem around completion.

@natebosch
Copy link
Owner

Fixed also the problem where it would stop requesting completions. I can now see it sending didOpen, didChange and multiple completion requests and all I ever get are empty completion suggestions. I'm assuming this is a problem with my rls setup.

If you have a correctly set up rls I'm thinking this should unblock you. Please pull down the latest and let me know how it works for you.

If you still see issues the next step is to try capture the messages being sent back and forth and see if we're missing something the server expects to get it configured properly.

I tried setting the trace option when I sent the initialization request, but if it's writing logs I don't know where they are going.
You can capture the communication manually by wrapping rls with a shell script (assuming you're on mac or linux) with something like:

#!/bin/bash
tee in.log | rls | tee out.log

Then point your vim config to run that script instead of rls directly.

@vorner
Copy link
Author

vorner commented Jun 27, 2017

Hello

It helped a lot. I still have some smallish issues, but it mostly works:

  • Can I turn on the suggestions after :: as well as .?
  • It seems rls sometimes sends multi-line definitions which look a bit un-aesthetical in the output (I'd attach a screenshot, but github doesn't seem to like that png file :-( ‒ basically, every newline is replaced by ^@).
  • Sometimes I get a „Could not decode message“ error:
[lsc] Could not decode message: {"jsonrpc":"2.0","id":16,"result":[{"uri":"file:///home/vorner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.7/src/reacto
r/mod.rs","range":{"start":{"line":104,"character":11},"end":{"line":104,"character":11}}}]}

I have logs for these, but it seems I'm unable to attach them currently (my internet connection is very broken at the moment and it times out or something). If they are needed, I'll send them over the weekend, when I get to a better connection.

I'm attaching at least the corresponding request:

{"id":16,"jsonrpc":"2.0","method":"textDocument/definition","params":{"textDocument":{"uri":"file:///home/vorner/prog/corona/src/lib.rs"},"position":{"character":16,"line":138}}}

I noticed this doesn't happen every time on the same place. If I first let it do some completion, then go-to-definition twice in a row and the second is into another file, this happens. If I just jum through definitions or just do completions, it works fine.

Regarding setting up rls, you probably need something like:

  • rustup default nightly
  • rustup component add rls
  • rustup component add rust-src
  • rustup component add rust-analysis
  • cargo install racer
  • export RUST_SRC_PATH=$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/

(I'm not sure if all this is still needed, they gradually improve the experience, but rls is still very young)

@natebosch
Copy link
Owner

natebosch commented Jun 27, 2017

Glad to hear it's working 😄

Can I turn on the suggestions after :: as well as .?

Yeah I should have done this a while ago - it doesn't currently honor the triggerCharacters suggested by the server. Filed #18 to track.

It seems rls sometimes sends multi-line definitions which look a bit un-aesthetical in the output

I'm not sure I follow. Is this during completion? A screenshot and logs would definitely help here.

Sometimes I get a „Could not decode message“ error:

Hmm, the one you pasted looks like it should have worked, except for the line break in the middle which I'm assuming is an artifact of copying it rather than being present in the original... The only reason to get that error should be if json_decode throws or if the result isn't a dict. Seeing the communication logs that end up with that message would be helpful too.

natebosch added a commit that referenced this issue Jun 27, 2017
This came up in #16 where an exception during message handling gets
swallowed and the error is about decoding.
@natebosch
Copy link
Owner

Ah, I made a mistake where lots of exceptions could show up like decoding issues. Sync past 33b6259 and hopefully we can better track down where your complete or goto definition issues are coming from.

@natebosch
Copy link
Owner

Fixed the triggerCharacters as well.

Remaining issue, I think, is "It seems rls sometimes sends multi-line definitions which look a bit un-aesthetical in the output" - If you can give some more information on this I can take a look.

@vorner
Copy link
Author

vorner commented Jun 28, 2017

Thank you, the :: works fine now. And that decode error turned out to be „No write since last change“ error.

I still can't attach to github, so I put the screenshot elsewhere: https://vorner.cz/tmp/lsc.png. As you can notice, the definitions of the functions are really multi-line in the source file, and I guess rls really sends them so (the logs agree with the theory). It's nothing serious, I just think it would look a bit nicer to either cut-off on the first newline or turn all successive whitespace (including newlines) into single space.

The logs are https://vorner.cz/tmp/log.in (vim → rls) and https://vorner.cz/tmp/log.out (rls → vim). The completion on the screenshot is id 9.

natebosch added a commit that referenced this issue Jun 28, 2017
Fixes remaining issue in #16

Some servers send multiline detail strings in completion suggestions.
Split to just the first line to avoid ugly characters and long menu.
@natebosch
Copy link
Owner

Thanks for the details - that what just what I needed.

The "No write since last change" sounds like trying to jump to a definition in another file and not having set hidden.

8278065 should fix the last remaining issue with the long lines in the completion menu - I'm truncating to the first line so you won't see anything after the first ^@

Hopefully this covers everything. If you run into further problems you can reopen this issue or file a new one.

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