Lightweight coding agent that runs in your terminal
Rust
Highlight CUDA files as C++ in the TUI (#34570)
Eric Traut726689564aa7
diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rsindex 58410baf33..388d282bc9 100644--- a/codex-rs/tui/src/diff_render.rs+++ b/codex-rs/tui/src/diff_render.rs@@ -2222,34 +2222,37 @@ mod tests {#[test]fn cpp_module_extensions_use_cpp_highlighting() {- let highlighted_tokens = ["cpp", "cppm", "CPPM", "cxxm", "CxXm", "ixx", "IXX"]- .into_iter()- .map(|extension| {- let mut changes: HashMap<PathBuf, FileChange> = HashMap::new();- changes.insert(- PathBuf::from(format!("math.{extension}")),- FileChange::Add {- content:- "export module math;\nexport int sum(int a, int b) { return a + b; }\n"- .to_string(),- },- );-- let lines =- create_diff_summary(&changes, &PathBuf::from("/"), /*wrap_cols*/ 80);- let rgb_tokens = lines- .iter()- .flat_map(|line| &line.spans)- .filter(|span| matches!(span.style.fg, Some(ratatui::style::Color::Rgb(..))))- .map(|span| span.content.to_string())- .collect::<Vec<_>>();- assert!(- !rgb_tokens.is_empty(),- "add diff for .{extension} file should produce syntax-highlighted (RGB) spans"- );- (extension, rgb_tokens.join("|"))- })- .collect::<Vec<_>>();+ let highlighted_tokens = [+ "cpp",+ // CUDA source and header extensions use C++ highlighting as a fallback.+ "cu", "cuh", "cppm", "CPPM", "cxxm", "CxXm", "ixx", "IXX",+ ]+ .into_iter()+ .map(|extension| {+ let mut changes: HashMap<PathBuf, FileChange> = HashMap::new();+ changes.insert(+ PathBuf::from(format!("math.{extension}")),+ FileChange::Add {+ content:+ "export module math;\nexport int sum(int a, int b) { return a + b; }\n"+ .to_string(),+ },+ );++ let lines = create_diff_summary(&changes, &PathBuf::from("/"), /*wrap_cols*/ 80);+ let rgb_tokens = lines+ .iter()+ .flat_map(|line| &line.spans)+ .filter(|span| matches!(span.style.fg, Some(ratatui::style::Color::Rgb(..))))+ .map(|span| span.content.to_string())+ .collect::<Vec<_>>();+ assert!(+ !rgb_tokens.is_empty(),+ "add diff for .{extension} file should produce syntax-highlighted (RGB) spans"+ );+ (extension, rgb_tokens.join("|"))+ })+ .collect::<Vec<_>>();assert_debug_snapshot!("cpp_module_extension_highlighting", highlighted_tokens);}diff --git a/codex-rs/tui/src/render/highlight.rs b/codex-rs/tui/src/render/highlight.rsindex f0b77f6652..058dbc8a45 100644--- a/codex-rs/tui/src/render/highlight.rs+++ b/codex-rs/tui/src/render/highlight.rs@@ -539,6 +539,8 @@ fn find_syntax(lang: &str) -> Option<&'static SyntaxReference> {let normalized = lang.to_ascii_lowercase();let patched = match normalized.as_str() {"csharp" | "c-sharp" => "c#",+ // CUDA source (.cu) and header (.cuh) files use C++ highlighting as a fallback.+ "cu" | "cuh" => "cpp","cppm" | "cxxm" | "ixx" => "cpp","golang" => "go","python3" => "python",@@ -1216,8 +1218,8 @@ mod tests {}// Patched aliases that two-face cannot resolve on its own.for alias in [- "csharp", "c-sharp", "cppm", "CPPM", "cxxm", "CxXm", "ixx", "IXX", "golang", "python3",- "shell",+ "csharp", "c-sharp", "cu", "cuh", "cppm", "CPPM", "cxxm", "CxXm", "ixx", "IXX",+ "golang", "python3", "shell",] {assert!(find_syntax(alias).is_some(),diff --git a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__cpp_module_extension_highlighting.snap b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__cpp_module_extension_highlighting.snapindex be5ab4fe17..3376f8f04c 100644--- a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__cpp_module_extension_highlighting.snap+++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__cpp_module_extension_highlighting.snap@@ -7,6 +7,14 @@ expression: highlighted_tokens"cpp","export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}",),+ (+ "cu",+ "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}",+ ),+ (+ "cuh",+ "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}",+ ),("cppm","export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}",