From 05d1f9452ae67a9f1cff2160d018aab47f58f798 Mon Sep 17 00:00:00 2001 From: woojiq Date: Fri, 4 Aug 2023 17:45:49 +0300 Subject: [PATCH 1/3] feat(health): support multiple health arguments --- helix-term/src/args.rs | 7 +++++-- helix-term/src/health.rs | 34 ++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..22131d0ffb58 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -8,7 +8,7 @@ pub struct Args { pub display_help: bool, pub display_version: bool, pub health: bool, - pub health_arg: Option, + pub health_arg: Vec, pub load_tutor: bool, pub fetch_grammars: bool, pub build_grammars: bool, @@ -42,7 +42,10 @@ impl Args { }, "--health" => { args.health = true; - args.health_arg = argv.next_if(|opt| !opt.starts_with('-')); + // Helix exists after printin health so we don't care about files + while let Some(item) = argv.next_if(|opt| !opt.starts_with('-')) { + args.health_arg.push(item); + } } "-g" | "--grammar" => match argv.next().as_deref() { Some("fetch") => args.fetch_grammars = true, diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 8f92187778be..e435abf70941 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -328,17 +328,31 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<( Ok(()) } -pub fn print_health(health_arg: Option) -> std::io::Result<()> { - match health_arg.as_deref() { - Some("languages") => languages_all()?, - Some("clipboard") => clipboard()?, - None | Some("all") => { - general()?; - clipboard()?; - writeln!(std::io::stdout().lock())?; - languages_all()?; +pub fn print_health(health_args: Vec) -> std::io::Result<()> { + fn print_all() -> std::io::Result<()> { + general()?; + clipboard()?; + writeln!(std::io::stdout().lock())?; + languages_all()?; + Ok(()) + } + + if health_args.is_empty() { + print_all()?; + return Ok(()); + } + for (idx, health_arg) in health_args.into_iter().enumerate() { + if idx != 0 { + // Empty line + let mut stdout = std::io::stdout().lock(); + writeln!(stdout)?; + } + match health_arg.as_str() { + "languages" => languages_all()?, + "clipboard" => clipboard()?, + "all" => print_all()?, + lang => language(lang.into())?, } - Some(lang) => language(lang.to_string())?, } Ok(()) } From 5c4b8732fcf5017f5cb505c33861ba0755da559a Mon Sep 17 00:00:00 2001 From: woojiq Date: Fri, 4 Aug 2023 19:17:51 +0300 Subject: [PATCH 2/3] feat(health): show info about all lsp/dap binaries --- helix-term/src/health.rs | 55 ++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index e435abf70941..cf8edd6ce759 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -192,15 +192,15 @@ pub fn languages_all() -> std::io::Result<()> { 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| { + // All supported servers for language + let mut servers = lang.language_servers.iter().filter_map(|ls| { syn_loader_conf .language_server .get(&ls.name) .map(|config| config.command.clone()) }); - check_binary(lsp); + + check_binary(servers.next()); let dap = lang.debugger.as_ref().map(|dap| dap.command.to_string()); check_binary(dap); @@ -213,6 +213,14 @@ pub fn languages_all() -> std::io::Result<()> { } writeln!(stdout)?; + + // Add other language servers binary to the column + for ls in servers { + // Skip lang name + column("", Color::Reset); + check_binary(Some(ls)); + writeln!(stdout)?; + } } Ok(()) @@ -271,17 +279,24 @@ pub fn language(lang_str: String) -> std::io::Result<()> { // TODO multiple language servers probe_protocol( "language server", - lang.language_servers.first().and_then(|ls| { - syn_loader_conf - .language_server - .get(&ls.name) - .map(|config| config.command.clone()) - }), + lang.language_servers + .iter() + .filter_map(|ls| { + syn_loader_conf + .language_server + .get(&ls.name) + .map(|config| config.command.clone()) + }) + .collect(), )?; probe_protocol( "debug adapter", - lang.debugger.as_ref().map(|dap| dap.command.to_string()), + lang.debugger + .as_ref() + .map(|dap| dap.command.to_owned()) + .into_iter() + .collect(), )?; for ts_feat in TsFeature::all() { @@ -292,18 +307,20 @@ pub fn language(lang_str: String) -> std::io::Result<()> { } /// Display diagnostics about LSP and DAP. -fn probe_protocol(protocol_name: &str, server_cmd: Option) -> std::io::Result<()> { +fn probe_protocol(protocol_name: &str, server_cmds: Vec) -> std::io::Result<()> { let stdout = std::io::stdout(); let mut stdout = stdout.lock(); - let cmd_name = match server_cmd { - Some(ref cmd) => cmd.as_str().green(), - None => "None".yellow(), - }; - writeln!(stdout, "Configured {}: {}", protocol_name, cmd_name)?; + if server_cmds.is_empty() { + writeln!(stdout, "Configured {}: {}", protocol_name, "None".yellow())?; + return Ok(()); + } + + for server_cmd in server_cmds { + let cmd = server_cmd.as_str(); + writeln!(stdout, "Configured {}: {}", protocol_name, cmd.green())?; - if let Some(cmd) = server_cmd { - let path = match which::which(&cmd) { + let path = match which::which(cmd) { Ok(path) => path.display().to_string().green(), Err(_) => format!("'{}' not found in $PATH", cmd).red(), }; From 01c98025b85fc0cfde24a6162585ad62085c047f Mon Sep 17 00:00:00 2001 From: woojiq Date: Fri, 4 Aug 2023 19:41:02 +0300 Subject: [PATCH 3/3] fix grammar --- helix-term/src/args.rs | 2 +- helix-term/src/health.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 22131d0ffb58..dd339dc7080e 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -42,7 +42,7 @@ impl Args { }, "--health" => { args.health = true; - // Helix exists after printin health so we don't care about files + // Treat all arguments after `--health' as language names while let Some(item) = argv.next_if(|opt| !opt.starts_with('-')) { args.health_arg.push(item); } diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index cf8edd6ce759..78bb3fca2240 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -276,7 +276,6 @@ pub fn language(lang_str: String) -> std::io::Result<()> { } }; - // TODO multiple language servers probe_protocol( "language server", lang.language_servers @@ -358,9 +357,10 @@ pub fn print_health(health_args: Vec) -> std::io::Result<()> { print_all()?; return Ok(()); } + for (idx, health_arg) in health_args.into_iter().enumerate() { if idx != 0 { - // Empty line + // New line let mut stdout = std::io::stdout().lock(); writeln!(stdout)?; }