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

Rust analyzer shows errors with loco-rs #490

Closed
assapir opened this issue Mar 8, 2024 · 9 comments
Closed

Rust analyzer shows errors with loco-rs #490

assapir opened this issue Mar 8, 2024 · 9 comments

Comments

@assapir
Copy link

assapir commented Mar 8, 2024

Description

When trying to open the loco-rs in VSCode with rust-analyzer extension, this extension fails to do its job, with the following errors:

2024-03-08T11:49:25.833538Z ERROR project_model::workspace: cyclic deps: loco_rs(Idx::<CrateData>(197)) -> loco_rs(Idx::<CrateData>(197)), alternative path: loco_rs(Idx::<CrateData>(197))
2024-03-08T11:49:26.301369Z ERROR project_model::workspace: cyclic deps: loco_rs(Idx::<CrateData>(197)) -> loco_rs(Idx::<CrateData>(197)), alternative path: loco_rs(Idx::<CrateData>(197))
2024-03-08T11:49:27.030212Z ERROR project_model::workspace: cyclic deps: loco_rs(Idx::<CrateData>(197)) -> loco_rs(Idx::<CrateData>(197)), alternative path: loco_rs(Idx::<CrateData>(197))

To Reproduce

Open the project in VSCode with rust-analyzer installed on a Linux (x64)

Expected Behavior

rust-analyzer should work and give all it's expected functionality, like "go to definitions", etc.

Environment:

rust-analyzer version details (from it's logs):

INFO [08/03/2024, 13:49:25]: /home/assaf/.vscode/extensions/rust-lang.rust-analyzer-0.3.1868-linux-x64/server/rust-analyzer --version: {
  status: 0,
  signal: null,
  output: [ null, 'rust-analyzer 0.3.1868-standalone\n', '' ],
  pid: 984450,
  stdout: 'rust-analyzer 0.3.1868-standalone\n',
  stderr: ''
}

Additional Context
Probably related to rust-lang/rust-analyzer#14167

I can help debug on my machine if needed. This doesn't happen if one is only opening an internal crate like the loco-cli

@assapir assapir changed the title Rust analyzer unable to work with loco-rs Rust analyzer shows errors with loco-rs Mar 8, 2024
@jondot
Copy link
Contributor

jondot commented Mar 8, 2024

Never had that one, I'm using pre-release usually, which only failed me once in 3-4 years.

rust-analyzer 0.4.1870-standalone (767d5d3ea 2024-03-05)

@kaplanelad are you using pre-release or release?

@assapir
Copy link
Author

assapir commented Mar 8, 2024

Never had that one, I'm using pre-release usually, which only failed me once in 3-4 years.

rust-analyzer 0.4.1870-standalone (767d5d3ea 2024-03-05)

@kaplanelad are you using pre-release or release?

I tried to switch to pre-release, still happens:

INFO [08/03/2024, 14:25:48]: /home/assaf/.vscode/extensions/rust-lang.rust-analyzer-0.4.1873-linux-x64/server/rust-analyzer --version: {
  status: 0,
  signal: null,
  output: [ null, 'rust-analyzer 0.4.1873-standalone\n', '' ],
  pid: 1033877,
  stdout: 'rust-analyzer 0.4.1873-standalone\n',
  stderr: ''
}

The errors are shown inside OUTPUT -> Rust Analyzer Language Server

@jondot
Copy link
Contributor

jondot commented Mar 8, 2024

yes, now i get it!
very strange, i just upgraded everything and it might started now (but I might have missed it earlier)
i'll try figuring this out

@assapir
Copy link
Author

assapir commented Mar 8, 2024

yes, now i get it! very strange, i just upgraded everything and it might started now (but I might have missed it earlier) i'll try figuring this out

From the attached discussion in the rust-analyzer repo and from my testing, this is the offensive line:

loco/Cargo.toml

Line 151 in c3597ab

loco-rs = { path = ".", features = ["testing"] }

@jondot
Copy link
Contributor

jondot commented Mar 8, 2024

Yep I got this as well.
And in your experience, rust-analyzer isn't working well?

@assapir
Copy link
Author

assapir commented Mar 8, 2024

Yep I got this as well. And in your experience, rust-analyzer isn't working well?

I am not sure, I thought it didn't work as expected, but it mostly does? 🤷🏻
I don't think it's urgent in any way, for sure.

@jondot
Copy link
Contributor

jondot commented Mar 8, 2024

Yea, I didn't notice anything but I can now document this like so:

  • Loco comes with optional testing kits, which are flagged under the testing feature flag
  • By default, Loco does not ship with the testing feature, in order to not include axum-test and other overhead
  • When Loco tests itself, it will "require itself to have testing kits" by including itself as a dev-dependency with a testing feature flag.

Rust analyzer has trouble dealing with Loco requiring itself (and maybe rightly so?), because it does not deal with these kind of cycles well.

Options to resolve:

  1. Include testing by default, which will obsolete "re-requiring" in Loco and in starters
  2. Extract all testing related code into a separate crate loco-testing and depend on that in dev-dependencies, then, enable relevant testing code in Loco based on a required feature flag
  3. Ignore this, as there is some indication that rust-analyzer can still function well with this error

I'd look at (3) more deeply now that we're aware of it. If rust-analyzer isn't performing well, I'm leaning towards (1), and then having users build "for production" without testing. The disadvantage here is to force users to explicitly say what their feature flags are for production.

@kaplanelad WDYT?

@jondot
Copy link
Contributor

jondot commented Mar 8, 2024

...One more option is to not add testing as default, and require devs to say cargo test --features testing all the time (maybe we can hide this pesky typing under an alias cargo loco test)

UPDATE: this issue is relevant only for Loco testing Loco. Starters work fine (as intended, requiring the testing feature from Loco)

jondot added a commit that referenced this issue Mar 8, 2024
@jondot
Copy link
Contributor

jondot commented Mar 8, 2024

I came up with a minimal, golf solution.
nice catch @assapir , looks like this started to appear this week as we added the new query DSL

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

3 participants