Sourcegraph have a beta version of an lsp client, here. I've set it up and configured it, and I've got rls (https://github.com/rust-lang-nursery/rls/commit/e24fc84bfc4b3360a3d65d9adeab0f701140094d, on Nightly 6f10e2f63) running too. Predictably, it's not working yet, but it looks like:
sublime-lsp is sending data to rlsWhat are some next steps to figure out where the current incompatibilities are?
Sample request:
Action: hovering over .to_vec(), in a file at /Users/sth/dev/rust-geo/src/algorithm/simplifyvw.rs
This sends (visible from the sublime-lsp debug log in the console):
[
'Content-Length: 259',
'',
'{',
' "method": "textDocument/hover", ',
' "params": {',
' "position": {',
' "character": 23, ',
' "line": 53',
' }, ',
' "textDocument": {',
' "uri": "file:///Users/sth/dev/rust-geo/src/algorithm/simplifyvw.rs"',
' }',
' }, ',
' "jsonrpc": "2.0", ',
' "id": 27',
'}'
]
And receives the response:
{
'result': {
'range': None,
'contents': []
},
'jsonrpc': '2.0',
'id': 27
}
I've configured the User settings for Sublime-lsp as follows:
{
"clients": [
{
"binary": "rls",
"file_exts": ["rs"],
"path_additions": [
"/users/sth/dev/rls/target/release/",
"/Users/sth/.rustup/toolchains/nightly-x86_64-apple-darwin/lib"
],
"env": {
"DYLD_LIBRARY_PATH": "/Users/sth/.rustup/toolchains/nightly-x86_64-apple-darwin/lib",
"RLS_ROOT": "/users/sth/dev/rls/target/release/rls"
}
}
]
}
(I've also set up DYLD_LIBRARY_PATH and RLS_ROOT in my .bashrc)
@urschrei - great that you're digging into this.
A couple things -
Can you confirm that the test you're doing of hovering .to_vec works in VSCode with your configuration? I want to isolate that it's specific to the sublime plugin.
I'm a little confused by:
[
'Content-Length: 259',
'',
'{',
' "method": "textDocument/hover", ',
' "params": {',
' "position": {',
' "character": 23, ',
' "line": 53',
' }, ',
' "textDocument": {',
' "uri": "file:///Users/sth/dev/rust-geo/src/algorithm/simplifyvw.rs"',
' }',
' }, ',
' "jsonrpc": "2.0", ',
' "id": 27',
'}'
]
Should this be read as separate lines? Seems so, but I'm not sure how the line separator works here. I don't think we use one generally since it would (I think) be added to the character count in Content-Length: 259
Sorry, I hadn't seen your comments in https://github.com/sourcegraph/sublime-lsp/pull/12#issuecomment-284264669!
I think the separators I pasted above are inserted by the debug output in the Sublime console; if they weren't, wouldn't I be seeing errors from the RLS binary, as opposed to empty responses?
In any case:
After a Sublime restart, I can see the debug telemetry being sent and received again, and I get squiggles and errors as I type. (🎉):

Some questions (these aren't necessarily all for you. @alexsaveliev probably has some of them covered)
I'm happy to turn the results into some docs and screenshots, and then open a PR.
Awesome! I'm glad we see some signs of life. Would love to follow along with progress here
Circling back to this. I'm trying out https://github.com/tomv564/LSP with a recent rls, and everything seems to work now. Closing, but feel free to reopen if I'm missing something.
I expect we'd need to implement our custom parts of the protocol to have a complete experience here.
@nrc - seems like this bug is fixed, but we could open another for the extras you mention
They're not really extras - its required to offer the complete RLS experience. But I plan to write some docs about this and organise the issues a bit today.
After a quick test, this still looks too buggy to be usable.
If I make a typo, I'm getting an error, as I should :

But then if I fix it and save, the error doesn't go away.
@kamek-pf - I saw some of that, but it took a few seconds for the error to go away. You're seeing that sometimes the error doesn't go away at all?
From what I see, it looks like it never goes away unless you break something else.
If you simply fix the error without breaking anything else, the error stays.
@kamek-pf I played with it for a few minutes but couldn't get it to break once. That said, I don't doubt you're seeing an issue.
Just to double check, how recent is your rls?
I just installed it through rustup on my machine at work :
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rls --version
rls-preview 0.122.0-nightly (303671e 2017-08-31)
This is also going to cause problems for people who use Rust Enhanced (which is where all the Sublime Rust development is happening now), because it's not clear how to point LSP at its definitions (although that's more of an issue on their side)
it's not clear how to point LSP at its definitions
You can change the config to point to the different syntax file like this:
"clients": {
"rls": {
"command": ["rustup", "run", "nightly", "rls"],
"scopes": ["source.rust"],
"syntaxes": ["Packages/Rust Enhanced/RustEnhanced.sublime-syntax"],
"languageId": "rust"
}
However, there currently isn't a way to merge/update the existing clients dictionary (see tomv564/LSP#76), so you have to copy all clients to your custom config.
After ~3 days of use, this seems quite stable. I know there's some functionality missing, but aside from occasionally needing a server restart (which can be triggered from the command palette), it's working well enough to use as part of my setup.
So, there seems to have been a blur of activity, and encouraged, I installed the LSP plugin on my Sublime 3, and tried editing Rust code. It says "LSP initialized" in the status bar, but that disappears after a short while. Besides that, I don't notice anything to be different from the normal editing experience. There is no autocomplete. Goto definition from the menu bar causes an error "Unable to find ..." to show in the status bar. I've tried the "LPS: show diagnostics", but it just shows a separate console-like window... that doesn't print anything at all.
My RLS version, rls-preview 0.122.0-nightly (8dd7094 2017-09-12), doesn't seem to work with the LPS plugin as it is. Is there something I am missing?
@golddranks Are you using Rust Enhanced, or the bundled Sublime Text Rust plugin?
I haven't installed Rust Enhanced, but it recognizes that my code is Rust and syntax-hilights it, so I guess I'm using the bundled one...?
@golddranks And you can rustup run nightly rls --version from a console and get output?
Like I said, it's rls-preview 0.122.0-nightly (8dd7094 2017-09-12):
$ rustup run nightly rls --version
rls-preview 0.122.0-nightly (8dd7094 2017-09-12)
@golddranks Hm. The only other thing I can suggest is copying the prefs explicitly into your LSP user prefs: Here's what I'm using, adapted for the bundled Rust package: https://gist.github.com/urschrei/5f526b1a00378bfc049b23323b0002fb
Okay, I tried that. (I earlier had only the "auto_complete_triggers": [ {"selector": "source.rust", "characters": ".:"} ],) line, which was suggested by the LSP docs.
Still no effect – nothing changes. I'd like to help with debugging this, but I don't have a clue where to start. Is there a some way I can log the traffic between RLS and the editor?
@golddranks Did you install LSP from the package manager ? I couldn't get it to work this way, I had to clone the repo.
Not sure if anyone else is seeing this btw.
@kamek-pf I installed it using Sublime's package control. I'll try installing from the repo!
Tried to install it from the repo. Still no signs of life. Btw. now using rls-preview 0.122.0-nightly (7221e38 2017-09-14) and Sublime Text 3.0, Build 3143.
I checked the console; it shows, among others:
reloading plugin LSP.main
plugins loaded
LSP: Config added: rls (enabled)
(Used the user config shared by @urschrei)
Still no signs of life in the editor, though.
Trying with this simple program; creating a new project with cargo, and writing:
struct Foo {
bar: f32,
}
impl Foo {
fn hoge() -> String {
"hoge?".to_owned()
}
}
fn main() {
println!("Hello, world!");
let fuga = Foo { bar: 1.0 };
fuga
}
It recognises in the right bottom bar that the code is Rust. I think that it should be simple enough for RLS to able to provide completion? When I write a dot after fuga nothing happens. Also, when I do obvious syntax mistakes, nothing happens. Is there any way to see what gets sent to the server, if anything?
Can you confirm the Rust scope is active by going to Tools -> Developer -> Show scope name
Then, confirm the active syntax by pasting sublime.active_window().active_view().settings().get("syntax") in the Sublime Text console
Ah, okay, I managed to enable debug logging in console:
LSP: no clients found for window 5
LSP: no clients found for window 5
LSP: Couldn't determine project directory
LSP: client registered for window 5 {'rls': None}
LSP: Couldn't determine project directory
LSP: Couldn't determine project directory
Scope:
source.rust
meta.function.rust
meta.block.rust
Active syntax:
>>> sublime.active_window().active_view().settings().get("syntax")
'Packages/Rust/Rust.sublime-syntax'
sublime.active_window().folders() returns [], which is strange. The file is saved, and belongs to a normal cargo project.
@golddranks you need to ensure your project folder is part of a Sublime project (Project > Add Folder to Project...)
Okay, got some signs of life. (...so, it doesn't support single files at the moment?).
plugins loaded
LSP: Config added: rls (enabled)
LSP: no clients found for window 2
LSP: no clients found for window 2
LSP: starting in /Users/um003415/repos/hello
LSP: starting ['rustup', 'run', 'nightly', 'rls']
LSP: request 1: initialize
LSP: client registered for window 2 {'rls': <LSP.main.Client object at 0x111b104d0>}
environment variables loaded using: /bin/bash -l
LSP: got json: {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"refer
LSP: notify: initialized
LSP: notify: textDocument/didOpen
LSP: got json: {"jsonrpc":"2.0","method":"rustDocument/beginBuild","params":null}
LSP: Unhandled notification: rustDocument/beginBuild
LSP: got json: {"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid type: unit value, expected struct NoParams"},"id":null}
LSP: got error: {'message': 'invalid type: unit value, expected struct NoParams', 'code': -32602}
LSP: LSP stderr process ended.
LSP: LSP stdout process ended.
Package Control: Skipping automatic upgrade, last run at 2017-09-18 23:57:59, next run at 2017-09-19 00:57:59 or after
Next, it dies here, every time I save: (edit, or more like, the connection has died on the startup.)
LSP: notify: textDocument/didSave
LSP: client unexpectedly died: [Errno 32] Broken pipe
Still no activity in editor itself, only in the debug log.
I think we're confusing two different things :
The first one seems a bit buggy for me, the second one appears to work fine.
Also, they both seem to have trouble dealing with multiple folders (representing different projects) in the same window.
Creating different Sublime projects and switching between them using ctrl+alt+p works well though.
The issues I'm reporting in this threads are with LSP.
Hmm, I got LSP and RLS to work on my laptop at work, but on my desktop at home I get the same error @golddranks has : LSP: client unexpectedly died: [Errno 32] Broken pipe.
Not the slightest idea what's different between the 2 setups.
I tried to move my .sublime-text-3 folder to start from scratch, doesn't help.
Setting RUST_LOG=rls=trace helps a lot seeing what's going on! Let's see if we can get this working smoothly!
So, the problem seems to be that the JSON message received is structured like {"jsonrpc": "2.0", "method": "initialized", "params": null}. There is a slight problem in the message itself, in params: null; according to JSON-RPC, params should be a Structured value (Object or Array) or may be omitted, but it mustn't be Null. (If I understand correctly, Null isn't a Structured value, although JavaScript accepts it as Object... Edit: Okay, it says pretty clearly in the spec that it MUST be a Structured value, or be omitted.)
This leads it to parse the value as Some(Value::Null), which might be an unexpected state; I think the valid, or expected ones are None, Some(Value::Object) and Some(Value::Array).
Initialized is a notification, and it dispatches the message to the parse_as_notification method of RawMessage. However, there onwards it gets murky: the as_params method fails if params is None, although this should be one of the expected cases! Also, it fails to parse the case Some(Value::Null) to the zero-sized struct NoParams, which is the expected outcome.
So, the parsing logic needs a bit more robustness and fixing. Sending a PR!
Wow, great support and troubleshooting in this issue!
Some updates:
initialized sending params: null has now been fixed in master.A question:
initializationOptions (for omitInitBuild: true) and settings (for eg. rust.build_lib and rust.build_bin) (example here). Are these working for you? I'd like to document them if they are essential.Awesome !
@golddranks I compiled RLS from your branch, I can confirm it fixes it for me too.
@tomv564 Can the requirement of the workspace be relaxed some day? It would be useful to be able to use RLS even when editing some single file "ad hoc".
After implementing the fix, RLS+LSP now works for me. It shows warnings and errors, and hovering for types works. Go to symbol definition works. Code completion doesn't work for some reason, gonna look at it later.
I haven't tried per-project settings yet.
@golddranks I believe ad-hoc editing fits with the spirit of Sublime Text and LSP should support it in the future. I'll create an issue to track it now, thanks for your input!
Code completion not working was a configuration issue (and my fault, because I was skipping the explanation :P) – I sent a PR to LSP that makes the docs hopefully clearer!
Warnings, errors and code completion for fields and methods works now; for some reason, code completion with use std:: doesn't work.
For some reason, sometimes hovering brings up "No description available", and sometimes the correct types.
I'll keep investigating!
Also, when starting writing a new line, like printl, a code completion/suggestion menu flashes quickly and disappears.
The use std:: problem was because of Racer crashing – it couldn't find the RUST_SRC_PATH env var, which I thought it wouldn't need anymore! (This confused me: The Racer binary doesn't need it, it knows how to use rustup to get the path, so it works without. However, Racer as a library doesn't, so it crashes.) Sent a PR to Racer to fix this: https://github.com/racer-rust/racer/pull/799
Hooray, most of the initial bugs I stumbled upon are either fixed or waiting for merge! (I'm gonna start using Sublime as my daily Rust editor and try to find some more.)
Some instructions for using rust-enhanced: https://github.com/rust-lang/rust-enhanced#rls
And just to note that Rust Enhanced has been doing really well recently - 50k+ downloads and in the top 15 trending packages - https://github.com/rust-lang/rust-enhanced/issues/224
Triage: It looks like there are no outstanding bugs and Sublime is supported. Thanks to everyone involved! :tada: I'll close this but feel free to reopen if there's anything crucial or Sublime-specific that needs fixing.
Most helpful comment
And just to note that Rust Enhanced has been doing really well recently - 50k+ downloads and in the top 15 trending packages - https://github.com/rust-lang/rust-enhanced/issues/224