Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Workspace path mismatch with Rust Analyzer #36

Open
jssblck opened this issue Aug 7, 2024 · 9 comments · May be fixed by #47
Open

Workspace path mismatch with Rust Analyzer #36

jssblck opened this issue Aug 7, 2024 · 9 comments · May be fixed by #47
Labels
bug Something isn't working

Comments

@jssblck
Copy link

jssblck commented Aug 7, 2024

Hello! Thanks for taking the time to make this library, it's great!

In #9, an issue was observed with "workspace usage". The decision was that this wasn't truly broken, which is fair, but a problem when the code interacts with Rust Analyzer.

Specifically, I have code like this:

// Workspace is at `/project`, e.g. `/project/Cargo.toml` is the workspace root.

// In `/project/server/src/api.rs`, Rust Analyzer displays an error:
#[utoipauto::utoipauto(paths = "./server/src")]
#[derive(OpenApi)]
#[openapi(
    info(
        description = include_str!("../../docs/api.md"),
    ),
    modifiers(&InfoAddon, &SecurityAddon),
)]
struct ApiDoc;

This causes Rust Analyzer to report the error "Failed to parse file: ./server/src":
error

However, the build succeeds:

; cargo clean && cargo build
     Removed 8110 files, 4.5GiB total
   Compiling proc-macro2 v1.0.86
   ...
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 25.44s

Obviously, this isn't a case where the library is broken, but I think this is a case where the library makes assumptions about how the macro is executed that aren't compatible with Rust Analyzer.

Do you have any suggestions for steps I could take to resolve this issue?

@DenuxPlays
Copy link
Collaborator

I think I have the same issue but just have not recognized it.

I use RustRover as my IDE so I do not get to see the Rust-Analyzer errors directly but I've never had code-completion/intellisense on my ApiDoc struct.

I'll have a look but my knowledge about the rust-analyzer is fairly limited.
Would be great if someone else could also take a look at it.

@DenuxPlays DenuxPlays added bug Something isn't working help wanted Extra attention is needed labels Aug 8, 2024
@jssblck
Copy link
Author

jssblck commented Aug 8, 2024

I suspect that the issue here is that Rust Analyzer executes the macro in a different directory, so making the macro normalize the path to be based on the workspace root would fix the problem.

If I get time I'll take a stab at fixing it!

@DenuxPlays
Copy link
Collaborator

I suspect that the issue here is that Rust Analyzer executes the macro in a different directory, so making the macro normalize the path to be based on the workspace root would fix the problem.

If I get time I'll take a stab at fixing it!

This would be great 👌

Let me know if you need any help.
Also if this isn't the root problem please report it back.

@ProbablyClem
Copy link
Owner

I've noticed the same issue but had no clue about how to fix it.
Thanks for your help

@ginkcode
Copy link

I don't have solution for this issue. But I think rust-analyzer diagnostics is quite annoying rather than giving any useful info.
As we always verify project via cargo check / clippy.
If you're using VSCode, can turn it off via this setting:

"rust-analyzer.diagnostics.enable": false

@DenuxPlays
Copy link
Collaborator

Idea:

Check if we can find out the project Directory (maybe Cargo envs)

CD into absolut path instead of the relative

@DenuxPlays
Copy link
Collaborator

Maybe this if they have a crate to use

https://doc.rust-lang.org/cargo/commands/cargo-locate-project.html

Would also improve workspace support

DenuxPlays added a commit that referenced this issue Jan 6, 2025
Also enhance workspace support
@DenuxPlays DenuxPlays linked a pull request Jan 6, 2025 that will close this issue
@DenuxPlays DenuxPlays removed the help wanted Extra attention is needed label Jan 6, 2025
@domenicquirl
Copy link

I suspect that the issue here is that Rust Analyzer executes the macro in a different directory, so making the macro normalize the path to be based on the workspace root would fix the problem.

Just as a note / some context: I mentioned doing this previously in #7 (comment), but didn't actually end up doing it because there was a simpler fix for the specific issue with normalizing module paths:

The fully correct thing would probably be to actually resolve the Cargo.toml responsible for the file / module to determine the crate root.

@DenuxPlays
Copy link
Collaborator

I think I did it with this pr:

#47

But I haven't tested it enough yet.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants