on 376c19e help sign in
helix/xtask/src/helpers.rs
44 lines 1.4 kB history raw
1use std::path::{Path, PathBuf};
3use crate::path;
4use helix_core::syntax::Configuration as LangConfig;
5use helix_term::health::TsFeature;
7/// Get the list of languages that support a particular tree-sitter
8/// based feature.
9pub fn ts_lang_support(feat: TsFeature) -> Vec<String> {
10 let queries_dir = path::ts_queries();
12 find_files(&queries_dir, feat.runtime_filename())
13 .iter()
14 .map(|f| {
15 // .../helix/runtime/queries/python/highlights.scm
16 let tail = f.strip_prefix(&queries_dir).unwrap(); // python/highlights.scm
17 let lang = tail.components().next().unwrap(); // python
18 lang.as_os_str().to_string_lossy().to_string()
19 })
20 .collect()
23// naive implementation, but suffices for our needs
24pub fn find_files(dir: &Path, filename: &str) -> Vec<PathBuf> {
25 std::fs::read_dir(dir)
26 .unwrap()
27 .filter_map(|entry| {
28 let path = entry.ok()?.path();
29 if path.is_dir() {
30 Some(find_files(&path, filename))
31 } else if path.file_name()?.to_string_lossy() == filename {
32 Some(vec![path])
33 } else {
34 None
35 }
36 })
37 .flatten()
38 .collect()
41pub fn lang_config() -> LangConfig {
42 let text = std::fs::read_to_string(path::lang_config()).unwrap();
43 toml::from_str(&text).unwrap()