Skip to content

Commit

Permalink
Use TsFeature from xtask for --health
Browse files Browse the repository at this point in the history
  • Loading branch information
sudormrfbin committed Mar 1, 2022
1 parent 91e0773 commit 0a369c0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 57 deletions.
66 changes: 50 additions & 16 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@ use helix_core::{
syntax::load_runtime_file,
};

#[derive(Copy, Clone)]
pub enum TsFeature {
Highlight,
TextObject,
AutoIndent,
}

impl TsFeature {
pub fn all() -> &'static [Self] {
&[Self::Highlight, Self::TextObject, Self::AutoIndent]
}

pub fn runtime_filename(&self) -> &'static str {
match *self {
Self::Highlight => "highlights.scm",
Self::TextObject => "textobjects.scm",
Self::AutoIndent => "indents.toml",
}
}

pub fn long_title(&self) -> &'static str {
match *self {
Self::Highlight => "Syntax Highlighting",
Self::TextObject => "Treesitter Textobjects",
Self::AutoIndent => "Auto Indent",
}
}

pub fn short_title(&self) -> &'static str {
match *self {
Self::Highlight => "Highlight",
Self::TextObject => "Textobject",
Self::AutoIndent => "Indent",
}
}
}

/// Display general diagnostics.
pub fn general() {
let config_file = helix_core::config_file();
Expand Down Expand Up @@ -43,14 +80,11 @@ pub fn languages_all() {
default_syntax_loader()
});

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

for feat in TsFeature::all() {
headings.push(feat.short_title())
}

let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80);
let column_width = terminal_cols as usize / headings.len();
Expand Down Expand Up @@ -99,8 +133,8 @@ pub fn languages_all() {
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() {
for ts_feat in TsFeature::all() {
match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() {
true => column("Found", Color::Green),
false => column("Not Found", Color::Red),
}
Expand Down Expand Up @@ -154,9 +188,9 @@ pub fn language(lang_str: String) {
lang.debugger.as_ref().map(|dap| dap.command.to_string()),
);

probe_treesitter_feature(&lang_str, "Highlight", "highlights.scm");
probe_treesitter_feature(&lang_str, "Textobject", "textobjects.scm");
probe_treesitter_feature(&lang_str, "Indent", "indents.toml");
for ts_feat in TsFeature::all() {
probe_treesitter_feature(&lang_str, *ts_feat)
}
}

/// Display diagnostics about LSP and DAP.
Expand All @@ -178,10 +212,10 @@ fn probe_protocol(protocol_name: &str, server_cmd: Option<String>) {

/// Display diagnostics about a feature that requires tree-sitter
/// query files (highlights, textobjects, etc).
fn probe_treesitter_feature(lang: &str, feature: &str, query_filename: &str) {
let found = match load_runtime_file(lang, query_filename).is_ok() {
fn probe_treesitter_feature(lang: &str, feature: TsFeature) {
let found = match load_runtime_file(lang, feature.runtime_filename()).is_ok() {
true => "Found".green(),
false => "Not found".red(),
};
println!("{} queries: {}", feature, found);
println!("{} queries: {}", feature.short_title(), found);
}
46 changes: 5 additions & 41 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,11 @@ use std::{env, error::Error};
type DynError = Box<dyn Error>;

pub mod helpers {
use std::{
fmt::Display,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};

use crate::path;
use helix_core::syntax::Configuration as LangConfig;

#[derive(Copy, Clone)]
pub enum TsFeature {
Highlight,
TextObjects,
AutoIndent,
}

impl TsFeature {
pub fn all() -> &'static [Self] {
&[Self::Highlight, Self::TextObjects, Self::AutoIndent]
}

pub fn runtime_filename(&self) -> &'static str {
match *self {
Self::Highlight => "highlights.scm",
Self::TextObjects => "textobjects.scm",
Self::AutoIndent => "indents.toml",
}
}
}

impl Display for TsFeature {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match *self {
Self::Highlight => "Syntax Highlighting",
Self::TextObjects => "Treesitter Textobjects",
Self::AutoIndent => "Auto Indent",
}
)
}
}
use helix_term::health::TsFeature;

/// Get the list of languages that support a particular tree-sitter
/// based feature.
Expand Down Expand Up @@ -108,6 +71,7 @@ pub mod md_gen {
use std::fs;

use helix_term::commands::cmd::TYPABLE_COMMAND_LIST;
use helix_term::health::TsFeature;

pub const TYPABLE_COMMANDS_MD_OUTPUT: &str = "typable-cmd.md";
pub const LANG_SUPPORT_MD_OUTPUT: &str = "lang-support.md";
Expand Down Expand Up @@ -151,13 +115,13 @@ pub mod md_gen {

pub fn lang_features() -> Result<String, DynError> {
let mut md = String::new();
let ts_features = helpers::TsFeature::all();
let ts_features = TsFeature::all();

let mut cols = vec!["Language".to_owned()];
cols.append(
&mut ts_features
.iter()
.map(|t| t.to_string())
.map(|t| t.long_title().to_string())
.collect::<Vec<_>>(),
);
cols.push("Default LSP".to_owned());
Expand Down

0 comments on commit 0a369c0

Please # to comment.