Skip to content

Commit 76029e5

Browse files
authored
health: Use lsp name in output wherever possible (#13573)
Also match the DAP/Formatter output style to the LSP style
1 parent 3a6c974 commit 76029e5

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

helix-term/src/health.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,26 @@ pub fn languages_all() -> std::io::Result<()> {
185185
.language
186186
.sort_unstable_by_key(|l| l.language_id.clone());
187187

188-
let check_binary = |cmd: Option<&str>| match cmd {
189-
Some(cmd) => match helix_stdx::env::which(cmd) {
190-
Ok(_) => color(fit(&format!("✓ {}", cmd)), Color::Green),
191-
Err(_) => color(fit(&format!("✘ {}", cmd)), Color::Red),
188+
let check_binary_with_name = |cmd: Option<(&str, &str)>| match cmd {
189+
Some((name, cmd)) => match helix_stdx::env::which(cmd) {
190+
Ok(_) => color(fit(&format!("✓ {}", name)), Color::Green),
191+
Err(_) => color(fit(&format!("✘ {}", name)), Color::Red),
192192
},
193193
None => color(fit("None"), Color::Yellow),
194194
};
195195

196+
let check_binary = |cmd: Option<&str>| check_binary_with_name(cmd.map(|cmd| (cmd, cmd)));
197+
196198
for lang in &syn_loader_conf.language {
197199
write!(stdout, "{}", fit(&lang.language_id))?;
198200

199201
let mut cmds = lang.language_servers.iter().filter_map(|ls| {
200202
syn_loader_conf
201203
.language_server
202204
.get(&ls.name)
203-
.map(|config| config.command.as_str())
205+
.map(|config| (ls.name.as_str(), config.command.as_str()))
204206
});
205-
write!(stdout, "{}", check_binary(cmds.next()))?;
207+
write!(stdout, "{}", check_binary_with_name(cmds.next()))?;
206208

207209
let dap = lang.debugger.as_ref().map(|dap| dap.command.as_str());
208210
write!(stdout, "{}", check_binary(dap))?;
@@ -224,7 +226,7 @@ pub fn languages_all() -> std::io::Result<()> {
224226

225227
for cmd in cmds {
226228
write!(stdout, "{}", fit(""))?;
227-
writeln!(stdout, "{}", check_binary(Some(cmd)))?;
229+
writeln!(stdout, "{}", check_binary_with_name(Some(cmd)))?;
228230
}
229231
}
230232

@@ -283,10 +285,12 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
283285

284286
probe_protocols(
285287
"language server",
286-
lang.language_servers
287-
.iter()
288-
.filter_map(|ls| syn_loader_conf.language_server.get(&ls.name))
289-
.map(|config| config.command.as_str()),
288+
lang.language_servers.iter().filter_map(|ls| {
289+
syn_loader_conf
290+
.language_server
291+
.get(&ls.name)
292+
.map(|config| (ls.name.as_str(), config.command.as_str()))
293+
}),
290294
)?;
291295

292296
probe_protocol(
@@ -323,7 +327,7 @@ fn probe_parser(grammar_name: &str) -> std::io::Result<()> {
323327
}
324328

325329
/// Display diagnostics about multiple LSPs and DAPs.
326-
fn probe_protocols<'a, I: Iterator<Item = &'a str> + 'a>(
330+
fn probe_protocols<'a, I: Iterator<Item = (&'a str, &'a str)> + 'a>(
327331
protocol_name: &str,
328332
server_cmds: I,
329333
) -> std::io::Result<()> {
@@ -338,12 +342,12 @@ fn probe_protocols<'a, I: Iterator<Item = &'a str> + 'a>(
338342
}
339343
writeln!(stdout)?;
340344

341-
for cmd in server_cmds {
342-
let (path, icon) = match helix_stdx::env::which(cmd) {
345+
for (name, cmd) in server_cmds {
346+
let (diag, icon) = match helix_stdx::env::which(cmd) {
343347
Ok(path) => (path.display().to_string().green(), "✓".green()),
344348
Err(_) => (format!("'{}' not found in $PATH", cmd).red(), "✘".red()),
345349
};
346-
writeln!(stdout, " {} {}: {}", icon, cmd, path)?;
350+
writeln!(stdout, " {} {}: {}", icon, name, diag)?;
347351
}
348352

349353
Ok(())
@@ -354,19 +358,18 @@ fn probe_protocol(protocol_name: &str, server_cmd: Option<String>) -> std::io::R
354358
let stdout = std::io::stdout();
355359
let mut stdout = stdout.lock();
356360

357-
let cmd_name = match server_cmd {
358-
Some(ref cmd) => cmd.as_str().green(),
359-
None => "None".yellow(),
361+
write!(stdout, "Configured {}:", protocol_name)?;
362+
let Some(cmd) = server_cmd else {
363+
writeln!(stdout, "{}", " None".yellow())?;
364+
return Ok(());
360365
};
361-
writeln!(stdout, "Configured {}: {}", protocol_name, cmd_name)?;
366+
writeln!(stdout)?;
362367

363-
if let Some(cmd) = server_cmd {
364-
let path = match helix_stdx::env::which(&cmd) {
365-
Ok(path) => path.display().to_string().green(),
366-
Err(_) => format!("'{}' not found in $PATH", cmd).red(),
367-
};
368-
writeln!(stdout, "Binary for {}: {}", protocol_name, path)?;
369-
}
368+
let (diag, icon) = match helix_stdx::env::which(&cmd) {
369+
Ok(path) => (path.display().to_string().green(), "✓".green()),
370+
Err(_) => (format!("'{}' not found in $PATH", cmd).red(), "✘".red()),
371+
};
372+
writeln!(stdout, " {} {}", icon, diag)?;
370373

371374
Ok(())
372375
}

0 commit comments

Comments
 (0)