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

health: add formatter binary #5692

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,36 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
lang.debugger.as_ref().map(|dap| dap.command.to_string()),
)?;

probe_commands(
lang.formatter
.as_ref()
.map(|fmtcfg| fmtcfg.command.to_string()),
)?;

for ts_feat in TsFeature::all() {
probe_treesitter_feature(&lang_str, *ts_feat)?
}

Ok(())
}

/// Display any additional binaries that are configured as commands for the
/// language.
fn probe_commands(formatter_cmd: Option<String>) -> std::io::Result<()> {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();

if let Some(cmd) = formatter_cmd {
let path = match which::which(&cmd) {
Ok(path) => path.display().to_string().green(),
Err(_) => format!("'{}' not found in $PATH", cmd).red(),
};
writeln!(stdout, "Binary for formatter: {}", path)?;
}

Ok(())
}

Comment on lines +280 to +294
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make it more generic for checking any binary exists? Might not get the lock on stdout if the binary's path is None.

Suggested change
fn probe_commands(formatter_cmd: Option<String>) -> std::io::Result<()> {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
if let Some(cmd) = formatter_cmd {
let path = match which::which(&cmd) {
Ok(path) => path.display().to_string().green(),
Err(_) => format!("'{}' not found in $PATH", cmd).red(),
};
writeln!(stdout, "Binary for formatter: {}", path)?;
}
Ok(())
}
fn probe_binary(binary_name: &str, binary_path: Option<String>) -> std::io::Result<()> {
if let Some(bin) = binary_path {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
let path = match which::which(&bin) {
Ok(path) => path.display().to_string().green(),
Err(_) => format!("'{}' not found in $PATH", bin).red(),
};
writeln!(stdout, "Binary for {}: {}", binary_name, 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