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

feat(health): show info about multiple lsp/dap binaries #7833

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Args {
pub display_help: bool,
pub display_version: bool,
pub health: bool,
pub health_arg: Option<String>,
pub health_arg: Vec<String>,
pub load_tutor: bool,
pub fetch_grammars: bool,
pub build_grammars: bool,
Expand Down Expand Up @@ -42,7 +42,10 @@ impl Args {
},
"--health" => {
args.health = true;
args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
// Treat all arguments after `--health' as language names
while let Some(item) = argv.next_if(|opt| !opt.starts_with('-')) {
args.health_arg.push(item);
}
}
"-g" | "--grammar" => match argv.next().as_deref() {
Some("fetch") => args.fetch_grammars = true,
Expand Down
91 changes: 61 additions & 30 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ pub fn languages_all() -> std::io::Result<()> {
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| {
// All supported servers for language
let mut servers = lang.language_servers.iter().filter_map(|ls| {
syn_loader_conf
.language_server
.get(&ls.name)
.map(|config| config.command.clone())
});
check_binary(lsp);

check_binary(servers.next());

let dap = lang.debugger.as_ref().map(|dap| dap.command.to_string());
check_binary(dap);
Expand All @@ -213,6 +213,14 @@ pub fn languages_all() -> std::io::Result<()> {
}

writeln!(stdout)?;

// Add other language servers binary to the column
for ls in servers {
// Skip lang name
column("", Color::Reset);
check_binary(Some(ls));
writeln!(stdout)?;
}
}

Ok(())
Expand Down Expand Up @@ -268,20 +276,26 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
}
};

// TODO multiple language servers
probe_protocol(
"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.clone())
})
.collect(),
)?;

probe_protocol(
"debug adapter",
lang.debugger.as_ref().map(|dap| dap.command.to_string()),
lang.debugger
.as_ref()
.map(|dap| dap.command.to_owned())
.into_iter()
.collect(),
)?;

for ts_feat in TsFeature::all() {
Expand All @@ -292,18 +306,20 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
}

/// Display diagnostics about LSP and DAP.
fn probe_protocol(protocol_name: &str, server_cmd: Option<String>) -> std::io::Result<()> {
fn probe_protocol(protocol_name: &str, server_cmds: Vec<String>) -> std::io::Result<()> {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();

let cmd_name = match server_cmd {
Some(ref cmd) => cmd.as_str().green(),
None => "None".yellow(),
};
writeln!(stdout, "Configured {}: {}", protocol_name, cmd_name)?;
if server_cmds.is_empty() {
writeln!(stdout, "Configured {}: {}", protocol_name, "None".yellow())?;
return Ok(());
}

if let Some(cmd) = server_cmd {
let path = match which::which(&cmd) {
for server_cmd in server_cmds {
let cmd = server_cmd.as_str();
writeln!(stdout, "Configured {}: {}", protocol_name, cmd.green())?;

let path = match which::which(cmd) {
Ok(path) => path.display().to_string().green(),
Err(_) => format!("'{}' not found in $PATH", cmd).red(),
};
Expand All @@ -328,17 +344,32 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<(
Ok(())
}

pub fn print_health(health_arg: Option<String>) -> std::io::Result<()> {
match health_arg.as_deref() {
Some("languages") => languages_all()?,
Some("clipboard") => clipboard()?,
None | Some("all") => {
general()?;
clipboard()?;
writeln!(std::io::stdout().lock())?;
languages_all()?;
pub fn print_health(health_args: Vec<String>) -> std::io::Result<()> {
fn print_all() -> std::io::Result<()> {
general()?;
clipboard()?;
writeln!(std::io::stdout().lock())?;
languages_all()?;
Ok(())
}

if health_args.is_empty() {
print_all()?;
return Ok(());
}

for (idx, health_arg) in health_args.into_iter().enumerate() {
if idx != 0 {
// New line
let mut stdout = std::io::stdout().lock();
writeln!(stdout)?;
}
match health_arg.as_str() {
"languages" => languages_all()?,
"clipboard" => clipboard()?,
"all" => print_all()?,
lang => language(lang.into())?,
}
Some(lang) => language(lang.to_string())?,
}
Ok(())
}
Loading