@@ -11,21 +11,20 @@ static RUNTIME_DIRS: once_cell::sync::Lazy<Vec<PathBuf>> =
1111
1212static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
1313
14−pub fn initialize_config_file(specified_file: Option<PathBuf>) {
15− let config_file = specified_file.unwrap_or_else(|| {
16− let config_dir = config_dir();
17−
18− if !config_dir.exists() {
19− std::fs::create_dir_all(&config_dir).ok();
20− }
14+static LOG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
2115
22− config_dir.join("config.toml")
23− });
24−
25− // We should only initialize this value once.
16+pub fn initialize_config_file(specified_file: Option<PathBuf>) {
17+ let config_file = specified_file.unwrap_or_else(default_config_file);
18+ ensure_parent_dir(&config_file);
2619 CONFIG_FILE.set(config_file).ok();
2720}
2821
22+pub fn initialize_log_file(specified_file: Option<PathBuf>) {
23+ let log_file = specified_file.unwrap_or_else(default_log_file);
24+ ensure_parent_dir(&log_file);
25+ LOG_FILE.set(log_file).ok();
26+}
27+
2928/// A list of runtime directories from highest to lowest priority
3029///
3130/// The priority is:
@@ -122,10 +121,11 @@ pub fn cache_dir() -> PathBuf {
122121}
123122
124123pub fn config_file() -> PathBuf {
125− CONFIG_FILE
126− .get()
127− .map(|path| path.to_path_buf())
128− .unwrap_or_else(|| config_dir().join("config.toml"))
124+ CONFIG_FILE.get().map(|path| path.to_path_buf()).unwrap()
125+}
126+
127+pub fn log_file() -> PathBuf {
128+ LOG_FILE.get().map(|path| path.to_path_buf()).unwrap()
129129}
130130
131131pub fn workspace_config_file() -> PathBuf {
@@ -136,7 +136,7 @@ pub fn lang_config_file() -> PathBuf {
136136 config_dir().join("languages.toml")
137137}
138138
139−pub fn log_file() -> PathBuf {
139+pub fn default_log_file() -> PathBuf {
140140 cache_dir().join("helix.log")
141141}
142142
@@ -227,6 +227,18 @@ pub fn find_workspace() -> (PathBuf, bool) {
227227 (current_dir, true)
228228}
229229
230+fn default_config_file() -> PathBuf {
231+ config_dir().join("config.toml")
232+}
233+
234+fn ensure_parent_dir(path: &Path) {
235+ if let Some(parent) = path.parent() {
236+ if !parent.exists() {
237+ std::fs::create_dir_all(parent).ok();
238+ }
239+ }
240+}
241+
230242#[cfg(test)]
231243mod merge_toml_tests {
232244 use std::str;