Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for showing all LSPs in --health #7315

Merged
merged 10 commits into from
Oct 16, 2023
74 changes: 57 additions & 17 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,36 @@ pub fn languages_all() -> std::io::Result<()> {
None => column("None", Color::Yellow),
};

let check_binaries = |cmds: Vec<String>| {
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);

// 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);
Expand Down Expand Up @@ -268,15 +286,14 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
}
};

// TODO multiple language servers
probe_protocol(
probe_protocols(
"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.as_str())
.collect::<Vec<_>>()
.as_slice(),
)?;

probe_protocol(
Expand All @@ -291,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<()> {
TheRealLorenz marked this conversation as resolved.
Show resolved Hide resolved
let stdout = std::io::stdout();
let mut stdout = stdout.lock();

write!(stdout, "Configured {}s:", protocol_name)?;
if server_cmds.is_empty() {
TheRealLorenz marked this conversation as resolved.
Show resolved Hide resolved
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<String>) -> std::io::Result<()> {
let stdout = std::io::stdout();
Expand Down