diff options
| author | bors <bors@rust-lang.org> | 2023-03-14 17:48:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-14 17:48:49 +0000 |
| commit | c15335c8b02dbc0ccc04f04c56d6471120db1bd2 (patch) | |
| tree | ca0ee8481be7701dc4878b1e7da100ab53a48de8 /editors/code/src/client.ts | |
| parent | ad91622d115a9501277c6902ecbdfd70d882bfef (diff) | |
| parent | 6e7bc07cdf225aea811f793c2f712f25846b8d20 (diff) | |
| download | rust-c15335c8b02dbc0ccc04f04c56d6471120db1bd2.tar.gz rust-c15335c8b02dbc0ccc04f04c56d6471120db1bd2.zip | |
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.)
Diffstat (limited to 'editors/code/src/client.ts')
| -rw-r--r-- | editors/code/src/client.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 62980ca0464..565cb9c6432 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -6,7 +6,7 @@ import * as Is from "vscode-languageclient/lib/common/utils/is"; import { assert } from "./util"; import * as diagnostics from "./diagnostics"; import { WorkspaceEdit } from "vscode"; -import { Config, substituteVSCodeVariables } from "./config"; +import { Config, prepareVSCodeConfig } from "./config"; import { randomUUID } from "crypto"; export interface Env { @@ -95,7 +95,16 @@ export async function createClient( const resp = await next(params, token); if (resp && Array.isArray(resp)) { return resp.map((val) => { - return substituteVSCodeVariables(val); + return prepareVSCodeConfig(val, (key, cfg) => { + // we only want to set discovered workspaces on the right key + // and if a workspace has been discovered. + if ( + key === "linkedProjects" && + config.discoveredWorkspaces.length > 0 + ) { + cfg[key] = config.discoveredWorkspaces; + } + }); }); } else { return resp; |
