about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-08-19 16:00:06 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-08-19 16:00:06 +0200
commit879fa66c881f1d1e0632cb3bfc6d559c042e2e72 (patch)
tree6cdca150b22314ab76459bb75112f4743b9fd5f8
parentbd6ea758cc9221dbe8cd922495b8efbbce54932a (diff)
downloadrust-879fa66c881f1d1e0632cb3bfc6d559c042e2e72.tar.gz
rust-879fa66c881f1d1e0632cb3bfc6d559c042e2e72.zip
Allow user config to not exist
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs12
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs7
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/ratoml.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs2
5 files changed, 10 insertions, 15 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
index 02a513f44b2..36907c468b0 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
@@ -794,19 +794,17 @@ impl Config {
     /// | Linux   | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config                      |
     /// | macOS   | `$HOME`/Library/Application Support   | /Users/Alice/Library/Application Support |
     /// | Windows | `{FOLDERID_RoamingAppData}`           | C:\Users\Alice\AppData\Roaming           |
-    pub fn user_config_path() -> &'static AbsPath {
-        static USER_CONFIG_PATH: LazyLock<AbsPathBuf> = LazyLock::new(|| {
+    pub fn user_config_path() -> Option<&'static AbsPath> {
+        static USER_CONFIG_PATH: LazyLock<Option<AbsPathBuf>> = LazyLock::new(|| {
             let user_config_path = if let Some(path) = env::var_os("__TEST_RA_USER_CONFIG_DIR") {
                 std::path::PathBuf::from(path)
             } else {
-                dirs::config_dir()
-                    .expect("A config dir is expected to existed on all platforms ra supports.")
-                    .join("rust-analyzer")
+                dirs::config_dir()?.join("rust-analyzer")
             }
             .join("rust-analyzer.toml");
-            AbsPathBuf::assert_utf8(user_config_path)
+            Some(AbsPathBuf::assert_utf8(user_config_path))
         });
-        &USER_CONFIG_PATH
+        USER_CONFIG_PATH.as_deref()
     }
 
     pub fn same_source_root_parent_map(
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs
index 1e21249c125..8fcdfa5829a 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs
@@ -399,7 +399,7 @@ impl GlobalState {
                     .collect_vec();
 
                 for (file_id, (_change_kind, vfs_path)) in modified_ratoml_files {
-                    if vfs_path == *user_config_path {
+                    if vfs_path.as_path() == user_config_path {
                         change.change_user_config(Some(db.file_text(file_id)));
                         continue;
                     }
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
index 5b58b332df2..2b9bcf12a48 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
@@ -551,11 +551,8 @@ impl GlobalState {
 
             watchers.extend(
                 iter::once(Config::user_config_path())
-                    .chain(
-                        self.workspaces
-                            .iter()
-                            .filter_map(|ws| ws.manifest().map(ManifestPath::as_ref)),
-                    )
+                    .chain(self.workspaces.iter().map(|ws| ws.manifest().map(ManifestPath::as_ref)))
+                    .flatten()
                     .map(|glob_pattern| lsp_types::FileSystemWatcher {
                         glob_pattern: lsp_types::GlobPattern::String(glob_pattern.to_string()),
                         kind: None,
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/ratoml.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/ratoml.rs
index 478840f104e..f68b94fa66a 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/ratoml.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/ratoml.rs
@@ -77,7 +77,7 @@ impl RatomlTest {
         let mut spl = spl.into_iter();
         if let Some(first) = spl.next() {
             if first == "$$CONFIG_DIR$$" {
-                path = Config::user_config_path().to_path_buf().into();
+                path = Config::user_config_path().unwrap().to_path_buf().into();
             } else {
                 path = path.join(first);
             }
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
index 5bd27133c2c..06ce9846818 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
@@ -123,7 +123,7 @@ impl Project<'_> {
                 if config_dir_guard.is_none() {
                     config_dir_guard = Some(CONFIG_DIR_LOCK.lock());
                 }
-                let path = Config::user_config_path().join(&pth['/'.len_utf8()..]);
+                let path = Config::user_config_path().unwrap().join(&pth['/'.len_utf8()..]);
                 fs::create_dir_all(path.parent().unwrap()).unwrap();
                 fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
             } else {