-
Notifications
You must be signed in to change notification settings - Fork 440
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
Integration with rust-analyzer's automatic project discovery #2755
Comments
For reference, the Buck-side implementation of this can be found here: https://github.com/facebook/buck2/tree/main/integrations/rust-project/src |
Hi, @davidbarsky I read a few of the discussions on RAtoml (including: rust-lang/rust-analyzer#17246). But I don't fully understand the concept/advantages of ra's automatic project discovery. Would you mind explaining? In what ways will it improve the Rust Bazel IDE experience? |
I think it improves the situation in two major ways:
|
Thanks for the explanation!
Does this mean it could generate based on the open buffers / crate you're currently in ? |
Yes, but you can still can still generate a |
Thanks for the pointer @davidbarsky, this looks really nice! I'd happily review a contribution if someone wanted to put one together :) |
Hi @davidbarsky, I’d like to contribute, but I’ll need some guidance. It looks like I'll need to update the existing rust-project-gen similar to the one Buck has (reference above)? mainly what buck's rust-project develop(+json) and check cmds implement? What else is needed? Does rust-analyzer provide the currently edited files? |
Sorry, I thought I replied, @otiv-emiel-vanseveren.
Yup!
|
This is great :-) The main awkwardness is relative paths: @davidbarsky I guess Buck has the same issue and forcing the paths to be relative anyway ( (My script just pokes around making all the paths absolute, which is ugly but works. We can't generate absolute paths in the first place, because the hermetic build doesn't know its location) |
As a preface, I don't really understand or know Blaze/Bazel, so I might say things that don't really make sense or aren't applicable.
Nice!
A question and a comment:
It does have the same issue, but no: we force all paths to be absolute in two steps:
This allows us to keep the core, heavy work of generating a |
This is a step towards supporting automatic project discovery (bazelbuild#2755). Relative paths are resolved against the location of rust-project.json, but in auto-discovery this is the location of the BUILD file being discovered, not the workspace root. We already use absolute paths for generated files, so rust-project.json is not workspace-independent today. The alternatives seem more complex for little gain: - Only use absolute paths for auto-discovery mode, relative otherwise. - Use ../../ to express all workspace paths relative to the BUILD. See bazelbuild#2755 (comment)
Thanks David!
Yeah, I think technically (To be honest, I live in our monorepo and don't understand multi-repo too well)
Ah, that seems easier. The existing The structure we have is very similar to yours: hermetic piece of aspect/BXL, driver glue of
As it happens I'm also trying to set up rust-analyzer based static analysis, which will use VFS, but I think we can just pick a fixed concrete layout for the VFS (e.g. |
@otiv-emiel-vanseveren are you currently working on this? It looks like there are a few separable pieces:
I'd like to contribute whatever's needed to get this working. Please let me know if there are things you have in flight! |
Hi @sam-mccall, unfortunately I did not have the time yet. Looking forward to your contributions!
I initially started working on something very similar to buck's RA cli tool, the one in rules_rust is not that nice. |
This is a step towards supporting automatic project discovery (#2755). Relative paths are resolved against the location of rust-project.json, but in auto-discovery this is the location of the BUILD file being discovered, not the workspace root. We already use absolute paths for generated files, so rust-project.json is not workspace-independent today. The alternatives seem more complex for little gain: - Only use absolute paths for auto-discovery mode, relative otherwise. - Use ../../ to express all workspace paths relative to the BUILD. See #2755 (comment)
Thankfully, it's not too hard to support multiple repos! We also technically support multiple repos, but if you know where your impure driver is being invoked from, it's generally pretty easy to normalize the paths to the correct repo root. We do this in Buck's rust-project because people might have multiple checkouts of
Cool, yeah! I'm glad we converged on the same solution!
Yeah, for Glean—code indexing—it's static analysis if you squint and we simply make it relative to the repo root. Everything is keyed off
Lemme know how that protocol feels: I'm happy to change/evolve it in response to feedback! It was very Buck-centric, so if anything feels off, let me know! |
Hi folks! I added Cargo-style automatic project discovery in rust-analyzer for non-Cargo build systems (Buck primarily, but it's designed to be usable by Bazel...) in rust-lang/rust-analyzer#17246. The documentation for this feature is in the manual, under "rust-analyzer.workspace.discoverConfig". I've been using it with Buck for the last month and a half, and while some details are still likely to change, the general shape of the API is in a spot that I'm happy with. I think this would make the Rust IDE experience with Bazel a lot nicer and I'd be very happy to provide guidance on integrating this feature into rules_rust!
The text was updated successfully, but these errors were encountered: