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

Go-to-definition not working for symbols defined outside of file #4402

Closed
pwaller opened this issue May 9, 2020 · 12 comments
Closed

Go-to-definition not working for symbols defined outside of file #4402

pwaller opened this issue May 9, 2020 · 12 comments
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@pwaller
Copy link

pwaller commented May 9, 2020

Hi! rust newbie here just trying things out. The first things I'm trying haven't worked and I thought you might like to know. Perhaps there is something obvious wrong with what I'm trying to do, but looking over the docs and issue tracker I can't figure it out quickly.

~/.config/Code/User/globalStorage/matklad.rust-analyzer/rust-analyzer-linux --version
rust-analyzer 6a48a94
  1. I've just installed rust-analyser 0.2.159 in vscode.
  2. I've done cargo new.
  3. In my main.rs I put the following code, which runs ok with cargo run:
use std::process::{Stdio};

fn main() -> std::io::Result<()> {
    std::process::Command::new("echo")
        .args(&["hello", "world"])
        .stdout(Stdio::inherit())
        .spawn()
        .unwrap();
    Ok(())
}

Go to definition does not work on any symbol, as far as I can tell. For example, Command, or new, Result, Ok, etc. Should I expect this to work?

Go-to-symbol works if I define and use a symbol within the file.

Completion doesn't seem to work for symbols outside the file, either.

@lnicola
Copy link
Member

lnicola commented May 10, 2020

Yes, it should work. Do you have rust-src installed?

@pwaller
Copy link
Author

pwaller commented May 10, 2020

@lnicola

$ rustup component list | grep src
rust-src (installed)

(So I guess, yes?)

@JPMoresmau
Copy link

I have the same issue (variables with type unknown, jump to definition doesn't work) for some crates but not others. How can we debug such issues? I've set RUST_LOG=info and enable server verbose trace and I see nothing in the Server Trace. (Using VS Code on windows). rust-src is installed. Sometimes restarting the server or restarting the IDE solves some issues.
My current problem is in a web assembly project, none of the web-sys symbols are resolved. Could it be that these are dependent on features? My project builds and run fine, but not having all the hints from rust-analyzer is a pain.

@JPMoresmau
Copy link

OK, after restart I see the Server Trace, and I suppose I've ran into #4150

@lnicola
Copy link
Member

lnicola commented Jan 22, 2021

@pwaller is this working for you now? We've added some messages for users with RUST_SRC_PATH set incorrectly.

@lnicola lnicola added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Jan 22, 2021
@pwaller
Copy link
Author

pwaller commented Jan 22, 2021

Since filing the issue, I have used rust-analyzer on multiple machines in this kind of configuration and not hit the problem.

I have found that whenever there is an update for rust-analyzer available, it stops working until I update. Oftentimes the notification goes missing before I notice it, resulting in the analyzer being silently broken. I also don't understand why the presence of a new version should cause the old version to stop working, but I have seen this behaviour on a large number of occasions. I mention this now because I wonder if it could be related to the bug I originally filed? I learned to watch out for updates being available and upgrade (which feels non-ideal), but in practice I don't seem to get stuck in the same way now as I did when I was first starting out and filed this issue.

@lnicola feel free to close the issue, or keep it open and keep the dialog going, if there is anything else it's useful for me to report back with on this issue.

@bjorn3
Copy link
Member

bjorn3 commented Jan 22, 2021

I also don't understand why the presence of a new version should cause the old version to stop working, but I have seen this behaviour on a large number of occasions.

This happens because the extension itself is updated automatically but the matching rust-analyzer binary is not yet downloaded. The extension is only guaranteed to work with exactly one rust-analyzer binary version which is stated inside the extension source.

@pwaller
Copy link
Author

pwaller commented Jan 22, 2021

@bjorn3 thanks for the context - that makes sense, but as a user it seems non-ideal, could the extension present me with an update button which updates both concurrently, rather than allowing the extension to break in this way when I might be relying on it?

e.g. I open my editor, the extension updates, I don't use rust and don't notice, then I get on an airplane, where I don't have internet. A workflow which worked just before I got on the airplane now doesn't work, because I got unlucky, and I'm not in a situation where I can easily fix it.

Even if the above scenario is contrived, in practice, I'm demoing rust a lot to different people at the moment, and often I have to say "oh darn, it's broken, we have to wait a few minutes while the extension updates and then I have to restart my editor and rust is great I promise! crap, I've lost them."

@bjorn3
Copy link
Member

bjorn3 commented Jan 22, 2021

could the extension present me with an update button which updates both concurrently, rather than allowing the extension to break in this way when I might be relying on it?

Vscode automatically updates the extension when there is a new version. I don't think extensions can prevent this. Only the user can by explicitly installing a specific version.

I agree that it is not ideal, but I don't think there is much we can do apart from maybe allowing the extension to use an older rust-analyzer binary and hoping that nothing breaks.

@pwaller
Copy link
Author

pwaller commented Jan 22, 2021

One suggestion which comes to mind is to have logic in the extension which grabs the latest analyzer binary in advance of when it's needed. So that when vscode updates the extension, the needed binary is already there. It's not a full fix, but would at least mean that it doesn't break for everybody every time.

@lnicola
Copy link
Member

lnicola commented Jan 23, 2021

The extension and server binary are published at the same time. I'm not sure if Code updates the extension on the fly or on restart, but we generally can't detect that a new server was published.

A workaround for you would be to disable updates for the extension (you can do that in Code) and update it manually when you remember and know you're on a stable network connection.

Maybe we could also have a toggle to disable protocol extensions; then we could still run a mismatched server.

@matklad
Copy link
Member

matklad commented May 22, 2021

Not sure what’s the root cause here is exactly, but weave recently became more forgiving of mismatched versions (by using lsp capabilities), so I thing we can clots this,

@matklad matklad closed this as completed May 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

5 participants