Skip to content

Commit b99c129

Browse files
committed
fix: when running the "discoverProjectCommand", use the Rust file's
parent directory instead of the workspace folder.
1 parent 51d5862 commit b99c129

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

editors/code/src/commands.ts

Lines changed: 7 additions & 6 deletions
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

Lines changed: 8 additions & 6 deletions
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)