Skip to content

Commit afad7bf

Browse files
committed
Some DRY refactor
1 parent dc06713 commit afad7bf

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

helix-term/src/health.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,20 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
250250
}
251251
};
252252

253-
probe_protocol(
253+
probe_binary(
254254
"language server",
255255
lang.language_server
256256
.as_ref()
257257
.map(|lsp| lsp.command.to_string()),
258258
)?;
259259

260-
probe_protocol(
260+
probe_binary(
261261
"debug adapter",
262262
lang.debugger.as_ref().map(|dap| dap.command.to_string()),
263263
)?;
264264

265-
probe_commands(
265+
probe_binary(
266+
"formatter",
266267
lang.formatter
267268
.as_ref()
268269
.map(|fmtcfg| fmtcfg.command.to_string()),
@@ -275,40 +276,23 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
275276
Ok(())
276277
}
277278

278-
/// Display any additional binaries that are configured as commands for the
279-
/// language.
280-
fn probe_commands(formatter_cmd: Option<String>) -> std::io::Result<()> {
281-
let stdout = std::io::stdout();
282-
let mut stdout = stdout.lock();
283-
284-
if let Some(cmd) = formatter_cmd {
285-
let path = match which::which(&cmd) {
286-
Ok(path) => path.display().to_string().green(),
287-
Err(_) => format!("'{}' not found in $PATH", cmd).red(),
288-
};
289-
writeln!(stdout, "Binary for formatter: {}", path)?;
290-
}
291-
292-
Ok(())
293-
}
294-
295-
/// Display diagnostics about LSP and DAP.
296-
fn probe_protocol(protocol_name: &str, server_cmd: Option<String>) -> std::io::Result<()> {
279+
/// Display diagnostics about binaries related to the language.
280+
fn probe_binary(use_case: &str, server_cmd: Option<String>) -> std::io::Result<()> {
297281
let stdout = std::io::stdout();
298282
let mut stdout = stdout.lock();
299283

300284
let cmd_name = match server_cmd {
301285
Some(ref cmd) => cmd.as_str().green(),
302286
None => "None".yellow(),
303287
};
304-
writeln!(stdout, "Configured {}: {}", protocol_name, cmd_name)?;
288+
writeln!(stdout, "Configured {}: {}", use_case, cmd_name)?;
305289

306290
if let Some(cmd) = server_cmd {
307291
let path = match which::which(&cmd) {
308292
Ok(path) => path.display().to_string().green(),
309293
Err(_) => format!("'{}' not found in $PATH", cmd).red(),
310294
};
311-
writeln!(stdout, "Binary for {}: {}", protocol_name, path)?;
295+
writeln!(stdout, "Binary for {}: {}", use_case, path)?;
312296
}
313297

314298
Ok(())

0 commit comments

Comments
 (0)