syster-cli 0.4.5-alpha

Command-line interface for SysML v2 and KerML analysis
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
//! syster CLI - Command-line interface for SysML v2 and KerML analysis

use clap::{Parser, ValueEnum};
use std::path::PathBuf;
use std::process::ExitCode;
use syster::hir::Severity;
use syster_cli::{DiagnosticInfo, export_ast, export_json, run_analysis};
#[cfg(feature = "interchange")]
use syster_cli::{add_member, inspect_element, query_model, remove_member, rename_element};
#[cfg(feature = "interchange")]
use syster_cli::{decompile_model, export_model, import_model, import_model_into_host};

/// Output format for export commands
#[derive(Clone, Copy, Debug, ValueEnum)]
enum OutputFormat {
    /// Human-readable text format
    Text,
    /// JSON format
    Json,
}

/// Interchange format for model export
#[cfg(feature = "interchange")]
#[derive(Clone, Copy, Debug, ValueEnum)]
enum InterchangeFormat {
    /// XML Model Interchange
    Xmi,
    /// Kernel Package Archive (ZIP)
    Kpar,
    /// JSON-LD
    JsonLd,
    /// YAML
    Yaml,
}

#[derive(Parser)]
#[command(name = "syster")]
#[command(about = "SysML v2 parser and semantic analyzer", long_about = None)]
#[command(version)]
struct Cli {
    /// Input file or directory to analyze
    #[arg(value_name = "FILE")]
    input: PathBuf,

    /// Enable verbose output
    #[arg(short, long)]
    verbose: bool,

    /// Skip loading standard library
    #[arg(long)]
    no_stdlib: bool,

    /// Path to custom standard library (default: sysml.library)
    #[arg(long, value_name = "PATH")]
    stdlib_path: Option<PathBuf>,

    /// Export AST (abstract syntax tree) for all files
    #[arg(long)]
    export_ast: bool,

    /// Export analysis results as JSON
    #[arg(long)]
    json: bool,

    /// Export model to interchange format (xmi, kpar, jsonld)
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "FORMAT")]
    export: Option<InterchangeFormat>,

    /// Import and validate an interchange file (xmi, kpar, jsonld)
    #[cfg(feature = "interchange")]
    #[arg(long)]
    import: bool,

    /// Import interchange file into workspace for analysis (preserves element IDs)
    #[cfg(feature = "interchange")]
    #[arg(long)]
    import_workspace: bool,

    /// Decompile interchange file to SysML text + metadata
    #[cfg(feature = "interchange")]
    #[arg(long)]
    decompile: bool,

    /// Include standard library in export (self-contained output)
    #[cfg(feature = "interchange")]
    #[arg(long)]
    self_contained: bool,

    /// Query model elements by name (substring match)
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "NAME")]
    query: Option<String>,

    /// List all model elements (use with --kind to filter)
    #[cfg(feature = "interchange")]
    #[arg(long)]
    list: bool,

    /// Filter query results by metaclass kind (e.g., PartDefinition, PartUsage)
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "KIND")]
    kind: Option<String>,

    /// Inspect a specific element by name or qualified name
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "NAME")]
    inspect: Option<String>,

    /// Rename an element: --rename OLD=NEW
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "OLD=NEW")]
    rename: Option<String>,

    /// Add a member to an element: --add-member PARENT:KIND:NAME[:TYPE]
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "PARENT:KIND:NAME[:TYPE]")]
    add_member: Option<String>,

    /// Remove an element by name or qualified name
    #[cfg(feature = "interchange")]
    #[arg(long, value_name = "NAME")]
    remove_member: Option<String>,

    /// Write output to file instead of stdout
    #[arg(short, long, value_name = "FILE")]
    output: Option<PathBuf>,
}

