mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-22 11:24:24 +00:00
This commit 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 "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. I think that the command-running functionality _could_ merit being placed into its own extension (and expose it via extension contribution points), if only provide build-system idiomatic progress reporting and status handling, but I haven't (yet) made an extension that does this.
This commit is contained in:
parent
9549753352
commit
8af3d6367e
14 changed files with 258 additions and 25 deletions
|
@ -3,7 +3,7 @@ import * as lc from "vscode-languageclient";
|
|||
import * as ra from "./lsp_ext";
|
||||
import * as path from "path";
|
||||
|
||||
import { Ctx, Cmd, CtxInit } from "./ctx";
|
||||
import { Ctx, Cmd, CtxInit, discoverWorkspace } from "./ctx";
|
||||
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from "./snippets";
|
||||
import { spawnSync } from "child_process";
|
||||
import { RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
|
||||
|
@ -749,6 +749,23 @@ export function reloadWorkspace(ctx: CtxInit): Cmd {
|
|||
return async () => ctx.client.sendRequest(ra.reloadWorkspace);
|
||||
}
|
||||
|
||||
export function addProject(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
const discoverProjectCommand = ctx.config.discoverProjectCommand;
|
||||
if (!discoverProjectCommand) {
|
||||
return;
|
||||
}
|
||||
|
||||
let workspaces: JsonProject[] = await Promise.all(vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
|
||||
return discoverWorkspace(vscode.workspace.textDocuments, discoverProjectCommand, { cwd: folder.uri.fsPath });
|
||||
}));
|
||||
|
||||
await ctx.client.sendRequest(ra.addProject, {
|
||||
project: workspaces
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function showReferencesImpl(
|
||||
client: LanguageClient | undefined,
|
||||
uri: string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue