Skip to content

New files in tests/ give "This file is not included in any crates" #18279

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

Open
9999years opened this issue Oct 10, 2024 · 8 comments
Open

New files in tests/ give "This file is not included in any crates" #18279

9999years opened this issue Oct 10, 2024 · 8 comments
Labels
A-project-model project model and workspace related issues C-bug Category: bug

Comments

@9999years
Copy link
Contributor

When I open a new file in tests/ (e.g. tests/my_test.rs), rust-analyzer gives an unlinked file diagnostic:

This file is not included in any crates, so rust-analyzer can't offer IDE services.

If you're intentionally working on unowned files, you can silence this warning by adding "unlinked-file" to rust-analyzer.diagnostics.disabled in your settings. [unlinked-file]

Once I restart the rust-analyzer process, the file is loaded correctly. This may be related to #9910, but I only have this issue with files under the tests/ directory.

rust-analyzer version: rust-analyzer 2024-09-02

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: Neovim with native LSP

relevant settings: https://github.com/9999years/dotfiles/blob/205a5d1738c5520759512bf82454d04059b3b1b3/config/nvim/init.lua#L911-L949

@9999years 9999years added the C-bug Category: bug label Oct 10, 2024
@ShoyuVanilla ShoyuVanilla added the A-project-model project model and workspace related issues label Oct 10, 2024
@9999years
Copy link
Contributor Author

I'd love to help with this, but I'm not sure where to look -- grepping around for the diagnostics and the reload behavior gives me a lot to dig into, but I'm not sure of the semantics. Here, when a tests file is reloaded, it seems like the crate graph isn't reloaded. Would setting that true make this work properly? I'm not sure...

force_crate_graph_reload: false,

@ChayimFriedman2
Copy link
Contributor

Is cfg(test) turned off?

@9999years
Copy link
Contributor Author

I don't think so -- rust-analyzer works fine on my #[cfg(test)] mod tests {} test modules, and if I restart rust-analyzer it gives me intelligence for tests/foo.rs files, it just can't load them after I create them.

@ShoyuVanilla
Copy link
Member

ShoyuVanilla commented Oct 11, 2024

As each file in the tests/ is a separated binary, I think that we might lack of the logic that loading them other than startup time 🤔 I'll take a look on this

@ShoyuVanilla ShoyuVanilla self-assigned this Oct 11, 2024
@9999years
Copy link
Contributor Author

@ShoyuVanilla Thanks! I'm happy to put in some legwork if you can point me to where the files get loaded at startup time and where they should be detected while the langserver is running (handle_did_open_text_document maybe?)

@davidbarsky
Copy link
Contributor

I wish it was that simple: when it comes to project loading/discovery, parts of rust-analyzer are lazy; other parts are eager. We should make all of it lazy, I described why in #17537. I started on the laziness in 491f69a; I should probably finish it.
As for workspace loading—handle_did_open_text_document is reasonable; as is GlobalState::switch_workspaces. It's a big loop, so it can get a bit funky.

@ShoyuVanilla
Copy link
Member

I wish it was that simple: when it comes to project loading/discovery, parts of rust-analyzer are lazy; other parts are eager. We should make all of it lazy, I described why in #17537. I started on the laziness in 491f69a; I should probably finish it.
As for workspace loading—handle_did_open_text_document is reasonable; as is GlobalState::switch_workspaces. It's a big loop, so it can get a bit funky.

Oh, that's quite more complecated than I thought and related to more fundamental debt we have. @9999years I think that I should try resolving the underlying issues and revisit this once we have dealt with it. It may take some time. Sorry 😢

@ShoyuVanilla ShoyuVanilla removed their assignment Oct 13, 2024
@9999years
Copy link
Contributor Author

No worries! It's not a big issue, I can just restart the LSP. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-project-model project model and workspace related issues C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants