@@ -2,11 +2,28 @@ pub mod config;
2pub mod grammar;
2pub mod grammar;
4use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
4use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
5+use std::path::PathBuf;
6−pub static RUNTIME_DIR: once_cell::sync::Lazy<std::path::PathBuf> =
7+pub static RUNTIME_DIR: once_cell::sync::Lazy<PathBuf> = once_cell::sync::Lazy::new(runtime_dir);
7− once_cell::sync::Lazy::new(runtime_dir);
9+static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
11+pub fn initialize_config_file(specified_file: Option<PathBuf>) {
12+ let config_file = specified_file.unwrap_or_else(|| {
13+ let config_dir = config_dir();
15+ if !config_dir.exists() {
16+ std::fs::create_dir_all(&config_dir).ok();
19+ config_dir.join("config.toml")
22+ // We should only initialize this value once.
23+ CONFIG_FILE.set(config_file).ok();
9−pub fn runtime_dir() -> std::path::PathBuf {
26+pub fn runtime_dir() -> PathBuf {
10 if let Ok(dir) = std::env::var("HELIX_RUNTIME") {
27 if let Ok(dir) = std::env::var("HELIX_RUNTIME") {
11 return dir.into();
28 return dir.into();
@@ -31,7 +48,7 @@ pub fn runtime_dir() -> std::path::PathBuf {
34−pub fn config_dir() -> std::path::PathBuf {
51+pub fn config_dir() -> PathBuf {
35 // TODO: allow env var override
52 // TODO: allow env var override
36 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
53 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
37 let mut path = strategy.config_dir();
54 let mut path = strategy.config_dir();
@@ -39,7 +56,7 @@ pub fn config_dir() -> std::path::PathBuf {
42−pub fn local_config_dirs() -> Vec<std::path::PathBuf> {
59+pub fn local_config_dirs() -> Vec<PathBuf> {
43 let directories = find_root_impl(None, &[".helix".to_string()])
60 let directories = find_root_impl(None, &[".helix".to_string()])
44 .into_iter()
61 .into_iter()
45 .map(|path| path.join(".helix"))
62 .map(|path| path.join(".helix"))
@@ -48,7 +65,7 @@ pub fn local_config_dirs() -> Vec<std::path::PathBuf> {
48 directories
65 directories
51−pub fn cache_dir() -> std::path::PathBuf {
68+pub fn cache_dir() -> PathBuf {
52 // TODO: allow env var override
69 // TODO: allow env var override
53 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
70 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
54 let mut path = strategy.cache_dir();
71 let mut path = strategy.cache_dir();
@@ -56,19 +73,22 @@ pub fn cache_dir() -> std::path::PathBuf {
59−pub fn config_file() -> std::path::PathBuf {
76+pub fn config_file() -> PathBuf {
79+ .map(|path| path.to_path_buf())
60− config_dir().join("config.toml")
80+ .unwrap_or_else(|| config_dir().join("config.toml"))
63−pub fn lang_config_file() -> std::path::PathBuf {
83+pub fn lang_config_file() -> PathBuf {
64 config_dir().join("languages.toml")
84 config_dir().join("languages.toml")
67−pub fn log_file() -> std::path::PathBuf {
87+pub fn log_file() -> PathBuf {
68 cache_dir().join("helix.log")
88 cache_dir().join("helix.log")
71−pub fn find_root_impl(root: Option<&str>, root_markers: &[String]) -> Vec<std::path::PathBuf> {
91+pub fn find_root_impl(root: Option<&str>, root_markers: &[String]) -> Vec<PathBuf> {
72 let current_dir = std::env::current_dir().expect("unable to determine current directory");
92 let current_dir = std::env::current_dir().expect("unable to determine current directory");
73 let mut directories = Vec::new();
93 let mut directories = Vec::new();