-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature Req: Add support for Rust files without Cargo.toml or valid cargo workspaces #4477
Comments
We already have an alternate way of configuring the project structure, rust-project.json. It's in fact used by some of these corporate environments (e.g. Fuchsia). I have actually been wondering if it would be possible to make rustlings emit rust-project.json files to make it work in RA, although we'd still probably need more dynamic workspace support to make it seamless. |
We support non-cargo based projects: https://rust-analyzer.github.io/manual.html#non-cargo-based-projects |
Does anyone have an example of how to make this rust-project.json work with rustlings?? I have been trying to follow along with the link that @matklad posted but I have no idea how to follow the typescript that was posted and the linked example is specifically for vscode and is pretty bare. Are there any working examples for making this work with rustlings? |
Ahhh. That's awesome. Thanks @jackos that's exactly what I was looking for |
No worries, for anyone else hitting this issue I made a crate to fix it: https://crates.io/crates/rustlings-fix Just go into
And it'll generate the file |
Is there anyway to make this dynamic? I have a |
Same boat, it took me way too long to understand that no, #!/bin/sh
for f in *.rs
do
crates="${crates}${next}{\"root_module\": \"$f\",\"edition\": \"2021\",\"deps\": []}"
next=","
done
sysroot_src="$(rustc --print sysroot)/lib/rustlib/src/rust/library"
echo "{\"sysroot_src\": \"$sysroot_src\", \"crates\": [$crates]}"|jq '' >rust-project.json |
@iMilnb it's built into rustlings now you can do: rustlings lsp |
And what about any other toy directory you'd like to have loose |
Agree with iMilnb, idk how this issue is closed at all. |
The issue is closed because rust-analzyer does in fact fully support projects without Cargo.toml. What you are asking is different: making rust-analyzer work out-of-the-box without any config for more ad-hoc projects structures. This is a hard problem, as I don't think rust-analyzer can "just" work with a bunch of But perhaps some kind of heuristic to infer a project structure would cover 80% here. If anyone wants to work on that, that probably should be a separate issue. #8955 would be the starting point for that work. |
For anyone else that ends up here while searching for solutions I want to flag that Rust Analyzer support for Cargo-Script should give good workaround. Tracking issues: Hopefully close! cargo +nightly clippy --manifest-path ./filename.rs -Zscript vs cargo +nightly -Zscript clippy --manifest-path ./filename.rs Been really great just using Cargo-Script natively for exploration, small problems, and ad-hoc scripting. |
Some people are trying the rustlings repo and the exercises are outside the src/ folder, but in a exercises/ folder. I have been using VSCode and rust-analyzer extension, and it does work under the src/ folder, but it does not on exercises/. There's another issue in github with users having this problem: lsp-mope issue
I understand that this is not straightforward because rust-analyzer cannot know which dependencies you may have for your code. But at least, a minimal amount of support would be nice.
Would it be possible to add an option (maybe disabled by default) that makes those work by assuming no dependencies? (i.e. a new blank, standard Cargo.toml and using the latest stable rust)
On the other hand, in some corporate environments, cargo is not desirable because the build systems are tightly integrated, so we could expect that some people have their own way of compiling Rust and their programs would not have a regular structure. It would be really interesting to have a way of allowing these companies to extend rust-analyzer to support their build environments.
As for myself, I had to switch back to RLS to do the rustlings exercises.
The text was updated successfully, but these errors were encountered: