From 5986719f966aaeb43fc53f66cfedacee42b7d094 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 10 Feb 2026 23:15:46 -0300 Subject: [PATCH] fix(tui): resolve clippy -D warnings findings --- codex-rs/tui/src/diff_render.rs | 6 +-- codex-rs/tui/src/markdown_render.rs | 2 +- codex-rs/tui/src/markdown_render_tests.rs | 20 ++++++++-- codex-rs/tui/src/render/highlight.rs | 48 +++++++++++++---------- codex-rs/tui/src/theme_picker.rs | 14 +++---- 5 files changed, 54 insertions(+), 36 deletions(-) diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index 82c0bd91be..ad973a1cd4 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -356,7 +356,7 @@ fn render_change( s, width, line_number_width, - &syn, + syn, )); } else { out.extend(push_wrapped_diff_line( @@ -378,7 +378,7 @@ fn render_change( s, width, line_number_width, - &syn, + syn, )); } else { out.extend(push_wrapped_diff_line( @@ -400,7 +400,7 @@ fn render_change( s, width, line_number_width, - &syn, + syn, )); } else { out.extend(push_wrapped_diff_line( diff --git a/codex-rs/tui/src/markdown_render.rs b/codex-rs/tui/src/markdown_render.rs index c5ec4e3481..48bb8d701f 100644 --- a/codex-rs/tui/src/markdown_render.rs +++ b/codex-rs/tui/src/markdown_render.rs @@ -424,7 +424,7 @@ where .as_deref() .and_then(|s| s.split([',', ' ', '\t']).next()) .filter(|s| !s.is_empty()) - .map(|s| s.to_string()); + .map(std::string::ToString::to_string); self.code_block_lang = lang; self.code_block_buffer.clear(); diff --git a/codex-rs/tui/src/markdown_render_tests.rs b/codex-rs/tui/src/markdown_render_tests.rs index fb1f8bab84..68daaaab7f 100644 --- a/codex-rs/tui/src/markdown_render_tests.rs +++ b/codex-rs/tui/src/markdown_render_tests.rs @@ -665,7 +665,11 @@ fn code_block_known_lang_has_syntax_colors() { }) .collect(); // Content should be preserved; ignore trailing empty line from highlighting. - let content: Vec<&str> = content.iter().map(|s| s.as_str()).filter(|s| !s.is_empty()).collect(); + let content: Vec<&str> = content + .iter() + .map(std::string::String::as_str) + .filter(|s| !s.is_empty()) + .collect(); assert_eq!(content, vec!["fn main() {}"]); // At least one span should have non-default style (syntax highlighting). @@ -690,7 +694,11 @@ fn code_block_unknown_lang_plain() { .collect::() }) .collect(); - let content: Vec<&str> = content.iter().map(|s| s.as_str()).filter(|s| !s.is_empty()).collect(); + let content: Vec<&str> = content + .iter() + .map(std::string::String::as_str) + .filter(|s| !s.is_empty()) + .collect(); assert_eq!(content, vec!["hello world"]); // No syntax coloring for unknown language — all spans have default style. @@ -715,7 +723,11 @@ fn code_block_no_lang_plain() { .collect::() }) .collect(); - let content: Vec<&str> = content.iter().map(|s| s.as_str()).filter(|s| !s.is_empty()).collect(); + let content: Vec<&str> = content + .iter() + .map(std::string::String::as_str) + .filter(|s| !s.is_empty()) + .collect(); assert_eq!(content, vec!["no lang specified"]); } @@ -785,7 +797,7 @@ Here is a code block that shows another fenced block: // Filter empty trailing lines for stability; the code block may or may // not emit a trailing blank depending on the highlighting path. let trimmed: Vec<&str> = { - let mut v: Vec<&str> = lines.iter().map(|s| s.as_str()).collect(); + let mut v: Vec<&str> = lines.iter().map(std::string::String::as_str).collect(); while v.last() == Some(&"") { v.pop(); } diff --git a/codex-rs/tui/src/render/highlight.rs b/codex-rs/tui/src/render/highlight.rs index d405f96ccd..6c7b41ca1f 100644 --- a/codex-rs/tui/src/render/highlight.rs +++ b/codex-rs/tui/src/render/highlight.rs @@ -151,10 +151,10 @@ fn resolve_theme_with_override(name: Option<&str>, codex_home: Option<&Path>) -> return ts.get(theme_name).clone(); } // 2. Try loading {CODEX_HOME}/themes/{name}.tmTheme from disk. - if let Some(home) = codex_home { - if let Some(theme) = load_custom_theme(name, home) { - return theme; - } + if let Some(home) = codex_home + && let Some(theme) = load_custom_theme(name, home) + { + return theme; } tracing::warn!("unknown syntax theme \"{name}\", falling back to auto-detection"); } @@ -190,7 +190,10 @@ pub(crate) fn set_syntax_theme(theme: Theme) { /// Clone the current syntax theme (e.g. to save for cancel-restore). pub(crate) fn current_syntax_theme() -> Theme { - theme_lock().read().unwrap().clone() + match theme_lock().read() { + Ok(theme) => theme.clone(), + Err(poisoned) => poisoned.into_inner().clone(), + } } /// Return the kebab-case name of the currently active theme. @@ -224,10 +227,10 @@ pub(crate) fn resolve_theme_by_name(name: &str, codex_home: Option<&Path>) -> Op return Some(ts.get(embedded).clone()); } // Custom .tmTheme file? - if let Some(home) = codex_home { - if let Some(theme) = load_custom_theme(name, home) { - return Some(theme); - } + if let Some(home) = codex_home + && let Some(theme) = load_custom_theme(name, home) + { + return Some(theme); } None } @@ -255,16 +258,16 @@ pub(crate) fn list_available_themes(codex_home: Option<&Path>) -> Vec Option theme_guard, + Err(poisoned) => poisoned.into_inner(), + }; + let mut h = HighlightLines::new(syntax, &theme_guard); let mut lines: Vec>> = Vec::new(); for line in LinesWithEndings::from(code) { diff --git a/codex-rs/tui/src/theme_picker.rs b/codex-rs/tui/src/theme_picker.rs index 0815ba6b0b..368f4949f1 100644 --- a/codex-rs/tui/src/theme_picker.rs +++ b/codex-rs/tui/src/theme_picker.rs @@ -281,7 +281,7 @@ pub(crate) fn build_theme_picker_params( let original_theme = highlight::current_syntax_theme(); let entries = highlight::list_available_themes(codex_home); - let codex_home_owned = codex_home.map(|p| p.to_path_buf()); + let codex_home_owned = codex_home.map(Path::to_path_buf); // Resolve the effective theme name: honor explicit config only when it is // currently available; otherwise fall back to the active runtime theme so @@ -331,10 +331,10 @@ pub(crate) fn build_theme_picker_params( let preview_names: Vec = entries.iter().map(|e| e.name.clone()).collect(); let preview_home = codex_home_owned.clone(); let on_selection_changed = Some(Box::new(move |idx: usize, _tx: &_| { - if let Some(name) = preview_names.get(idx) { - if let Some(theme) = highlight::resolve_theme_by_name(name, preview_home.as_deref()) { - highlight::set_syntax_theme(theme); - } + if let Some(name) = preview_names.get(idx) + && let Some(theme) = highlight::resolve_theme_by_name(name, preview_home.as_deref()) + { + highlight::set_syntax_theme(theme); } }) as Box); @@ -409,7 +409,7 @@ mod tests { fn preview_line_number(line: &str) -> Option { let trimmed = line.trim_start(); - let digits_len = trimmed.chars().take_while(|ch| ch.is_ascii_digit()).count(); + let digits_len = trimmed.chars().take_while(char::is_ascii_digit).count(); if digits_len == 0 { return None; } @@ -422,7 +422,7 @@ mod tests { fn preview_line_marker(line: &str) -> Option { let trimmed = line.trim_start(); - let digits_len = trimmed.chars().take_while(|ch| ch.is_ascii_digit()).count(); + let digits_len = trimmed.chars().take_while(char::is_ascii_digit).count(); if digits_len == 0 { return None; }