Skip to content

Commit 879fa66

Browse files
committed
Allow user config to not exist
1 parent bd6ea75 commit 879fa66

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,19 +794,17 @@ impl Config {
794794
/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config |
795795
/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support |
796796
/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming |
797-
pub fn user_config_path() -> &'static AbsPath {
798-
static USER_CONFIG_PATH: LazyLock<AbsPathBuf> = LazyLock::new(|| {
797+
pub fn user_config_path() -> Option<&'static AbsPath> {
798+
static USER_CONFIG_PATH: LazyLock<Option<AbsPathBuf>> = LazyLock::new(|| {
799799
let user_config_path = if let Some(path) = env::var_os("__TEST_RA_USER_CONFIG_DIR") {
800800
std::path::PathBuf::from(path)
801801
} else {
802-
dirs::config_dir()
803-
.expect("A config dir is expected to existed on all platforms ra supports.")
804-
.join("rust-analyzer")
802+
dirs::config_dir()?.join("rust-analyzer")
805803
}
806804
.join("rust-analyzer.toml");
807-
AbsPathBuf::assert_utf8(user_config_path)
805+
Some(AbsPathBuf::assert_utf8(user_config_path))
808806
});
809-
&USER_CONFIG_PATH
807+
USER_CONFIG_PATH.as_deref()
810808
}
811809

812810
pub fn same_source_root_parent_map(

src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl GlobalState {
399399
.collect_vec();
400400

401401
for (file_id, (_change_kind, vfs_path)) in modified_ratoml_files {
402-
if vfs_path == *user_config_path {
402+
if vfs_path.as_path() == user_config_path {
403403
change.change_user_config(Some(db.file_text(file_id)));
404404
continue;
405405
}

src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,8 @@ impl GlobalState {
551551

552552
watchers.extend(
553553
iter::once(Config::user_config_path())
554-
.chain(
555-
self.workspaces
556-
.iter()
557-
.filter_map(|ws| ws.manifest().map(ManifestPath::as_ref)),
558-
)
554+
.chain(self.workspaces.iter().map(|ws| ws.manifest().map(ManifestPath::as_ref)))
555+
.flatten()
559556
.map(|glob_pattern| lsp_types::FileSystemWatcher {
560557
glob_pattern: lsp_types::GlobPattern::String(glob_pattern.to_string()),
561558
kind: None,

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/ratoml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl RatomlTest {
7777
let mut spl = spl.into_iter();
7878
if let Some(first) = spl.next() {
7979
if first == "$$CONFIG_DIR$$" {
80-
path = Config::user_config_path().to_path_buf().into();
80+
path = Config::user_config_path().unwrap().to_path_buf().into();
8181
} else {
8282
path = path.join(first);
8383
}

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Project<'_> {
123123
if config_dir_guard.is_none() {
124124
config_dir_guard = Some(CONFIG_DIR_LOCK.lock());
125125
}
126-
let path = Config::user_config_path().join(&pth['/'.len_utf8()..]);
126+
let path = Config::user_config_path().unwrap().join(&pth['/'.len_utf8()..]);
127127
fs::create_dir_all(path.parent().unwrap()).unwrap();
128128
fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
129129
} else {

0 commit comments

Comments
 (0)