From adeb8d0aa9af9d4472316d74dcc0c809ac3654b6 Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:34:19 +0900 Subject: [PATCH 1/2] cli: Make init-config respect TREE_SITTER_DIR --- cli/config/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/config/src/lib.rs b/cli/config/src/lib.rs index 678688fe..27b2dfb6 100644 --- a/cli/config/src/lib.rs +++ b/cli/config/src/lib.rs @@ -81,7 +81,13 @@ impl Config { /// /// (Note that this is typically only done by the `tree-sitter init-config` command.) pub fn initial() -> Result { - let location = Self::xdg_config_file()?; + let location = if let Ok(path) = env::var("TREE_SITTER_DIR") { + let mut path = PathBuf::from(path); + path.push("config.json"); + path + } else { + Self::xdg_config_file()? + }; let config = serde_json::json!({}); Ok(Config { location, config }) } From 23ce370fa3607ab1fed4e60aebd6c0d2e6744376 Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:24:16 +0900 Subject: [PATCH 2/2] cli: Stop config.json search sooner if TREE_SITTER_DIR set --- cli/config/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/config/src/lib.rs b/cli/config/src/lib.rs index 27b2dfb6..3cd09b8d 100644 --- a/cli/config/src/lib.rs +++ b/cli/config/src/lib.rs @@ -25,6 +25,9 @@ impl Config { if let Ok(path) = env::var("TREE_SITTER_DIR") { let mut path = PathBuf::from(path); path.push("config.json"); + if !path.exists() { + return Ok(None); + } if path.is_file() { return Ok(Some(path)); }