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

Gnome Builder support #3758

Closed
lnicola opened this issue Mar 28, 2020 · 15 comments · Fixed by #4236
Closed

Gnome Builder support #3758

lnicola opened this issue Mar 28, 2020 · 15 comments · Fixed by #4236
Labels
E-has-instructions Issue has some instructions and pointers to code to get started fun A technically challenging issue with high impact good first issue

Comments

@lnicola
Copy link
Member

lnicola commented Mar 28, 2020

It seems that Gnome Builder supports LSP, but doesn't allow users to configure the path to the server. Replacing rls with rust-analyzer in /usr/lib/gnome-builder/plugins/rls_plugin.py should work, but after doing that I ran into a snag.

rust-analyzer starts, but uses the wrong project directory and doesn't work very well. It's worth looking into this as it would improve compatibility with at least one editor. One way to debug it would be to trace the LSP communication and compare Gnome Builder with Code.

@lnicola lnicola added E-has-instructions Issue has some instructions and pointers to code to get started fun A technically challenging issue with high impact good first issue labels Mar 28, 2020
@lnicola
Copy link
Member Author

lnicola commented Mar 28, 2020

More details: unsurprisingly, I had to open the project folder, not a source code file. That takes care of the wrong root directory. Then:

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///home/user/Projects/hello/src/main.rs","version":20},"contentChanges":[{"range":{"start":{"line":2,"character":5},"end":{"line":2,"character":5}},"rangeLength":0,"text":"."}]}}
{"method":"textDocument/completion","jsonrpc":"2.0","id":30,"params":{"textDocument":{"uri":"file:///home/user/Projects/hello/src/main.rs"},"position":{"line":2,"character":6},"context":{"triggerKind":2}}}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 2', /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libcore/slice/mod.rs:2842:10
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.45/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.45/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1427
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: rust_begin_unwind
             at src/libstd/panicking.rs:419
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  13: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:69
  14: <usize as core::slice::SliceIndex<[T]>>::index
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libcore/slice/mod.rs:2842
  15: core::slice::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libcore/slice/mod.rs:2707
  16: <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/liballoc/vec.rs:1891
  17: ra_ide_db::line_index::LineIndex::offset
             at crates/ra_ide_db/src/line_index.rs:88
  18: <lsp_types::Position as rust_analyzer::conv::ConvWith<&ra_ide_db::line_index::LineIndex>>::conv_with
             at crates/rust-analyzer/src/conv.rs:184
  19: <&lsp_types::TextDocumentPositionParams as rust_analyzer::conv::TryConvWith<&rust_analyzer::world::WorldSnapshot>>::try_conv_with
             at crates/rust-analyzer/src/conv.rs:440
  20: rust_analyzer::main_loop::handlers::handle_completion
             at crates/rust-analyzer/src/main_loop/handlers.rs:405

The source code is:

fn main() {
    let s = "hello".to_owned();
    s.<|>
    println!("{}", s);
}

@kjeremy
Copy link
Contributor

kjeremy commented Mar 28, 2020

I can't reproduce this in vscode. In fact in vscode it always seems to send down the entire file in textDocument/didChange. I wonder if that plays into it.

@lnicola
Copy link
Member Author

lnicola commented Mar 28, 2020

With Code:

{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///home/user/Projects/hello/src/main.rs","version":3},"contentChanges":[{"text":"fn main() {\n    let s = \"hello\".to_owned();\n    s.\n    println!(\"{}\", s);\n}\n"}]}}
{"jsonrpc":"2.0","id":14,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///home/user/Projects/hello/src/main.rs"},"position":{"line":2,"character":6},"context":{"triggerKind":2,"triggerCharacter":"."}}}

@kjeremy
Copy link
Contributor

kjeremy commented Mar 28, 2020

It doesn't look like the gnome builder lsp client is respecting our text synchronization choice of "full" (see caprs.rs) https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_synchronization

@lnicola
Copy link
Member Author

lnicola commented Mar 28, 2020

My guess is that rust-analyzer takes the file contents from the request, so when Builder sends only a partial change we index into the change instead of the full file. Part of the problem is that Builder doesn't support full synchronization.

@gwutz
Copy link
Contributor

gwutz commented Apr 24, 2020

Hey all. I will help here. Actually i implement the necessary client functionality to react to the server capabilities and send the full buffer instead just the incremental changes.
But i have still another problem:

21:45:01.9212 jsonrpc-input-stream[    2]:  MESSAGE: <<< {"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/randomDude/Projects/git-project/Cargo.toml: Failed to run `cargo metadata --manifest-path /home/randomDude/Projects/git-project/Cargo.toml`: No such file or directory (os error 2): No such file or directory (os error 2)","type":1}}

Do i have to set some specific environment variables to be able to use rust-analyzer correctly? This file exists of course.

@lnicola
Copy link
Member Author

lnicola commented Apr 24, 2020

It sounds like cargo is not on your PATH. That's common with DEs, since it's added the by .bash_profile and that's not sourced if you run the editor from the DE. Try running it from a terminal.

@gwutz
Copy link
Contributor

gwutz commented Apr 24, 2020

Got it. Seems to work at least without specific errors. Completion is still not valid - will investigate whats the problem here. Thank you @lnicola

@lnicola
Copy link
Member Author

lnicola commented Apr 26, 2020

@gwutz it works fine for me 😛:

image

@gwutz
Copy link
Contributor

gwutz commented Apr 26, 2020

Did you implemented the full text synchronization? I got it already to work too. Right now i make my PoC product ready here: https://gitlab.gnome.org/GNOME/gnome-builder/-/merge_requests/268

@lnicola
Copy link
Member Author

lnicola commented Apr 26, 2020

No, I added incremental synchronization support in #4153.

@gwutz
Copy link
Contributor

gwutz commented Apr 26, 2020

Ha, this super awesome. What will be the default for the future? Full or incremental? I still will finish this plugin (as there is no implementation for analyzer nevertheless) and maybe i can drive some specific language server client things (messages, installation automatic etc.)
Just want to make sure that gnome-builder is a viable alternative for rust as IDE

@lnicola
Copy link
Member Author

lnicola commented Apr 26, 2020

I hope we'll default to incremental, but my PR wasn't even reviewed yet, so don't take it for granted.

@kjeremy
Copy link
Contributor

kjeremy commented Apr 27, 2020

@lnicola FYI I'm not sure if you've worked on Gnome Builder but it should support all three modes: see microsoft/language-server-protocol#967 (comment)

@gwutz
Copy link
Contributor

gwutz commented Apr 27, 2020

@kjeremy yes but this is not the case right now

@bors bors bot closed this as completed in d79a699 May 1, 2020
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Sep 25, 2024
Add `miri_start` support

This PR uses a function with the exported symbol `miri_start` as a drop-in alternative to `#[start]`. So the signature stays the same as suggested in [this comment](rust-lang/miri#3498 (comment)). <del>I’ve also removed Miri’s restriction  to only work on bin crates as I don’t think this is necessary anymore.</del>

Closes rust-lang#3758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-has-instructions Issue has some instructions and pointers to code to get started fun A technically challenging issue with high impact good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants