Debian Codegraph @

xtask/src/helpers.rs

raw symbols SCIP
1 use std::path::{Path, PathBuf};
2
3 use crate::path;
4 use helix_term::health::TsFeature;
5
6 /// Get the list of languages that support a particular tree-sitter
7 /// based feature.
8 pub fn ts_lang_support(feat: TsFeature) -> Vec<String> {
9 let queries_dir = path::ts_queries();
10
11 find_files(&queries_dir, feat.runtime_filename())
12 .iter()
13 .map(|f| {
14 // .../helix/runtime/queries/python/highlights.scm
15 let tail = f.strip_prefix(&queries_dir).unwrap(); // python/highlights.scm
16 let lang = tail.components().next().unwrap(); // python
17 lang.as_os_str().to_string_lossy().to_string()
18 })
19 .collect()
20 }
21
22 // naive implementation, but suffices for our needs
23 pub fn find_files(dir: &Path, filename: &str) -> Vec<PathBuf> {
24 std::fs::read_dir(dir)
25 .unwrap()
26 .filter_map(|entry| {
27 let path = entry.ok()?.path();
28 if path.is_dir() {
29 Some(find_files(&path, filename))
30 } else if path.file_name()?.to_string_lossy() == filename {
31 Some(vec![path])
32 } else {
33 None
34 }
35 })
36 .flatten()
37 .collect()
38 }