Skip to main content

cargo_cgp/
render.rs

1use cargo_metadata::Message;
2
3use crate::cgp_patterns::is_cgp_diagnostic;
4use crate::diagnostic_db::DiagnosticDatabase;
5
6pub fn render_message(message: &Message, db: &mut DiagnosticDatabase) {
7    match message {
8        Message::CompilerMessage(msg) => {
9            // Check if this is a CGP-related error
10            if is_cgp_diagnostic(&msg.message) {
11                // Add to database for later processing, don't render yet
12                db.add_diagnostic(msg);
13            } else {
14                // Non-CGP error: render immediately using the original rendered field
15                if let Some(rendered) = &msg.message.rendered {
16                    println!("{}", rendered);
17                }
18            }
19        }
20        Message::CompilerArtifact(artifact) => {
21            // For now, we'll show the compilation progress
22            // Format similar to cargo's output
23            let target_name = &artifact.target.name;
24            let verb = if artifact.fresh { "Fresh" } else { "Compiling" };
25            eprintln!("    {:>12} {}", verb, target_name);
26        }
27        Message::BuildScriptExecuted(_) => {
28            // Silently skip build script notifications for now
29        }
30        Message::BuildFinished(finished) => {
31            if !finished.success {
32                eprintln!("Build failed");
33            }
34        }
35        Message::TextLine(_) => {
36            // Suppress text lines as they may contain fragments from Cargo's output
37            // that interfere with our formatted error messages
38        }
39        _ => {
40            // Ignore any other message types (Message is non-exhaustive)
41        }
42    }
43}