code: yeet rust-analyzer.discoverProjectCommand

This commit is contained in:
David Barsky 2023-09-05 12:02:30 -04:00
parent caeea45999
commit b1b044f2d5
5 changed files with 19 additions and 67 deletions

View file

@ -3,7 +3,7 @@ import * as lc from "vscode-languageclient";
import * as ra from "./lsp_ext";
import * as path from "path";
import { type Ctx, type Cmd, type CtxInit, discoverWorkspace } from "./ctx";
import { type Ctx, type Cmd, type CtxInit } from "./ctx";
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from "./snippets";
import { spawnSync } from "child_process";
import { type RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
@ -871,22 +871,16 @@ export function rebuildProcMacros(ctx: CtxInit): Cmd {
export function addProject(ctx: CtxInit): Cmd {
return async () => {
const discoverProjectCommand = ctx.config.discoverProjectCommand;
if (!discoverProjectCommand) {
const extensionName = ctx.config.discoverProjectRunner;
// this command shouldn't be enabled in the first place if this isn't set.
if (!extensionName) {
return;
}
const workspaces: JsonProject[] = await Promise.all(
vscode.workspace.textDocuments
.filter(isRustDocument)
.map(async (file): Promise<JsonProject> => {
return discoverWorkspace([file], discoverProjectCommand, {
cwd: path.dirname(file.uri.fsPath),
});
}),
);
const command = `${extensionName}.discoverWorkspaceCommand`;
const project = (await vscode.commands.executeCommand(command)) as JsonProject;
ctx.addToDiscoveredWorkspaces(workspaces);
ctx.addToDiscoveredWorkspaces([project]);
// this is a workaround to avoid needing writing the `rust-project.json` into
// a workspace-level VS Code-specific settings folder. We'd like to keep the