diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-20 22:03:49 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-20 22:08:26 +0300 |
| commit | df357b250c0fcf4edf2681d4f114e199afb51899 (patch) | |
| tree | eba744d9238057e8758e2098670e0561d920d998 /src/config/io.rs | |
| parent | c584037c77c63f6a08f8837f357c89432b8043e7 (diff) | |
fix: clarify keybinding conflict warnings
refs #154
Diffstat (limited to 'src/config/io.rs')
| -rw-r--r-- | src/config/io.rs | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/config/io.rs b/src/config/io.rs index 12176815..3b483ba6 100644 --- a/src/config/io.rs +++ b/src/config/io.rs @@ -92,17 +92,22 @@ pub fn config_path() -> PathBuf { } pub fn config_diagnostic_summary(diagnostics: &[String]) -> Option<String> { + const MAX_VISIBLE_DIAGNOSTICS: usize = 4; + if diagnostics.is_empty() { - None - } else if diagnostics.len() == 1 { - Some(diagnostics[0].clone()) - } else { - Some(format!( - "{} (and {} more)", - diagnostics[0], - diagnostics.len() - 1 - )) + return None; + } + + let mut lines: Vec<String> = diagnostics + .iter() + .take(MAX_VISIBLE_DIAGNOSTICS) + .map(|diagnostic| diagnostic.split_whitespace().collect::<Vec<_>>().join(" ")) + .collect(); + let hidden = diagnostics.len().saturating_sub(MAX_VISIBLE_DIAGNOSTICS); + if hidden > 0 { + lines.push(format!("and {hidden} more config warnings")); } + Some(lines.join("\n")) } pub fn load_live_config() -> Result<LoadedConfig, Vec<String>> { @@ -435,6 +440,22 @@ mod tests { } #[test] + fn config_diagnostic_summary_keeps_multiple_warnings_visible() { + let diagnostics = vec![ + "one".to_string(), + "two".to_string(), + "three".to_string(), + "four".to_string(), + "five".to_string(), + ]; + + assert_eq!( + config_diagnostic_summary(&diagnostics).as_deref(), + Some("one\ntwo\nthree\nfour\nand 1 more config warnings") + ); + } + + #[test] fn remove_keybinding_config_sections_removes_keys_tables_only() { let content = r#"onboarding = false |
