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

Conversation

jzelinskie
Copy link
Contributor

I noticed that some languages have external formatters that are not a part of their LSP configuration.
To surface that information, this PR adds a new output to --health that displays the formatter binary.

In the future, this could be expanded to look for other fields that contain commands from the language config.

Here's some example output.

$ cargo run -- --health go
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/hx --health go`
Configured language server: gopls
Binary for language server: /Users/jzelinskie/.local/share/go/bin/gopls
Configured debug adapter: dlv
Binary for debug adapter: /Users/jzelinskie/.local/share/go/bin/dlv
Highlight queries: ✓
Textobject queries: ✓
Indent queries: ✓
$ cargo run -- --health cue
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/hx --health cue`
Configured language server: cuelsp
Binary for language server: /Users/jzelinskie/.local/share/go/bin/cuelsp
Configured debug adapter: None
Binary for formatter: /opt/homebrew/bin/cue
Highlight queries: ✓
Textobject queries: ✘
Indent queries: ✘

This adds a new output to --health that displays
the formatter binary.
@the-mikedavis the-mikedavis added C-enhancement Category: Improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Jan 26, 2023
Comment on lines +280 to +294
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(())
}

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(())
}

@gibbz00 gibbz00 mentioned this pull request Jan 27, 2023
5 tasks
@kirawi kirawi added the A-helix-term Area: Helix term improvements label Jan 29, 2023
@the-mikedavis the-mikedavis linked an issue May 8, 2023 that may be closed by this pull request
@rayanpiro
Copy link

I feel more comfortable with a solution like this.

In this case probe_commands has the same goal that probe_protocol. So just change some naming and the calls from the LSP, DAP and add the formatter one.

Tests OK and is working properly.

@jzelinskie
Copy link
Contributor Author

Fixed in #7986

@jzelinskie jzelinskie closed this Feb 6, 2024
@jzelinskie jzelinskie deleted the formatter-health branch February 6, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add formatter to hx --health
5 participants