diff options
| author | bors <bors@rust-lang.org> | 2023-04-11 07:22:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-11 07:22:40 +0000 |
| commit | 208a74ca5079d2f605f7dd7cd3864e355c12be22 (patch) | |
| tree | 5cd9800ab07622cb6e4498c3030147ad7ada1e6c | |
| parent | 44cf8ef49ad3db5e82f18a89b20e925353389121 (diff) | |
| parent | b99c129b74a0ba1eb2307fa6151be81b544a3794 (diff) | |
| download | rust-208a74ca5079d2f605f7dd7cd3864e355c12be22.tar.gz rust-208a74ca5079d2f605f7dd7cd3864e355c12be22.zip | |
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.)
| -rw-r--r-- | editors/code/src/commands.ts | 13 | ||||
| -rw-r--r-- | editors/code/src/ctx.ts | 14 |
2 files changed, 15 insertions, 12 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 7a8490e4767..4438d475ad9 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -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); diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index dd74b31cc71..0ffa42c2a5a 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -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); |
