From 11b37e75d6f8475baa14aeb7277fc4554a88715c Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 16 Jun 2026 12:17:44 -0400 Subject: [PATCH 1/3] fix(tui): highlight C++ module files --- codex-rs/tui/src/diff_render.rs | 43 ++++++++++++++++++++++++++++ codex-rs/tui/src/render/highlight.rs | 5 +++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index 350c3c7aa059..d44bcb427898 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -2200,6 +2200,49 @@ mod tests { ); } + #[test] + fn cpp_module_extensions_use_cpp_highlighting() { + for extension in ["cpp", "ixx", "cxxm"] { + let mut changes: HashMap = 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); + assert!( + lines.iter().any(|line| { + line.spans + .iter() + .any(|span| matches!(span.style.fg, Some(ratatui::style::Color::Rgb(..)))) + }), + "add diff for .{extension} file should produce syntax-highlighted (RGB) spans" + ); + } + } + + #[test] + fn unknown_extension_falls_back_without_syntax_highlighting() { + let mut changes: HashMap = HashMap::new(); + changes.insert( + PathBuf::from("math.unknown-extension"), + FileChange::Add { + content: "export module math;\nexport int value = 42;\n".to_string(), + }, + ); + + let lines = create_diff_summary(&changes, &PathBuf::from("/"), /*wrap_cols*/ 80); + assert!(lines.iter().all(|line| { + line.spans + .iter() + .all(|span| !matches!(span.style.fg, Some(ratatui::style::Color::Rgb(..)))) + })); + } + #[test] fn delete_diff_uses_path_extension_for_highlighting() { let mut changes: HashMap = HashMap::new(); diff --git a/codex-rs/tui/src/render/highlight.rs b/codex-rs/tui/src/render/highlight.rs index cb83f06f4efa..e2582ea6fba6 100644 --- a/codex-rs/tui/src/render/highlight.rs +++ b/codex-rs/tui/src/render/highlight.rs @@ -528,6 +528,7 @@ fn find_syntax(lang: &str) -> Option<&'static SyntaxReference> { // Aliases that two-face does not resolve on its own. let patched = match lang { "csharp" | "c-sharp" => "c#", + "cxxm" | "ixx" => "cpp", "golang" => "go", "python3" => "python", "shell" => "bash", @@ -1203,7 +1204,9 @@ mod tests { ); } // Patched aliases that two-face cannot resolve on its own. - for alias in ["csharp", "c-sharp", "golang", "python3", "shell"] { + for alias in [ + "csharp", "c-sharp", "cxxm", "ixx", "golang", "python3", "shell", + ] { assert!( find_syntax(alias).is_some(), "find_syntax({alias:?}) returned None — patched alias broken" From 13b40b2b4bdc6343dd78ea35af27e76b37cf7338 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 16 Jun 2026 13:07:31 -0400 Subject: [PATCH 2/3] fix(tui): highlight cppm module files --- codex-rs/tui/src/diff_render.rs | 50 +++++++++++-------- codex-rs/tui/src/render/highlight.rs | 4 +- ...ts__cpp_module_extension_highlighting.snap | 22 ++++++++ 3 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__cpp_module_extension_highlighting.snap diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index d44bcb427898..fe52dee8c539 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -1307,6 +1307,7 @@ fn style_gutter_dim() -> Style { #[cfg(test)] mod tests { use super::*; + use insta::assert_debug_snapshot; use insta::assert_snapshot; use pretty_assertions::assert_eq; use ratatui::Terminal; @@ -2202,27 +2203,36 @@ mod tests { #[test] fn cpp_module_extensions_use_cpp_highlighting() { - for extension in ["cpp", "ixx", "cxxm"] { - let mut changes: HashMap = 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 highlighted_tokens = ["cpp", "cppm", "cxxm", "ixx"] + .into_iter() + .map(|extension| { + let mut changes: HashMap = 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::>(); + assert!( + !rgb_tokens.is_empty(), + "add diff for .{extension} file should produce syntax-highlighted (RGB) spans" + ); + (extension, rgb_tokens.join("|")) + }) + .collect::>(); - let lines = create_diff_summary(&changes, &PathBuf::from("/"), /*wrap_cols*/ 80); - assert!( - lines.iter().any(|line| { - line.spans - .iter() - .any(|span| matches!(span.style.fg, Some(ratatui::style::Color::Rgb(..)))) - }), - "add diff for .{extension} file should produce syntax-highlighted (RGB) spans" - ); - } + assert_debug_snapshot!("cpp_module_extension_highlighting", highlighted_tokens); } #[test] diff --git a/codex-rs/tui/src/render/highlight.rs b/codex-rs/tui/src/render/highlight.rs index e2582ea6fba6..c8d1615bed29 100644 --- a/codex-rs/tui/src/render/highlight.rs +++ b/codex-rs/tui/src/render/highlight.rs @@ -528,7 +528,7 @@ fn find_syntax(lang: &str) -> Option<&'static SyntaxReference> { // Aliases that two-face does not resolve on its own. let patched = match lang { "csharp" | "c-sharp" => "c#", - "cxxm" | "ixx" => "cpp", + "cppm" | "cxxm" | "ixx" => "cpp", "golang" => "go", "python3" => "python", "shell" => "bash", @@ -1205,7 +1205,7 @@ mod tests { } // Patched aliases that two-face cannot resolve on its own. for alias in [ - "csharp", "c-sharp", "cxxm", "ixx", "golang", "python3", "shell", + "csharp", "c-sharp", "cppm", "cxxm", "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.snap new file mode 100644 index 000000000000..1eff46230481 --- /dev/null +++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__cpp_module_extension_highlighting.snap @@ -0,0 +1,22 @@ +--- +source: tui/src/diff_render.rs +expression: highlighted_tokens +--- +[ + ( + "cpp", + "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|;| |}", + ), + ( + "cxxm", + "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}", + ), + ( + "ixx", + "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}", + ), +] From 8488219425c7d197501159c7cd478c0ebcac5976 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 16 Jun 2026 13:22:37 -0400 Subject: [PATCH 3/3] fix(tui): match syntax aliases case-insensitively --- codex-rs/tui/src/diff_render.rs | 2 +- codex-rs/tui/src/render/highlight.rs | 6 ++++-- ...er__tests__cpp_module_extension_highlighting.snap | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index fe52dee8c539..9df58fb7e66f 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -2203,7 +2203,7 @@ mod tests { #[test] fn cpp_module_extensions_use_cpp_highlighting() { - let highlighted_tokens = ["cpp", "cppm", "cxxm", "ixx"] + let highlighted_tokens = ["cpp", "cppm", "CPPM", "cxxm", "CxXm", "ixx", "IXX"] .into_iter() .map(|extension| { let mut changes: HashMap = HashMap::new(); diff --git a/codex-rs/tui/src/render/highlight.rs b/codex-rs/tui/src/render/highlight.rs index c8d1615bed29..ef4d7a2f353a 100644 --- a/codex-rs/tui/src/render/highlight.rs +++ b/codex-rs/tui/src/render/highlight.rs @@ -526,7 +526,8 @@ fn find_syntax(lang: &str) -> Option<&'static SyntaxReference> { let ss = syntax_set(); // Aliases that two-face does not resolve on its own. - let patched = match lang { + let normalized = lang.to_ascii_lowercase(); + let patched = match normalized.as_str() { "csharp" | "c-sharp" => "c#", "cppm" | "cxxm" | "ixx" => "cpp", "golang" => "go", @@ -1205,7 +1206,8 @@ mod tests { } // Patched aliases that two-face cannot resolve on its own. for alias in [ - "csharp", "c-sharp", "cppm", "cxxm", "ixx", "golang", "python3", "shell", + "csharp", "c-sharp", "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.snap index 1eff46230481..be5ab4fe179d 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 @@ -11,12 +11,24 @@ expression: highlighted_tokens "cppm", "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|;| |}", + ), ( "cxxm", "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}", ), + ( + "CxXm", + "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}", + ), ( "ixx", "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}", ), + ( + "IXX", + "export| module math|;|export| |int| |sum|(|int| |a|,| |int| |b|)| |{| |return| a |+| b|;| |}", + ), ]