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

VSCode plugin only works in main.rs #4177

Closed
aecorredor opened this issue Apr 27, 2020 · 12 comments
Closed

VSCode plugin only works in main.rs #4177

aecorredor opened this issue Apr 27, 2020 · 12 comments

Comments

@aecorredor
Copy link

aecorredor commented Apr 27, 2020

I'm going through https://github.com/LukeMathWalker/build-your-own-jira-with-rust and had been previously using RLS. I just switched to rust-analyzer and the plugin is only working in the main.rs file. In any other file it doesn't work at all. The run links are in the file, but there is no auto-completion nor hints (hover or inlay).

I went through the manual and first uninstalled RLS and restarted VSCode before even installing rust-analyzer.

@lnicola
Copy link
Member

lnicola commented Apr 28, 2020

It works for me in most files:

image

image

But not in jira-wip/src/koans, because those files are not in the project structure, so rust-analyzer doesn't know about them. It looks like koans-framework fills in the initially empty path_to_enlightenment.rs with include! directives like include!("koans/00_greetings/00_greetings.rs");.

That doesn't work great because the file still lies outside of the project. Consider what happens if a file is include!d from two different places: it might have completely different meanings, and rust-analyzer won't know which context you want. It's probably a known issue, but CC @edwin0cheng.

A workaround is to replace the include! with something like

#[path = "koans/00_greetings/00_greetings.rs"]
mod greetings;

image

This doesn't seem to break the koans tool, so it still works.

@lnicola
Copy link
Member

lnicola commented Apr 28, 2020

More clearly, the issue with include! is that you can have:

//- lib.rs
mod m1 {
    struct S {
        foo: i32,
    }

    include!("fun.rs");
}

mod m2 {
    struct S {
        foo: String,
    }

    include!("fun.rs");
}

//- fun.rs
fn frob(s: S) {
    let _ = s.foo; // what type is this?
}

@lnicola
Copy link
Member

lnicola commented Apr 28, 2020

Filed LukeMathWalker/build-your-own-jira-with-rust#33.

@matklad
Copy link
Member

matklad commented Apr 28, 2020

Yeah, supporting code inside includes properly is kinda hard. That's on the radar, but is not a top priority at the moment. I am going to close this issue, as there's nothing immediatelly actionable here.

@ycjcl868
Copy link

same issue + 1

@bernd-k1337
Copy link

still the same issue

@poyrazhancilar
Copy link

Same issue goes on

@curiouscod3
Copy link

same issue here. It only works in main.rs!

@danielarcini
Copy link

I would really like it if it also worked outside of my main.rs file. Did anyone find a work around to this? been 2 years and still no fix.

@lnicola
Copy link
Member

lnicola commented Sep 23, 2022

You need to set up a proper module structure. If your code compiles, please provide an example.

@matklad
Copy link
Member

matklad commented Sep 23, 2022

Idea: we can switch ra status to red if the currently opened file is .rs unknown to ra? Would also help #13226

@ben-xshen
Copy link

ben-xshen commented Dec 13, 2023

not so difficulte i found directly declare the mod, and keep the mod name same as the filename, then u the mod can get the code intelligence again.... to tell the truth i don't know why the plugin is designed like such, or they just wanna to reduce the possibility of the no-used-declaration and tell u "hey buddy, u need to use it first or i cannot provide the support for u"?
image

image

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

9 participants