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

Add --health command for troubleshooting #1669

Merged
merged 7 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Show summary for all langs with bare --health
  • Loading branch information
sudormrfbin committed Mar 1, 2022
commit 91e07734c33014153a9cb4b9af268a115f8b02cf
76 changes: 75 additions & 1 deletion helix-term/src/health.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crossterm::style::Stylize;
use crossterm::style::{Color, Print, Stylize};
use helix_core::{
config::{default_syntax_loader, user_syntax_loader},
syntax::load_runtime_file,
Expand Down Expand Up @@ -36,6 +36,80 @@ pub fn general() {
}
}

pub fn languages_all() {
let mut syn_loader_conf = user_syntax_loader().unwrap_or_else(|err| {
eprintln!("{}: {}", "Error parsing user language config".red(), err);
eprintln!("{}", "Using default language config".yellow());
default_syntax_loader()
});

let headings = &[
"Language",
"LSP",
"DAP",
"Highlight",
"Textobject",
"Indent",
];

let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80);
let column_width = terminal_cols as usize / headings.len();

let column = |item: &str, color: Color| {
let data = format!(
"{:column_width$}",
item.get(..column_width - 2)
.map(|s| format!("{s}…"))
.unwrap_or_else(|| item.to_string())
)
.stylize()
.with(color);

// We can't directly use println!() because of
// https://github.com/crossterm-rs/crossterm/issues/589
let _ = crossterm::execute!(std::io::stdout(), Print(data));
};

for heading in headings {
column(heading, Color::White);
}
println!();

syn_loader_conf
.language
.sort_unstable_by_key(|l| l.language_id.clone());

let check_binary = |cmd: Option<String>| match cmd {
Some(cmd) => match which::which(&cmd) {
Ok(_) => column(&cmd, Color::Green),
Err(_) => column(&cmd, Color::Red),
},
None => column("None", Color::Yellow),
};

for lang in &syn_loader_conf.language {
column(&lang.language_id, Color::Reset);

let lsp = lang
.language_server
.as_ref()
.map(|lsp| lsp.command.to_string());
check_binary(lsp);

let dap = lang.debugger.as_ref().map(|dap| dap.command.to_string());
check_binary(dap);

for query_filename in &["highlights.scm", "textobjects.scm", "indents.toml"] {
match load_runtime_file(&lang.language_id, query_filename).is_ok() {
true => column("Found", Color::Green),
false => column("Not Found", Color::Red),
}
}

println!();
}
}

/// Display diagnostics pertaining to a particular language (LSP,
/// highlight queries, etc).
pub fn language(lang_str: String) {
Expand Down
7 changes: 6 additions & 1 deletion helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ FLAGS:

if args.health {
if let Some(lang) = args.health_arg {
helix_term::health::language(lang);
match lang.as_str() {
"all" => helix_term::health::languages_all(),
_ => helix_term::health::language(lang),
}
} else {
helix_term::health::general();
println!();
helix_term::health::languages_all();
}
std::process::exit(0);
}
Expand Down