Skip to content

Commit e26e989

Browse files
authored
Fix spacetime generate running dotnet format in the wrong directory (#3687)
# Description of Changes `spacetime generate` calls `dotnet format`.. but it did so with `--folder`, without going to any particular directory. The result would be that `dotnet format` tries to format _whatever directory it was run from. # API and ABI breaking changes None. # Expected complexity level and risk 1 # Testing - [x] `python3 -m smoketests namespaces` no longer hangs on my machine --------- Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent fc784fd commit e26e989

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

crates/cli/src/subcommands/generate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub async fn exec_ex(
252252
}
253253
}
254254

255-
if let Err(err) = lang.format_files(paths) {
255+
if let Err(err) = lang.format_files(out_dir, paths) {
256256
// If we couldn't format the files, print a warning but don't fail the entire
257257
// task as the output should still be usable, just less pretty.
258258
eprintln!("Could not format generated files: {err}");
@@ -285,10 +285,10 @@ impl clap::ValueEnum for Language {
285285
}
286286

287287
impl Language {
288-
fn format_files(&self, generated_files: BTreeSet<PathBuf>) -> anyhow::Result<()> {
288+
fn format_files(&self, project_dir: &PathBuf, generated_files: BTreeSet<PathBuf>) -> anyhow::Result<()> {
289289
match self {
290290
Language::Rust => rustfmt(generated_files)?,
291-
Language::Csharp => dotnet_format(generated_files)?,
291+
Language::Csharp => dotnet_format(project_dir, generated_files)?,
292292
Language::TypeScript => {
293293
// TODO: implement formatting.
294294
}

crates/cli/src/tasks/csharp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub(crate) fn build_csharp(project_path: &Path, build_debug: bool) -> anyhow::Re
108108
anyhow::bail!("Built project successfully but couldn't find the output file.");
109109
}
110110

111-
pub(crate) fn dotnet_format(files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> {
111+
pub(crate) fn dotnet_format(project_dir: &PathBuf, files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> {
112112
duct::cmd(
113113
"dotnet",
114114
itertools::chain(
@@ -128,6 +128,8 @@ pub(crate) fn dotnet_format(files: impl IntoIterator<Item = PathBuf>) -> anyhow:
128128
files.into_iter().map_into(),
129129
),
130130
)
131+
// This is important because we're running with `--folder`. We want to format the right folder!
132+
.dir(project_dir)
131133
.run()?;
132134
Ok(())
133135
}

0 commit comments

Comments
 (0)