Skip to content

Commit 208a74c

Browse files
committed
Auto merge of rust-lang#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.)
2 parents 44cf8ef + b99c129 commit 208a74c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

editors/code/src/commands.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,13 @@ export function addProject(ctx: CtxInit): Cmd {
761761
}
762762

763763
const workspaces: JsonProject[] = await Promise.all(
764-
vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
765-
const rustDocuments = vscode.workspace.textDocuments.filter(isRustDocument);
766-
return discoverWorkspace(rustDocuments, discoverProjectCommand, {
767-
cwd: folder.uri.fsPath,
768-
});
769-
})
764+
vscode.workspace.textDocuments
765+
.filter(isRustDocument)
766+
.map(async (file): Promise<JsonProject> => {
767+
return discoverWorkspace([file], discoverProjectCommand, {
768+
cwd: path.dirname(file.uri.fsPath),
769+
});
770+
})
770771
);
771772

772773
ctx.addToDiscoveredWorkspaces(workspaces);

editors/code/src/ctx.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import * as lc from "vscode-languageclient/node";
33
import * as ra from "./lsp_ext";
4+
import * as path from "path";
45

56
import { Config, prepareVSCodeConfig } from "./config";
67
import { createClient } from "./client";
@@ -192,12 +193,13 @@ export class Ctx {
192193
const discoverProjectCommand = this.config.discoverProjectCommand;
193194
if (discoverProjectCommand) {
194195
const workspaces: JsonProject[] = await Promise.all(
195-
vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
196-
const rustDocuments = vscode.workspace.textDocuments.filter(isRustDocument);
197-
return discoverWorkspace(rustDocuments, discoverProjectCommand, {
198-
cwd: folder.uri.fsPath,
199-
});
200-
})
196+
vscode.workspace.textDocuments
197+
.filter(isRustDocument)
198+
.map(async (file): Promise<JsonProject> => {
199+
return discoverWorkspace([file], discoverProjectCommand, {
200+
cwd: path.dirname(file.uri.fsPath),
201+
});
202+
})
201203
);
202204

203205
this.addToDiscoveredWorkspaces(workspaces);

0 commit comments

Comments
 (0)