fn main() -> ExitCode {
    let cli = Cli::parse();

    if cli.verbose {
        eprintln!("Analyzing: {}", cli.input.display());
    }

    // Handle decompile (convert XMI to SysML text)
    #[cfg(feature = "interchange")]
    if cli.decompile {
        match decompile_model(&cli.input, None, cli.verbose) {
            Ok(result) => {
                eprintln!(
                    "✓ Decompiled {} elements from {}",
                    result.element_count, result.source_path
                );

                // Write SysML file
                let sysml_path = cli
                    .output
                    .clone()
                    .unwrap_or_else(|| cli.input.with_extension("sysml"));
                if let Err(e) = std::fs::write(&sysml_path, &result.sysml_text) {
                    eprintln!("error: failed to write {}: {}", sysml_path.display(), e);
                    return ExitCode::FAILURE;
                }
                eprintln!("  Wrote: {}", sysml_path.display());

                // Write metadata file
                let metadata_path = sysml_path.with_extension("metadata.json");
                if let Err(e) = std::fs::write(&metadata_path, &result.metadata_json) {
                    eprintln!("error: failed to write {}: {}", metadata_path.display(), e);
                    return ExitCode::FAILURE;
                }
                eprintln!("  Wrote: {}", metadata_path.display());

                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle query / list (semantic model query)
    #[cfg(feature = "interchange")]
    if cli.query.is_some() || cli.list {
        let name_filter = cli.query.as_deref();
        let kind_filter = cli.kind.as_deref();

        match query_model(
            &cli.input,
            name_filter,
            kind_filter,
            None, // qualified name — use --inspect for that
            cli.verbose,
        ) {
            Ok(result) => {
                if cli.json {
                    let json = serde_json::to_string_pretty(&result)
                        .expect("failed to serialize query result");
                    write_output(&json, cli.output.as_ref());
                } else {
                    println!("Found {} element(s):", result.match_count);
                    for el in &result.elements {
                        let kind = &el.kind;
                        let name = el.name.as_deref().unwrap_or("(anonymous)");
                        let qn = el
                            .qualified_name
                            .as_deref()
                            .map(|q| format!("  ({})", q))
                            .unwrap_or_default();
                        let typing = if !el.typed_by.is_empty() {
                            format!(" : {}", el.typed_by.join(", "))
                        } else {
                            String::new()
                        };
                        let supers = if !el.supertypes.is_empty() {
                            format!(" :> {}", el.supertypes.join(", "))
                        } else {
                            String::new()
                        };
                        let abs = if el.is_abstract { " [abstract]" } else { "" };
                        let members = if el.owned_member_count > 0 {
                            format!(" ({} members)", el.owned_member_count)
                        } else {
                            String::new()
                        };
                        println!("  {kind} {name}{typing}{supers}{abs}{members}{qn}");
                    }
                }
                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle inspect (detailed element view)
    #[cfg(feature = "interchange")]
    if let Some(ref target) = cli.inspect {
        match inspect_element(&cli.input, target, cli.verbose) {
            Ok(result) => {
                if cli.json {
                    let json = serde_json::to_string_pretty(&result)
                        .expect("failed to serialize inspect result");
                    write_output(&json, cli.output.as_ref());
                } else {
                    let el = &result.element;
                    let name = el.name.as_deref().unwrap_or("(anonymous)");
                    println!("{} {}", el.kind, name);
                    if let Some(qn) = &el.qualified_name {
                        println!("  qualified: {}", qn);
                    }
                    if let Some(owner) = &el.owner {
                        println!("  owner: {}", owner);
                    }
                    if el.is_abstract {
                        println!("  abstract: true");
                    }
                    if !el.typed_by.is_empty() {
                        println!("  typed by: {}", el.typed_by.join(", "));
                    }
                    if !el.supertypes.is_empty() {
                        println!("  specializes: {}", el.supertypes.join(", "));
                    }
                    if let Some(doc) = &el.documentation {
                        println!("  doc: {}", doc);
                    }

                    if !result.children.is_empty() {
                        println!("\n  Children ({}):", result.children.len());
                        for child in &result.children {
                            let cn = child.name.as_deref().unwrap_or("(anonymous)");
                            let ct = if !child.typed_by.is_empty() {
                                format!(": {}", child.typed_by.join(", "))
                            } else {
                                String::new()
                            };
                            println!("    {} {}{}", child.kind, cn, ct);
                        }
                    }

                    if !result.relationships_from.is_empty() {
                        println!(
                            "\n  Relationships from ({}):",
                            result.relationships_from.len()
                        );
                        for rel in &result.relationships_from {
                            println!("    {} -> {} ({})", rel.source, rel.target, rel.kind);
                        }
                    }

                    if !result.relationships_to.is_empty() {
                        println!("\n  Relationships to ({}):", result.relationships_to.len());
                        for rel in &result.relationships_to {
                            println!("    {} -> {} ({})", rel.source, rel.target, rel.kind);
                        }
                    }
                }
                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle rename (semantic rename + re-render)
    #[cfg(feature = "interchange")]
    if let Some(ref rename_spec) = cli.rename {
        let parts: Vec<&str> = rename_spec.splitn(2, '=').collect();
        if parts.len() != 2 {
            eprintln!("error: --rename requires OLD=NEW format (e.g., --rename Vehicle=Car)");
            return ExitCode::FAILURE;
        }
        let old_name = parts[0];
        let new_name = parts[1];

        match rename_element(&cli.input, old_name, new_name, cli.verbose) {
            Ok(result) => {
                let out_path = cli.output.clone().unwrap_or_else(|| cli.input.clone());

                // Write SysML text
                if cli.output.is_some() {
                    write_output(&result.rendered_text, cli.output.as_ref());
                } else if let Err(e) = std::fs::write(&out_path, &result.rendered_text) {
                    eprintln!("error: failed to write {}: {}", out_path.display(), e);
                    return ExitCode::FAILURE;
                }

                eprintln!(
                    "✓ Renamed '{}' -> '{}', wrote to {}",
                    result.old_name,
                    result.new_name,
                    out_path.display()
                );

                // Write updated metadata JSON alongside
                if let Some(metadata_json) = &result.metadata_json {
                    let metadata_path = out_path.with_extension("metadata.json");
                    if let Err(e) = std::fs::write(&metadata_path, metadata_json) {
                        eprintln!(
                            "warning: failed to write metadata {}: {}",
                            metadata_path.display(),
                            e
                        );
                    } else {
                        eprintln!("  Wrote: {}", metadata_path.display());
                    }
                }

                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle add-member (add a child element)
    #[cfg(feature = "interchange")]
    if let Some(ref add_spec) = cli.add_member {
        // Format: PARENT:KIND:NAME or PARENT:KIND:NAME:TYPE
        let parts: Vec<&str> = add_spec.splitn(4, ':').collect();
        if parts.len() < 3 {
            eprintln!("error: --add-member requires PARENT:KIND:NAME[:TYPE] format");
            eprintln!("  Example: --add-member Car:PartUsage:turbo");
            eprintln!("  Example: --add-member Car:PartUsage:turbo:Engine");
            return ExitCode::FAILURE;
        }
        let parent = parts[0];
        let kind = parts[1];
        let name = parts[2];
        let type_name = parts.get(3).copied();

        match add_member(&cli.input, parent, name, kind, type_name, cli.verbose) {
            Ok(result) => {
                let out_path = cli.output.clone().unwrap_or_else(|| cli.input.clone());

                if cli.output.is_some() {
                    write_output(&result.rendered_text, cli.output.as_ref());
                } else if let Err(e) = std::fs::write(&out_path, &result.rendered_text) {
                    eprintln!("error: failed to write {}: {}", out_path.display(), e);
                    return ExitCode::FAILURE;
                }

                eprintln!(
                    "✓ Added {} '{}' to '{}', wrote to {}",
                    result.member_kind,
                    result.member_name,
                    result.parent_name,
                    out_path.display()
                );

                if let Some(metadata_json) = &result.metadata_json {
                    let metadata_path = out_path.with_extension("metadata.json");
                    if let Err(e) = std::fs::write(&metadata_path, metadata_json) {
                        eprintln!(
                            "warning: failed to write metadata {}: {}",
                            metadata_path.display(),
                            e
                        );
                    } else {
                        eprintln!("  Wrote: {}", metadata_path.display());
                    }
                }

                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle remove-member (remove an element)
    #[cfg(feature = "interchange")]
    if let Some(ref target) = cli.remove_member {
        match remove_member(&cli.input, target, cli.verbose) {
            Ok(result) => {
                let out_path = cli.output.clone().unwrap_or_else(|| cli.input.clone());

                if cli.output.is_some() {
                    write_output(&result.rendered_text, cli.output.as_ref());
                } else if let Err(e) = std::fs::write(&out_path, &result.rendered_text) {
                    eprintln!("error: failed to write {}: {}", out_path.display(), e);
                    return ExitCode::FAILURE;
                }

                eprintln!(
                    "✓ Removed '{}', wrote to {}",
                    result.removed_name,
                    out_path.display()
                );

                if let Some(metadata_json) = &result.metadata_json {
                    let metadata_path = out_path.with_extension("metadata.json");
                    if let Err(e) = std::fs::write(&metadata_path, metadata_json) {
                        eprintln!(
                            "warning: failed to write metadata {}: {}",
                            metadata_path.display(),
                            e
                        );
                    } else {
                        eprintln!("  Wrote: {}", metadata_path.display());
                    }
                }

                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle interchange import (validate only)
    #[cfg(feature = "interchange")]
    if cli.import {
        match import_model(&cli.input, None, cli.verbose) {
            Ok(result) => {
                println!(
                    "✓ Imported {} elements, {} relationships",
                    result.element_count, result.relationship_count
                );
                if result.error_count > 0 || result.warning_count > 0 {
                    let total = result.error_count + result.warning_count;
                    eprintln!("  {} validation issue(s):", total);
                    for msg in &result.messages {
                        eprintln!("    {}", msg);
                    }
                }
                if result.error_count > 0 {
                    return ExitCode::FAILURE;
                }
                if result.warning_count > 0 {
                    return ExitCode::from(2);
                }
                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle import into workspace (for analysis) + optional export
    #[cfg(feature = "interchange")]
    if cli.import_workspace {
        use syster::ide::AnalysisHost;
        use syster::project::StdLibLoader;
        use syster_cli::export_from_host;

        let mut host = AnalysisHost::new();

        // Load stdlib if enabled
        if !cli.no_stdlib {
            let mut loader = StdLibLoader::new();
            if let Err(e) = loader.ensure_loaded_into_host(&mut host) {
                eprintln!("warning: failed to load stdlib: {}", e);
            }
        }

        // Import the XMI/KPAR model into workspace
        match import_model_into_host(&mut host, &cli.input, None, cli.verbose) {
            Ok(result) => {
                // If --export is also specified, export from the imported workspace
                if let Some(format) = &cli.export {
                    // Use stderr for status when exporting (stdout is for data)
                    eprintln!(
                        "✓ Imported {} elements ({} symbols) into workspace",
                        result.element_count, result.element_count
                    );

                    let analysis = host.analysis();
                    let all_symbols: Vec<_> = analysis.symbol_index().all_symbols().collect();
                    eprintln!("  Total symbols in workspace: {}", all_symbols.len());
                    eprintln!("  Element IDs preserved: ✓");

                    let format_str = match format {
                        InterchangeFormat::Xmi => "xmi",
                        InterchangeFormat::Kpar => "kpar",
                        InterchangeFormat::JsonLd => "jsonld",
                        InterchangeFormat::Yaml => "yaml",
                    };

                    match export_from_host(&mut host, format_str, cli.verbose, cli.self_contained) {
                        Ok(bytes) => {
                            write_bytes_output(&bytes, cli.output.as_ref());
                            return ExitCode::SUCCESS;
                        }
                        Err(e) => {
                            eprintln!("error: {}", e);
                            return ExitCode::FAILURE;
                        }
                    }
                }

                // No export - use stdout for status
                println!(
                    "✓ Imported {} elements ({} symbols) into workspace",
                    result.element_count, result.element_count
                );

                // Run analysis on imported symbols
                let analysis = host.analysis();
                let all_symbols: Vec<_> = analysis.symbol_index().all_symbols().collect();

                println!("  Total symbols in workspace: {}", all_symbols.len());
                println!("  Element IDs preserved: ✓");

                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle interchange export
    #[cfg(feature = "interchange")]
    if let Some(format) = &cli.export {
        let format_str = match format {
            InterchangeFormat::Xmi => "xmi",
            InterchangeFormat::Kpar => "kpar",
            InterchangeFormat::JsonLd => "jsonld",
            InterchangeFormat::Yaml => "yaml",
        };

        match export_model(
            &cli.input,
            format_str,
            cli.verbose,
            !cli.no_stdlib,
            cli.stdlib_path.as_deref(),
            cli.self_contained,
        ) {
            Ok(bytes) => {
                write_bytes_output(&bytes, cli.output.as_ref());
                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    // Handle AST export
    if cli.export_ast {
        match export_ast(
            &cli.input,
            cli.verbose,
            !cli.no_stdlib,
            cli.stdlib_path.as_deref(),
        ) {
            Ok(ast_output) => {
                write_output(&ast_output, cli.output.as_ref());
                return ExitCode::SUCCESS;
            }
            Err(e) => {
                eprintln!("error: {}", e);
                return ExitCode::FAILURE;
            }
        }
    }

    match run_analysis(
        &cli.input,
        cli.verbose,
        !cli.no_stdlib,
        cli.stdlib_path.as_deref(),
    ) {
        Ok(result) => {
            // Handle JSON export
            if cli.json {
                match export_json(&result) {
                    Ok(json) => {
                        write_output(&json, cli.output.as_ref());
                        return if result.error_count == 0 {
                            ExitCode::SUCCESS
                        } else {
                            ExitCode::FAILURE
                        };
                    }
                    Err(e) => {
                        eprintln!("error: {}", e);
                        return ExitCode::FAILURE;
                    }
                }
            }

            // Print diagnostics (normal mode)
            for diag in &result.diagnostics {
                print_diagnostic(diag);
            }

            // Print summary
            if result.error_count == 0 {
                println!(
                    "✓ Analyzed {} files: {} symbols, {} warnings",
                    result.file_count, result.symbol_count, result.warning_count
                );
                ExitCode::SUCCESS
            } else {
                eprintln!(
                    "✗ Analyzed {} files: {} errors, {} warnings",
                    result.file_count, result.error_count, result.warning_count
                );
                ExitCode::FAILURE
            }
        }
        Err(e) => {
            eprintln!("error: {}", e);
            ExitCode::FAILURE
        }
    }
}

/// Write output to file or stdout
fn write_output(content: &str, output_path: Option<&PathBuf>) {
    match output_path {
        Some(path) => {
            if let Err(e) = std::fs::write(path, content) {
                eprintln!("error: failed to write output: {}", e);
            }
        }
        None => {
            println!("{}", content);
        }
    }
}

/// Write binary output to file or stdout
fn write_bytes_output(content: &[u8], output_path: Option<&PathBuf>) {
    use std::io::Write;
    match output_path {
        Some(path) => {
            if let Err(e) = std::fs::write(path, content) {
                eprintln!("error: failed to write output: {}", e);
            }
        }
        None => {
            // For stdout, try to write as string if valid UTF-8, otherwise raw bytes
            if let Ok(s) = std::str::from_utf8(content) {
                println!("{}", s);
            } else {
                let mut stdout = std::io::stdout();
                if let Err(e) = stdout.write_all(content) {
                    eprintln!("error: failed to write output: {}", e);
                }
            }
        }
    }
}

/// Print a diagnostic message in a compiler-like format.
fn print_diagnostic(diag: &DiagnosticInfo) {
    let prefix = match diag.severity {
        Severity::Error => "error",
        Severity::Warning => "warning",
        Severity::Info => "info",
        Severity::Hint => "hint",
    };

    let code_suffix = diag
        .code
        .as_ref()
        .map(|c| format!("[{}]", c))
        .unwrap_or_default();

    eprintln!(
        "{}{}: {}:{}:{}: {}",
        prefix, code_suffix, diag.file, diag.line, diag.col, diag.message
    );
}