Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Mar 5, 2022
1 parent 7633c5a commit 4a33837
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
27 changes: 17 additions & 10 deletions helix-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ pub fn default_lang_config() -> toml::Value {

/// User configured languages.toml file, merged with the default config.
pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
let def_lang_conf = default_lang_config();
let data = std::fs::read(crate::config_dir().join("languages.toml"));
let user_lang_conf = match data {
Ok(raw) => {
let value = toml::from_slice(&raw)?;
merge_toml_values(def_lang_conf, value)
}
Err(_) => def_lang_conf,
};
let default_config = default_lang_config();
let config = crate::local_config_dirs()
.into_iter()
.map(|path| path.join("languages.toml"))
.chain([crate::config_dir().join("languages.toml")].into_iter())
.filter_map(|file| {
std::fs::read(&file)
.map(|config| toml::from_slice(&config))
.ok()
})
.flatten()
.chain([default_config].into_iter())
.fold(
toml::Value::Table(toml::value::Table::default()),
|a, b| merge_toml_values(b, a),
);

Ok(user_lang_conf)
Ok(config)
}

/// Syntax configuration loader based on built-in languages.toml.
Expand Down
20 changes: 17 additions & 3 deletions helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> {
/// * Top-most folder containing a root marker if not git repository detected
/// * Current working directory as fallback
pub fn find_root(root: Option<&str>, root_markers: &[String]) -> Option<std::path::PathBuf> {
find_root_impl(root, root_markers).first().cloned()
}

fn find_root_impl(root: Option<&str>, root_markers: &[String]) -> Vec<std::path::PathBuf> {
let current_dir = std::env::current_dir().expect("unable to determine current directory");
let mut directories = Vec::new();

let root = match root {
Some(root) => {
Expand All @@ -73,16 +78,18 @@ pub fn find_root(root: Option<&str>, root_markers: &[String]) -> Option<std::pat
// don't go higher than repo
if ancestor.join(".git").is_dir() {
// Use workspace if detected from marker
return Some(top_marker.unwrap_or(ancestor).to_path_buf());
directories.push(top_marker.unwrap_or(ancestor).to_path_buf());
}
}

// In absence of git repo, use workspace if detected
if top_marker.is_some() {
top_marker.map(|a| a.to_path_buf())
directories.push(top_marker.map(|a| a.to_path_buf()).unwrap())
} else {
Some(current_dir)
directories.push(current_dir)
}

directories
}

pub fn runtime_dir() -> std::path::PathBuf {
Expand Down Expand Up @@ -116,6 +123,13 @@ pub fn config_dir() -> std::path::PathBuf {
path
}

pub fn local_config_dirs() -> Vec<std::path::PathBuf> {
find_root_impl(None, &[".helix".to_string()])
.into_iter()
.map(|path| path.join(".helix"))
.collect()
}

pub fn cache_dir() -> std::path::PathBuf {
// TODO: allow env var override
let strategy = choose_base_strategy().expect("Unable to find the config directory!");
Expand Down
11 changes: 5 additions & 6 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ pub struct Application {
impl Application {
pub fn new(args: Args, mut config: Config) -> Result<Self, Error> {
use helix_view::editor::Action;
let mut compositor = Compositor::new()?;
let size = compositor.size();

let conf_dir = helix_core::config_dir();

let config_dir = helix_core::config_dir();

let theme_loader =
std::sync::Arc::new(theme::Loader::new(&conf_dir, &helix_core::runtime_dir()));
std::sync::Arc::new(theme::Loader::new(&config_dir, &helix_core::runtime_dir()));

// load default and user config, and merge both
let true_color = config.editor.true_color || crate::true_color();
Expand Down Expand Up @@ -99,8 +97,9 @@ impl Application {
});
let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf));

let mut compositor = Compositor::new()?;
let mut editor = Editor::new(
size,
compositor.size(),
theme_loader.clone(),
syn_loader.clone(),
config.editor.clone(),
Expand Down

0 comments on commit 4a33837

Please sign in to comment.