From 1f7669b069cadba21d62c7b99e4630101455980c Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Sun, 11 Jun 2023 19:07:38 +0200 Subject: [PATCH 01/10] Add support for showing all LSPs in --health --- helix-term/src/health.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 8f92187778be..221b2e517c75 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -268,16 +268,15 @@ pub fn language(lang_str: String) -> std::io::Result<()> { } }; - // TODO multiple language servers - probe_protocol( - "language server", - lang.language_servers.first().and_then(|ls| { + for ls in &lang.language_servers { + probe_protocol( + "language server", syn_loader_conf .language_server .get(&ls.name) - .map(|config| config.command.clone()) - }), - )?; + .map(|config| config.command.clone()), + )?; + } probe_protocol( "debug adapter", From 5377947be54ca6d3b3ae95501297c2eb6919735c Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Mon, 12 Jun 2023 14:08:28 +0200 Subject: [PATCH 02/10] Add support for showing all LSPs in --health languages --- helix-term/src/health.rs | 43 +++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 221b2e517c75..52f426595bb8 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -189,18 +189,43 @@ pub fn languages_all() -> std::io::Result<()> { None => column("None", Color::Yellow), }; + let check_binaries = |cmds: Vec| { + match cmds.len() { + 0 => column("None", Color::Yellow), + 1 => check_binary(cmds.get(0).cloned()), + _ => { + let mut checks = cmds + .iter() + .map(|cmd| which::which(cmd).is_ok()) + .collect::>(); + checks.sort_unstable(); + checks.dedup(); + + if checks.len() == 2 { + column("- Some", Color::Yellow); + } else if checks[0] { + column("✓ All", Color::Green); + } else { + column("✘ None", Color::Red); + } + } + }; + }; + for lang in &syn_loader_conf.language { column(&lang.language_id, Color::Reset); - // TODO multiple language servers (check binary for each supported language server, not just the first) - - let lsp = lang.language_servers.first().and_then(|ls| { - syn_loader_conf - .language_server - .get(&ls.name) - .map(|config| config.command.clone()) - }); - check_binary(lsp); + let cmds = lang + .language_servers + .iter() + .filter_map(|ls| { + syn_loader_conf + .language_server + .get(&ls.name) + .map(|config| config.command.clone()) + }) + .collect(); + check_binaries(cmds); let dap = lang.debugger.as_ref().map(|dap| dap.command.to_string()); check_binary(dap); From fa6e386e616496fb825bcd849615c70c422b84a8 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Mon, 12 Jun 2023 19:45:02 +0200 Subject: [PATCH 03/10] Use available/configured in --health languages --- helix-term/src/health.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 52f426595bb8..252d13cca3ba 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -193,20 +193,17 @@ pub fn languages_all() -> std::io::Result<()> { match cmds.len() { 0 => column("None", Color::Yellow), 1 => check_binary(cmds.get(0).cloned()), - _ => { - let mut checks = cmds - .iter() - .map(|cmd| which::which(cmd).is_ok()) - .collect::>(); - checks.sort_unstable(); - checks.dedup(); - - if checks.len() == 2 { - column("- Some", Color::Yellow); - } else if checks[0] { - column("✓ All", Color::Green); - } else { - column("✘ None", Color::Red); + n_configured => { + let n_available = cmds.iter().filter_map(|cmd| which::which(cmd).ok()).count(); + match n_available { + 0 => column(&format!("✘ 0/{}", n_configured), Color::Red), + n_available if n_available == n_configured => { + column(&format!("✓ {}/{}", n_available, n_configured), Color::Green) + } + n_available => column( + &format!("- {}/{}", n_available, n_configured), + Color::Yellow, + ), } } }; From 379691ca97f486c00de0f56f549b8077ee91ad4d Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Wed, 14 Jun 2023 10:20:23 +0200 Subject: [PATCH 04/10] Apply @AlexanderBrevig suggestion in --health --- helix-term/src/health.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 252d13cca3ba..70817ed4145f 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -195,16 +195,12 @@ pub fn languages_all() -> std::io::Result<()> { 1 => check_binary(cmds.get(0).cloned()), n_configured => { let n_available = cmds.iter().filter_map(|cmd| which::which(cmd).ok()).count(); - match n_available { - 0 => column(&format!("✘ 0/{}", n_configured), Color::Red), - n_available if n_available == n_configured => { - column(&format!("✓ {}/{}", n_available, n_configured), Color::Green) - } - n_available => column( - &format!("- {}/{}", n_available, n_configured), - Color::Yellow, - ), - } + let (icon, color) = match n_available { + 0 => ("✘", Color::Red), + n_available if n_available == n_configured => ("✓", Color::Green), + _ => ("-", Color::Yellow), + }; + column(&format!("{} {}/{}", icon, n_available, n_configured), color); } }; }; From 8fc0bc12522b525e34378dae78891d06a90495f8 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Sun, 3 Sep 2023 20:22:08 +0200 Subject: [PATCH 05/10] Update `--health ` Better output (inspired by #8156). Handle the case where no LSPs are configured. --- helix-term/src/health.rs | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 70817ed4145f..72ac2977a6f8 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -286,15 +286,15 @@ pub fn language(lang_str: String) -> std::io::Result<()> { } }; - for ls in &lang.language_servers { - probe_protocol( - "language server", - syn_loader_conf - .language_server - .get(&ls.name) - .map(|config| config.command.clone()), - )?; - } + probe_protocols( + "language server", + lang.language_servers + .iter() + .filter_map(|ls| syn_loader_conf.language_server.get(&ls.name)) + .map(|config| config.command.as_str()) + .collect::>() + .as_slice(), + )?; probe_protocol( "debug adapter", @@ -308,6 +308,29 @@ pub fn language(lang_str: String) -> std::io::Result<()> { Ok(()) } +/// Display diagnostics about multiple LSPs and DAPs. +fn probe_protocols(protocol_name: &str, server_cmds: &[&str]) -> std::io::Result<()> { + let stdout = std::io::stdout(); + let mut stdout = stdout.lock(); + + write!(stdout, "Configured {}s:", protocol_name)?; + if server_cmds.is_empty() { + writeln!(stdout, "{}", " None".yellow())?; + return Ok(()); + } + writeln!(stdout)?; + + for cmd in server_cmds { + let (path, icon) = match which::which(cmd) { + Ok(path) => (path.display().to_string().green(), "✓".green()), + Err(_) => (format!("'{}' not found in $PATH", cmd).red(), "✘".red()), + }; + writeln!(stdout, " {} {}: {}", icon, cmd, path)?; + } + + Ok(()) +} + /// Display diagnostics about LSP and DAP. fn probe_protocol(protocol_name: &str, server_cmd: Option) -> std::io::Result<()> { let stdout = std::io::stdout(); From cf729c59c36771a3e503c3f0775f749158b60d71 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Thu, 7 Sep 2023 19:51:04 +0200 Subject: [PATCH 06/10] Display all LSPs in `--health languages` instead of x/x Displays all LSPs as a list in the table generated wih `--health languages` --- helix-term/src/health.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 72ac2977a6f8..e59641bcfd25 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -189,22 +189,6 @@ pub fn languages_all() -> std::io::Result<()> { None => column("None", Color::Yellow), }; - let check_binaries = |cmds: Vec| { - match cmds.len() { - 0 => column("None", Color::Yellow), - 1 => check_binary(cmds.get(0).cloned()), - n_configured => { - let n_available = cmds.iter().filter_map(|cmd| which::which(cmd).ok()).count(); - let (icon, color) = match n_available { - 0 => ("✘", Color::Red), - n_available if n_available == n_configured => ("✓", Color::Green), - _ => ("-", Color::Yellow), - }; - column(&format!("{} {}/{}", icon, n_available, n_configured), color); - } - }; - }; - for lang in &syn_loader_conf.language { column(&lang.language_id, Color::Reset); @@ -217,8 +201,8 @@ pub fn languages_all() -> std::io::Result<()> { .get(&ls.name) .map(|config| config.command.clone()) }) - .collect(); - check_binaries(cmds); + .collect::>(); + check_binary(cmds.get(0).cloned()); let dap = lang.debugger.as_ref().map(|dap| dap.command.to_string()); check_binary(dap); @@ -231,6 +215,14 @@ pub fn languages_all() -> std::io::Result<()> { } writeln!(stdout)?; + + if cmds.len() > 1 { + cmds.iter().skip(1).try_for_each(|cmd| { + column("", Color::Reset); + check_binary(Some(cmd.clone())); + writeln!(stdout) + })?; + } } Ok(()) From 657695b3e54686db28d26ef3dbc9b21030a02586 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Thu, 7 Sep 2023 19:55:21 +0200 Subject: [PATCH 07/10] Make check_binary accept Optional references to str Avoids some calls to .clone() --- helix-term/src/health.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index e59641bcfd25..ff88da3beb04 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -181,8 +181,8 @@ pub fn languages_all() -> std::io::Result<()> { .language .sort_unstable_by_key(|l| l.language_id.clone()); - let check_binary = |cmd: Option| match cmd { - Some(cmd) => match which::which(&cmd) { + let check_binary = |cmd: Option<&str>| match cmd { + Some(cmd) => match which::which(cmd) { Ok(_) => column(&format!("✓ {}", cmd), Color::Green), Err(_) => column(&format!("✘ {}", cmd), Color::Red), }, @@ -199,12 +199,12 @@ pub fn languages_all() -> std::io::Result<()> { syn_loader_conf .language_server .get(&ls.name) - .map(|config| config.command.clone()) + .map(|config| config.command.as_str()) }) .collect::>(); - check_binary(cmds.get(0).cloned()); + check_binary(cmds.first().cloned()); - let dap = lang.debugger.as_ref().map(|dap| dap.command.to_string()); + let dap = lang.debugger.as_ref().map(|dap| dap.command.as_str()); check_binary(dap); for ts_feat in TsFeature::all() { @@ -219,7 +219,7 @@ pub fn languages_all() -> std::io::Result<()> { if cmds.len() > 1 { cmds.iter().skip(1).try_for_each(|cmd| { column("", Color::Reset); - check_binary(Some(cmd.clone())); + check_binary(Some(cmd)); writeln!(stdout) })?; } From 753e55a7ae95d5f677cf580a9f209a506251e07c Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Sat, 7 Oct 2023 18:44:35 +0200 Subject: [PATCH 08/10] Apply @the-mikedavis suggestions --- helix-term/src/health.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index ff88da3beb04..89ebc6ec57c0 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -283,9 +283,7 @@ pub fn language(lang_str: String) -> std::io::Result<()> { lang.language_servers .iter() .filter_map(|ls| syn_loader_conf.language_server.get(&ls.name)) - .map(|config| config.command.as_str()) - .collect::>() - .as_slice(), + .map(|config| config.command.as_str()), )?; probe_protocol( @@ -301,12 +299,16 @@ pub fn language(lang_str: String) -> std::io::Result<()> { } /// Display diagnostics about multiple LSPs and DAPs. -fn probe_protocols(protocol_name: &str, server_cmds: &[&str]) -> std::io::Result<()> { +fn probe_protocols<'a, I: Iterator + 'a>( + protocol_name: &str, + server_cmds: I, +) -> std::io::Result<()> { let stdout = std::io::stdout(); let mut stdout = stdout.lock(); + let mut server_cmds = server_cmds.peekable(); write!(stdout, "Configured {}s:", protocol_name)?; - if server_cmds.is_empty() { + if server_cmds.peek().is_none() { writeln!(stdout, "{}", " None".yellow())?; return Ok(()); } From d9647d3752b7f469eda81447acde250ea0826756 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Mon, 9 Oct 2023 08:45:39 +0200 Subject: [PATCH 09/10] Avoid useless collecting and cloning --- helix-term/src/health.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 89ebc6ec57c0..f6a4615b2752 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -192,17 +192,13 @@ pub fn languages_all() -> std::io::Result<()> { for lang in &syn_loader_conf.language { column(&lang.language_id, Color::Reset); - let cmds = lang - .language_servers - .iter() - .filter_map(|ls| { - syn_loader_conf - .language_server - .get(&ls.name) - .map(|config| config.command.as_str()) - }) - .collect::>(); - check_binary(cmds.first().cloned()); + let mut cmds = lang.language_servers.iter().filter_map(|ls| { + syn_loader_conf + .language_server + .get(&ls.name) + .map(|config| config.command.as_str()) + }); + check_binary(cmds.next()); let dap = lang.debugger.as_ref().map(|dap| dap.command.as_str()); check_binary(dap); @@ -216,13 +212,11 @@ pub fn languages_all() -> std::io::Result<()> { writeln!(stdout)?; - if cmds.len() > 1 { - cmds.iter().skip(1).try_for_each(|cmd| { - column("", Color::Reset); - check_binary(Some(cmd)); - writeln!(stdout) - })?; - } + cmds.try_for_each(|cmd| { + column("", Color::Reset); + check_binary(Some(cmd)); + writeln!(stdout) + })?; } Ok(()) From 45e66c5a4b048d6f8667d2414e299af1e2d4ce9e Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Tue, 10 Oct 2023 09:59:55 +0200 Subject: [PATCH 10/10] Use for loop instead of .try_for_each() --- helix-term/src/health.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index f6a4615b2752..dff9031929c3 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -212,11 +212,11 @@ pub fn languages_all() -> std::io::Result<()> { writeln!(stdout)?; - cmds.try_for_each(|cmd| { + for cmd in cmds { column("", Color::Reset); check_binary(Some(cmd)); - writeln!(stdout) - })?; + writeln!(stdout)?; + } } Ok(())