wip: documented and moved `theme::Loader::read_names` to `helix_loader::read_toml_names`

pull/11/head
LazyTanuki 1 year ago
parent 7d6b2cbbf6
commit 55de407681

@ -306,6 +306,22 @@ fn load_toml(path: &Path) -> Result<Value> {
Ok(value)
}
/// Returns the names of the TOML documents within a directory
pub fn read_toml_names(path: &Path) -> Vec<String> {
std::fs::read_dir(path)
.map(|entries| {
entries
.filter_map(|entry| {
let entry = entry.ok()?;
let path = entry.path();
(path.extension()? == "toml")
.then(|| path.file_stem().unwrap().to_string_lossy().into_owned())
})
.collect()
})
.unwrap_or_default()
}
#[cfg(test)]
mod merge_toml_tests {
use std::str;

@ -239,7 +239,6 @@ pub mod completers {
use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
use fuzzy_matcher::FuzzyMatcher;
use helix_view::document::SCRATCH_BUFFER_NAME;
use helix_view::theme;
use helix_view::{editor::Config, Editor};
use once_cell::sync::Lazy;
use std::borrow::Cow;
@ -280,9 +279,9 @@ pub mod completers {
}
pub fn theme(_editor: &Editor, input: &str) -> Vec<Completion> {
let mut names = theme::Loader::read_names(&helix_loader::config_dir().join("themes"));
let mut names = helix_loader::read_toml_names(&helix_loader::config_dir().join("themes"));
for rt_dir in helix_loader::runtime_dirs() {
names.extend(theme::Loader::read_names(&rt_dir.join("themes")));
names.extend(helix_loader::read_toml_names(&rt_dir.join("themes")));
}
names.push("default".into());
names.push("base16_default".into());

@ -1,6 +1,6 @@
use std::{
collections::{HashMap, HashSet},
path::{Path, PathBuf},
path::PathBuf,
str,
};
@ -80,21 +80,6 @@ impl Loader {
})
}
pub fn read_names(path: &Path) -> Vec<String> {
std::fs::read_dir(path)
.map(|entries| {
entries
.filter_map(|entry| {
let entry = entry.ok()?;
let path = entry.path();
(path.extension()? == "toml")
.then(|| path.file_stem().unwrap().to_string_lossy().into_owned())
})
.collect()
})
.unwrap_or_default()
}
// merge one theme into the parent theme
fn merge_themes(parent_theme_toml: Value, theme_toml: Value) -> Value {
let parent_palette = parent_theme_toml.get("palette");

@ -1,8 +1,6 @@
use crate::path;
use crate::DynError;
use helix_view::theme::Loader;
use helix_view::theme::Modifier;
use helix_view::Theme;
use helix_view::{theme::Modifier, Theme};
struct Rule {
fg: Option<&'static str>,
@ -180,7 +178,7 @@ pub fn lint(file: String) -> Result<(), DynError> {
}
pub fn lint_all() -> Result<(), DynError> {
let files = Loader::read_names(path::themes().as_path());
let files = helix_loader::read_toml_names(path::themes().as_path());
let files_count = files.len();
let ok_files_count = files
.into_iter()

Loading…
Cancel
Save