diff --git a/helix-loader/src/grammar.rs b/helix-loader/src/grammar.rs index 362d3ba09..11ddc0e4b 100644 --- a/helix-loader/src/grammar.rs +++ b/helix-loader/src/grammar.rs @@ -213,6 +213,27 @@ fn get_grammar_configs() -> Result> { Ok(grammars) } +pub fn get_grammar_names() -> Result>> { + let config: Configuration = crate::config::user_lang_config() + .context("Could not parse languages.toml")? + .try_into()?; + + let grammars = match config.grammar_selection { + Some(GrammarSelection::Only { only: selections }) => Some(selections), + Some(GrammarSelection::Except { except: rejections }) => Some( + config + .grammar + .into_iter() + .map(|grammar| grammar.grammar_id) + .filter(|id| !rejections.contains(id)) + .collect(), + ), + None => None, + }; + + Ok(grammars) +} + fn run_parallel(grammars: Vec, job: F) -> Vec<(String, Result)> where F: Fn(GrammarConfiguration) -> Result + Send + 'static + Clone, diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 180e0652c..d7e70021d 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -5,7 +5,7 @@ use crossterm::{ }; use helix_core::config::{default_lang_config, user_lang_config}; use helix_loader::grammar::load_runtime_file; -use std::io::Write; +use std::{collections::HashSet, io::Write}; #[derive(Copy, Clone)] pub enum TsFeature { @@ -134,6 +134,15 @@ pub fn clipboard() -> std::io::Result<()> { } pub fn languages_all() -> std::io::Result<()> { + languages(None) +} + +pub fn languages_selection() -> std::io::Result<()> { + let selection = helix_loader::grammar::get_grammar_names().unwrap_or_default(); + languages(selection) +} + +fn languages(selection: Option>) -> std::io::Result<()> { let stdout = std::io::stdout(); let mut stdout = stdout.lock(); @@ -196,6 +205,13 @@ pub fn languages_all() -> std::io::Result<()> { let check_binary = |cmd: Option<&str>| check_binary_with_name(cmd.map(|cmd| (cmd, cmd))); for lang in &syn_loader_conf.language { + if selection + .as_ref() + .is_some_and(|s| !s.contains(&lang.language_id)) + { + continue; + } + write!(stdout, "{}", fit(&lang.language_id))?; let mut cmds = lang.language_servers.iter().filter_map(|ls| { @@ -392,6 +408,7 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<( pub fn print_health(health_arg: Option) -> std::io::Result<()> { match health_arg.as_deref() { Some("languages") => languages_all()?, + Some("my-languages") => languages_selection()?, Some("clipboard") => clipboard()?, None | Some("all") => { general()?; diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 31ab85cff..d3c619239 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -63,8 +63,8 @@ FLAGS: -h, --help Prints help information --tutor Loads the tutorial --health [CATEGORY] Checks for potential errors in editor setup - CATEGORY can be a language or one of 'clipboard', 'languages' - or 'all'. 'all' is the default if not specified. + CATEGORY can be a language or one of 'clipboard', 'languages', + 'my-languages' or 'all'. 'all' is the default if not specified. -g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml -c, --config Specifies a file to use for configuration -v Increases logging verbosity each use for up to 3 times