mirror of https://github.com/helix-editor/helix
feat: add 'my-languages' option to hx --health
`hx --health my-languages` has same output than `hx --health languages`, but shows only languages corresponding to the 'use-grammars' config.pull/13484/head
parent
2b26d27416
commit
d4e319828c
|
@ -213,6 +213,27 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
|
|||
Ok(grammars)
|
||||
}
|
||||
|
||||
pub fn get_grammar_names() -> Result<Option<HashSet<String>>> {
|
||||
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<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<(String, Result<Res>)>
|
||||
where
|
||||
F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
|
||||
|
|
|
@ -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<HashSet<String>>) -> 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<String>) -> std::io::Result<()> {
|
||||
match health_arg.as_deref() {
|
||||
Some("languages") => languages_all()?,
|
||||
Some("my-languages") => languages_selection()?,
|
||||
Some("clipboard") => clipboard()?,
|
||||
None | Some("all") => {
|
||||
general()?;
|
||||
|
|
|
@ -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 <file> Specifies a file to use for configuration
|
||||
-v Increases logging verbosity each use for up to 3 times
|
||||
|
|
Loading…
Reference in New Issue