Skip to content

Commit 36d3c5a

Browse files
chore: format with cargo fmt
1 parent bb53da9 commit 36d3c5a

File tree

6 files changed

+334
-218
lines changed

6 files changed

+334
-218
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
restore-keys: |
5454
${{ runner.os }}-target-
5555
56+
- name: Check formatting of Rust code
57+
run: cargo fmt --check
58+
5659
- name: Install frontend dependencies
5760
run: cd frontend && npm ci
5861

src/cli.rs

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ async fn run_edit(cli: RenderArgs) -> Result<()> {
303303
}
304304
}
305305
} else {
306-
// Fallback: try relative to input file directory
307-
let resolved_direct = input_dir.join(path_str);
308-
if resolved_direct.exists() {
309-
Some(resolved_direct)
310-
} else {
311-
Some(path)
312-
}
306+
// Fallback: try relative to input file directory
307+
let resolved_direct = input_dir.join(path_str);
308+
if resolved_direct.exists() {
309+
Some(resolved_direct)
310+
} else {
311+
Some(path)
312+
}
313313
}
314314
}
315315
} else {
@@ -467,49 +467,56 @@ async fn run_new(cli: RenderArgs) -> Result<()> {
467467
#[cfg(all(feature = "server", not(target_arch = "wasm32")))]
468468
async fn run_code_map(cli: RenderArgs, code_map_path: String) -> Result<()> {
469469
let path = PathBuf::from(&code_map_path);
470-
470+
471471
// Check if it's an existing .mmd file
472472
if path.extension().and_then(|s| s.to_str()) == Some("mmd") && path.exists() {
473473
let content = fs::read_to_string(&path)?;
474474
let (mapping, metadata) = oxdraw::codemap::extract_code_mappings(&content);
475-
475+
476476
let mut warning = None;
477477
// Check sync status
478478
if let Some(path_str) = &metadata.path {
479-
// Try to resolve the path
480-
let mut source_path = PathBuf::from(path_str);
481-
482-
// If the path is relative and doesn't exist, try to resolve it relative to the git root of the input file
483-
if !source_path.exists() && source_path.is_relative() {
484-
let input_dir = path.parent().unwrap_or(&path);
485-
if let Some((_, _, git_root)) = oxdraw::codemap::get_git_info(input_dir) {
486-
let resolved = git_root.join(path_str);
487-
if resolved.exists() {
488-
source_path = resolved;
489-
}
490-
}
491-
}
492-
493-
if source_path.exists() {
494-
if let Some((current_commit, current_diff, _)) = oxdraw::codemap::get_git_info(&source_path) {
495-
let mut warnings = Vec::new();
496-
if let Some(meta_commit) = &metadata.commit {
497-
if meta_commit != &current_commit {
498-
warnings.push(format!("Commit mismatch: map({}) vs HEAD({})", meta_commit, current_commit));
499-
}
500-
}
501-
if let Some(meta_diff) = &metadata.diff_hash {
502-
if meta_diff != &current_diff {
503-
warnings.push("Working directory has changed since map generation".to_string());
504-
}
505-
}
506-
if !warnings.is_empty() {
507-
let msg = warnings.join("; ");
508-
println!("Warning: {}", msg);
509-
warning = Some(msg);
510-
}
511-
}
512-
}
479+
// Try to resolve the path
480+
let mut source_path = PathBuf::from(path_str);
481+
482+
// If the path is relative and doesn't exist, try to resolve it relative to the git root of the input file
483+
if !source_path.exists() && source_path.is_relative() {
484+
let input_dir = path.parent().unwrap_or(&path);
485+
if let Some((_, _, git_root)) = oxdraw::codemap::get_git_info(input_dir) {
486+
let resolved = git_root.join(path_str);
487+
if resolved.exists() {
488+
source_path = resolved;
489+
}
490+
}
491+
}
492+
493+
if source_path.exists() {
494+
if let Some((current_commit, current_diff, _)) =
495+
oxdraw::codemap::get_git_info(&source_path)
496+
{
497+
let mut warnings = Vec::new();
498+
if let Some(meta_commit) = &metadata.commit {
499+
if meta_commit != &current_commit {
500+
warnings.push(format!(
501+
"Commit mismatch: map({}) vs HEAD({})",
502+
meta_commit, current_commit
503+
));
504+
}
505+
}
506+
if let Some(meta_diff) = &metadata.diff_hash {
507+
if meta_diff != &current_diff {
508+
warnings.push(
509+
"Working directory has changed since map generation".to_string(),
510+
);
511+
}
512+
}
513+
if !warnings.is_empty() {
514+
let msg = warnings.join("; ");
515+
println!("Warning: {}", msg);
516+
warning = Some(msg);
517+
}
518+
}
519+
}
513520
}
514521

515522
let ui_root = locate_ui_dist()?;
@@ -548,7 +555,7 @@ async fn run_code_map(cli: RenderArgs, code_map_path: String) -> Result<()> {
548555
}
549556

550557
let root_path = path.canonicalize()?;
551-
558+
552559
let (mermaid, mapping) = oxdraw::codemap::generate_code_map(
553560
&root_path,
554561
cli.api_key,
@@ -559,7 +566,8 @@ async fn run_code_map(cli: RenderArgs, code_map_path: String) -> Result<()> {
559566
cli.no_ai,
560567
cli.max_nodes,
561568
cli.gemini,
562-
).await?;
569+
)
570+
.await?;
563571

564572
let git_info = oxdraw::codemap::get_git_info(&root_path);
565573
let metadata = oxdraw::codemap::CodeMapMetadata {
@@ -580,19 +588,23 @@ async fn run_code_map(cli: RenderArgs, code_map_path: String) -> Result<()> {
580588

581589
if let Some(output_path_str) = cli.output {
582590
if output_path_str == "-" {
583-
// stdout
584-
println!("{}", full_content);
585-
return Ok(());
591+
// stdout
592+
println!("{}", full_content);
593+
return Ok(());
586594
}
587595

588596
let output_path = PathBuf::from(&output_path_str);
589-
let extension = output_path.extension().and_then(|s| s.to_str()).unwrap_or("").to_lowercase();
597+
let extension = output_path
598+
.extension()
599+
.and_then(|s| s.to_str())
600+
.unwrap_or("")
601+
.to_lowercase();
590602

591603
if extension == "svg" || extension == "png" {
592604
// Save .mmd as well
593605
let mut mmd_path = output_path.clone();
594606
mmd_path.set_extension("mmd");
595-
607+
596608
fs::write(&mmd_path, &full_content)?;
597609
println!("Code map saved to {}", mmd_path.display());
598610

@@ -604,9 +616,11 @@ async fn run_code_map(cli: RenderArgs, code_map_path: String) -> Result<()> {
604616
}
605617
diagram.render_png(&cli.background_color, None, cli.scale)?
606618
} else {
607-
diagram.render_svg(&cli.background_color, None)?.into_bytes()
619+
diagram
620+
.render_svg(&cli.background_color, None)?
621+
.into_bytes()
608622
};
609-
623+
610624
fs::write(&output_path, output_bytes)?;
611625
println!("Rendered diagram saved to {}", output_path.display());
612626
} else {

0 commit comments

Comments
 (0)