Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/cli/src/subcommands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub async fn exec_ex(
}
}

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

impl Language {
fn format_files(&self, generated_files: BTreeSet<PathBuf>) -> anyhow::Result<()> {
fn format_files(&self, project_dir: &PathBuf, generated_files: BTreeSet<PathBuf>) -> anyhow::Result<()> {
match self {
Language::Rust => rustfmt(generated_files)?,
Language::Csharp => dotnet_format(generated_files)?,
Language::Csharp => dotnet_format(project_dir, generated_files)?,
Language::TypeScript => {
// TODO: implement formatting.
}
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/tasks/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub(crate) fn build_csharp(project_path: &Path, build_debug: bool) -> anyhow::Re
anyhow::bail!("Built project successfully but couldn't find the output file.");
}

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