Auto merge of #14535 - davidbarsky:davidbarsky/use-parent-folder-for-discovery-cwd, r=Veykril

fix: when running the "discoverProjectCommand", use the Rust file's parent directory instead of the workspace folder

This is a quick fix to allow the `discoverProjectCommand` to run successfully when the user has a workspace that does not, e.g., have a `.buckconfig` defined.

(It's also probably _more correct_ to set the `pwd` of the command to the parent of the Rust file _anyways_ rather than relying on the workspace folders, which may be entirely unrelated.)
This commit is contained in:
bors 2023-04-11 07:22:40 +00:00
commit 208a74ca50
2 changed files with 15 additions and 12 deletions

View File

@ -761,12 +761,13 @@ export function addProject(ctx: CtxInit): Cmd {
}
const workspaces: JsonProject[] = await Promise.all(
vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
const rustDocuments = vscode.workspace.textDocuments.filter(isRustDocument);
return discoverWorkspace(rustDocuments, discoverProjectCommand, {
cwd: folder.uri.fsPath,
});
})
vscode.workspace.textDocuments
.filter(isRustDocument)
.map(async (file): Promise<JsonProject> => {
return discoverWorkspace([file], discoverProjectCommand, {
cwd: path.dirname(file.uri.fsPath),
});
})
);
ctx.addToDiscoveredWorkspaces(workspaces);

View File

@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as lc from "vscode-languageclient/node";
import * as ra from "./lsp_ext";
import * as path from "path";
import { Config, prepareVSCodeConfig } from "./config";
import { createClient } from "./client";
@ -192,12 +193,13 @@ export class Ctx {
const discoverProjectCommand = this.config.discoverProjectCommand;
if (discoverProjectCommand) {
const workspaces: JsonProject[] = await Promise.all(
vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
const rustDocuments = vscode.workspace.textDocuments.filter(isRustDocument);
return discoverWorkspace(rustDocuments, discoverProjectCommand, {
cwd: folder.uri.fsPath,
});
})
vscode.workspace.textDocuments
.filter(isRustDocument)
.map(async (file): Promise<JsonProject> => {
return discoverWorkspace([file], discoverProjectCommand, {
cwd: path.dirname(file.uri.fsPath),
});
})
);
this.addToDiscoveredWorkspaces(workspaces);