aboutsummaryrefslogtreecommitdiff
path: root/helix-loader
diff options
context:
space:
mode:
authorAlex Vinyals2023-07-09 14:35:07 +0000
committerGitHub2023-07-09 14:35:07 +0000
commit1698992de6a601e65a0598ed132cab5419f7e578 (patch)
tree2059076e613c872f3a20982faaf849ef7fac443f /helix-loader
parent507dd5086093f48e666c99fb509b31721f366df2 (diff)
Fix `:log-open` when `--log` is specified (#7573)
Diffstat (limited to 'helix-loader')
-rw-r--r--helix-loader/src/lib.rs44
1 files changed, 28 insertions, 16 deletions
diff --git a/helix-loader/src/lib.rs b/helix-loader/src/lib.rs
index ad4ad899..c51c9c7d 100644
--- a/helix-loader/src/lib.rs
+++ b/helix-loader/src/lib.rs
@@ -11,21 +11,20 @@ static RUNTIME_DIRS: once_cell::sync::Lazy<Vec<PathBuf>> =
static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
-pub fn initialize_config_file(specified_file: Option<PathBuf>) {
- let config_file = specified_file.unwrap_or_else(|| {
- let config_dir = config_dir();
-
- if !config_dir.exists() {
- std::fs::create_dir_all(&config_dir).ok();
- }
+static LOG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
- config_dir.join("config.toml")
- });
-
- // We should only initialize this value once.
+pub fn initialize_config_file(specified_file: Option<PathBuf>) {
+ let config_file = specified_file.unwrap_or_else(default_config_file);
+ ensure_parent_dir(&config_file);
CONFIG_FILE.set(config_file).ok();
}
+pub fn initialize_log_file(specified_file: Option<PathBuf>) {
+ let log_file = specified_file.unwrap_or_else(default_log_file);
+ ensure_parent_dir(&log_file);
+ LOG_FILE.set(log_file).ok();
+}
+
/// A list of runtime directories from highest to lowest priority
///
/// The priority is:
@@ -122,10 +121,11 @@ pub fn cache_dir() -> PathBuf {
}
pub fn config_file() -> PathBuf {
- CONFIG_FILE
- .get()
- .map(|path| path.to_path_buf())
- .unwrap_or_else(|| config_dir().join("config.toml"))
+ CONFIG_FILE.get().map(|path| path.to_path_buf()).unwrap()
+}
+
+pub fn log_file() -> PathBuf {
+ LOG_FILE.get().map(|path| path.to_path_buf()).unwrap()
}
pub fn workspace_config_file() -> PathBuf {
@@ -136,7 +136,7 @@ pub fn lang_config_file() -> PathBuf {
config_dir().join("languages.toml")
}
-pub fn log_file() -> PathBuf {
+pub fn default_log_file() -> PathBuf {
cache_dir().join("helix.log")
}
@@ -227,6 +227,18 @@ pub fn find_workspace() -> (PathBuf, bool) {
(current_dir, true)
}
+fn default_config_file() -> PathBuf {
+ config_dir().join("config.toml")
+}
+
+fn ensure_parent_dir(path: &Path) {
+ if let Some(parent) = path.parent() {
+ if !parent.exists() {
+ std::fs::create_dir_all(parent).ok();
+ }
+ }
+}
+
#[cfg(test)]
mod merge_toml_tests {
use std::str;