You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #14307 - davidbarsky:davidbarsky/add-cargo-style-project-discovery-for-buck-and-bazel-sickos, r=Veykril
Add Cargo-style project discovery for Buck and Bazel Users
This feature requires the user to add a command that generates a `rust-project.json` from a set of files. Project discovery can be invoked in two ways:
1. At extension activation time, which includes the generated `rust-project.json` as part of the linkedProjects argument in `InitializeParams`.
2. Through a new command titled "rust-analyzer: Add current file to workspace", which makes use of a new, rust-analyzer-specific LSP request that adds the workspace without erasing any existing workspaces. Note that there is no mechanism to _remove_ workspaces other than "quit the rust-analyzer server".
Few notes:
- I think that the command-running functionality _could_ merit being placed into its own extension (and expose it via extension contribution points) to provide build-system idiomatic progress reporting and status handling, but I haven't (yet) made an extension that does this nor does Buck expose this sort of functionality.
- This approach would _just work_ for Bazel. I'll try and get the tool that's responsible for Buck integration open-sourced soon.
- On the testing side of things, I've used this in around my employer's Buck-powered monorepo and it's a nice experience. That being said, I can't think of an open-source repository where this can be tested in public, so you might need to trust me on this one.
I'd love to get feedback on:
- Naming of LSP extensions/new commands. I'm not too pleased with how "rust-analyzer: Add current file to workspace" is named, in that it's creating a _new_ workspace. I think that this command being added should be gated on `rust-analyzer.discoverProjectCommand` on being set, so I can add this in sequent commits.
- My Typescript. It's not particularly good.
- Suggestions on handling folders with _both_ Cargo and non-Cargo build systems and if I make activation a bit better.
(I previously tried to add this functionality entirely within rust-analyzer-the-LSP server itself, but matklad was right—an extension side approach is much, much easier.)
Copy file name to clipboardExpand all lines: editors/code/package.json
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -199,6 +199,11 @@
199
199
"title": "Reload workspace",
200
200
"category": "rust-analyzer"
201
201
},
202
+
{
203
+
"command": "rust-analyzer.addProject",
204
+
"title": "Add current file's crate to workspace",
205
+
"category": "rust-analyzer"
206
+
},
202
207
{
203
208
"command": "rust-analyzer.reload",
204
209
"title": "Restart server",
@@ -428,6 +433,17 @@
428
433
"default": false,
429
434
"type": "boolean"
430
435
},
436
+
"rust-analyzer.discoverProjectCommand": {
437
+
"markdownDescription": "Sets the command that rust-analyzer uses to generate `rust-project.json` files. This command should only be used\n if a build system like Buck or Bazel is also in use. The command must accept files as arguments and return \n a rust-project.json over stdout.",
438
+
"default": null,
439
+
"type": [
440
+
"null",
441
+
"array"
442
+
],
443
+
"items": {
444
+
"type": "string"
445
+
}
446
+
},
431
447
"$generated-start": {},
432
448
"rust-analyzer.assist.emitMustUse": {
433
449
"markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",
0 commit comments