How can I confirm that Eclipse content assist work

2019-08-20 12:07发布

问题:

I thought I'd pick up Rust, so I installed it alongside Corrosion for Eclipse. Corrosion's description reads:

Corrosion provides a rich and smart Rust editor with: - Syntax highlighting (using TextMate grammar) and Error reporting, Hover. Content assist. Jump to references, Code Outline, Formatting... provided by the Rust Language Server

I've made sure to install RLS, and autocomplete seems to work without any problems in IntelliJ IDEA so I assume the install was successful.

The RLS setting in Eclipse is set to "Use Rustup" — not really sure what that entails. The only warning (about missing RLS) on Eclipse's settings page for Rust went away as soon as I installed RLS, so I assume it detected it.

Despite this nothing happens when pressing ^Space, which is the currently bound shortcut for content assist (e.g. after typing use std:: or similar). Since I don't know what to expect from Corrosion I don't know if there's a problem or how to troubleshoot it.

What should I expect from this Content Assist?

$ cargo --version
cargo 1.29.0 (524a578d7 2018-08-05)
$ rustc --version
rustc 1.29.2 (17a9dc751 2018-10-05)

回答1:

The proposals of the content assist come via Language Server Protocol (LSP) from Rust, Eclipse Corrosion only displays them. To be more precise, the executable rls (rust language server), which is part of a rust version, makes the proposals via LSP.

Therefore the proposals made depends on the Rust version. With Rustup you can install several versions in parallel and keep them up to date.

With the following simple code snippet you can check if Eclipse Corrision is configured correctly and LSP works:

fn main() {
    let foo = 1;
    {
        let foo = 2;
        println!("{}", foo);
    }
    println!("{}", foo);
}

If the cursor is set to the first foo, the first and the last foo, but not the two inner ones, should be highlighted (which is also implemented via LSP):



回答2:

What finally solved the underlying problem was to change the Rust Language Server Location from the default "Use Rustup" to the pre-filled values of "Other installation" and relaunching.

I don't know what the problem was though.

It turned out that the actual symbol highlighting discussed above is broken in Eclipse's dark theme (white text on white background), with no way of changing it in preferences there is an obscure setting for this (see @howlger's comment), so in the end Eclipse turned out to not be a serious contender be a real hassle. Just a warning if you, like me, has dark theme as a requirement.



标签: eclipse rust