fix(tui): resolve clippy -D warnings findings

This commit is contained in:
Felipe Coury
2026-02-10 23:15:46 -03:00
parent 801ae5e979
commit 5986719f96
5 changed files with 54 additions and 36 deletions

View File

@@ -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(

View File

@@ -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();

View File

@@ -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::<String>()
})
.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::<String>()
})
.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();
}

View File

@@ -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<ThemeEntry
if let Ok(read_dir) = std::fs::read_dir(&themes_dir) {
for entry in read_dir.flatten() {
let path = entry.path();
if path.extension().and_then(|e| e.to_str()) == Some("tmTheme") {
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
let name = stem.to_string();
let is_valid_theme = ThemeSet::get_theme(&path).is_ok();
if is_valid_theme && !entries.iter().any(|e| e.name == name) {
entries.push(ThemeEntry {
name,
is_custom: true,
});
}
if path.extension().and_then(|e| e.to_str()) == Some("tmTheme")
&& let Some(stem) = path.file_stem().and_then(|s| s.to_str())
{
let name = stem.to_string();
let is_valid_theme = ThemeSet::get_theme(&path).is_ok();
if is_valid_theme && !entries.iter().any(|e| e.name == name) {
entries.push(ThemeEntry {
name,
is_custom: true,
});
}
}
}
@@ -417,8 +420,11 @@ fn highlight_to_line_spans(code: &str, lang: &str) -> Option<Vec<Vec<Span<'stati
}
let syntax = find_syntax(lang)?;
let theme_guard = theme_lock().read().unwrap();
let mut h = HighlightLines::new(syntax, &*theme_guard);
let theme_guard = match theme_lock().read() {
Ok(theme_guard) => theme_guard,
Err(poisoned) => poisoned.into_inner(),
};
let mut h = HighlightLines::new(syntax, &theme_guard);
let mut lines: Vec<Vec<Span<'static>>> = Vec::new();
for line in LinesWithEndings::from(code) {

View File

@@ -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<String> = 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<dyn Fn(usize, &crate::app_event_sender::AppEventSender) + Send + Sync>);
@@ -409,7 +409,7 @@ mod tests {
fn preview_line_number(line: &str) -> Option<usize> {
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<char> {
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;
}