mirror of https://github.com/helix-editor/helix
Add support for showing all LSPs in --health (#7315)
* Add support for showing all LSPs in --health <lang> * Add support for showing all LSPs in --health languages * Use available/configured in --health languages * Apply @AlexanderBrevig suggestion in --health * Update `--health <language>` Better output (inspired by #8156). Handle the case where no LSPs are configured. * Display all LSPs in `--health languages` instead of x/x Displays all LSPs as a list in the table generated wih `--health languages` * Make check_binary accept Optional references to str Avoids some calls to .clone() * Apply @the-mikedavis suggestions * Avoid useless collecting and cloning * Use for loop instead of .try_for_each()pull/8542/head^2
parent
7c98b1c829
commit
d9d7f67898
|
@ -181,8 +181,8 @@ pub fn languages_all() -> std::io::Result<()> {
|
||||||
.language
|
.language
|
||||||
.sort_unstable_by_key(|l| l.language_id.clone());
|
.sort_unstable_by_key(|l| l.language_id.clone());
|
||||||
|
|
||||||
let check_binary = |cmd: Option<String>| match cmd {
|
let check_binary = |cmd: Option<&str>| match cmd {
|
||||||
Some(cmd) => match which::which(&cmd) {
|
Some(cmd) => match which::which(cmd) {
|
||||||
Ok(_) => column(&format!("✓ {}", cmd), Color::Green),
|
Ok(_) => column(&format!("✓ {}", cmd), Color::Green),
|
||||||
Err(_) => column(&format!("✘ {}", cmd), Color::Red),
|
Err(_) => column(&format!("✘ {}", cmd), Color::Red),
|
||||||
},
|
},
|
||||||
|
@ -192,17 +192,15 @@ pub fn languages_all() -> std::io::Result<()> {
|
||||||
for lang in &syn_loader_conf.language {
|
for lang in &syn_loader_conf.language {
|
||||||
column(&lang.language_id, Color::Reset);
|
column(&lang.language_id, Color::Reset);
|
||||||
|
|
||||||
// TODO multiple language servers (check binary for each supported language server, not just the first)
|
let mut cmds = lang.language_servers.iter().filter_map(|ls| {
|
||||||
|
|
||||||
let lsp = lang.language_servers.first().and_then(|ls| {
|
|
||||||
syn_loader_conf
|
syn_loader_conf
|
||||||
.language_server
|
.language_server
|
||||||
.get(&ls.name)
|
.get(&ls.name)
|
||||||
.map(|config| config.command.clone())
|
.map(|config| config.command.as_str())
|
||||||
});
|
});
|
||||||
check_binary(lsp);
|
check_binary(cmds.next());
|
||||||
|
|
||||||
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);
|
check_binary(dap);
|
||||||
|
|
||||||
for ts_feat in TsFeature::all() {
|
for ts_feat in TsFeature::all() {
|
||||||
|
@ -213,6 +211,12 @@ pub fn languages_all() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(stdout)?;
|
writeln!(stdout)?;
|
||||||
|
|
||||||
|
for cmd in cmds {
|
||||||
|
column("", Color::Reset);
|
||||||
|
check_binary(Some(cmd));
|
||||||
|
writeln!(stdout)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -268,15 +272,12 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO multiple language servers
|
probe_protocols(
|
||||||
probe_protocol(
|
|
||||||
"language server",
|
"language server",
|
||||||
lang.language_servers.first().and_then(|ls| {
|
lang.language_servers
|
||||||
syn_loader_conf
|
.iter()
|
||||||
.language_server
|
.filter_map(|ls| syn_loader_conf.language_server.get(&ls.name))
|
||||||
.get(&ls.name)
|
.map(|config| config.command.as_str()),
|
||||||
.map(|config| config.command.clone())
|
|
||||||
}),
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
probe_protocol(
|
probe_protocol(
|
||||||
|
@ -291,6 +292,33 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Display diagnostics about multiple LSPs and DAPs.
|
||||||
|
fn probe_protocols<'a, I: Iterator<Item = &'a str> + '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.peek().is_none() {
|
||||||
|
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.
|
/// Display diagnostics about LSP and DAP.
|
||||||
fn probe_protocol(protocol_name: &str, server_cmd: Option<String>) -> std::io::Result<()> {
|
fn probe_protocol(protocol_name: &str, server_cmd: Option<String>) -> std::io::Result<()> {
|
||||||
let stdout = std::io::stdout();
|
let stdout = std::io::stdout();
|
||||||
|
|
Loading…
Reference in New Issue