From 5e2b6921256b1168cb0eac237665c159bcf01abd Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Wed, 22 Jan 2025 19:01:56 +0200 Subject: [PATCH] Make `rust-analyzer.files.excludeDirs` work, actually I have no idea what the original writer of the code thought but the logic just seems backwards. We should not exclude a file/directory if it is equal to an include! This also meant that we had to add a `root == path` check so this stuff will actually work, which in turn meant excludes (of root files) no longer worked... Also rename if to `rust-analyzer.files.exclude`, because it can exclude files as well. --- crates/rust-analyzer/src/config.rs | 8 ++--- crates/rust-analyzer/tests/slow-tests/main.rs | 36 ++++++++++++++++++- crates/vfs-notify/src/lib.rs | 5 +-- docs/user/generated_config.adoc | 4 +-- editors/code/package.json | 4 +-- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3dc4379258fa..d537e86defeb 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -84,10 +84,10 @@ config_data! { completion_snippets_custom: FxHashMap = Config::completion_snippets_default(), - /// These directories will be ignored by rust-analyzer. They are + /// These paths (file/directories) will be ignored by rust-analyzer. They are /// relative to the workspace root, and globs are not supported. You may /// also need to add the folders to Code's `files.watcherExclude`. - files_excludeDirs: Vec = vec![], + files_exclude | files_excludeDirs: Vec = vec![], @@ -1781,7 +1781,7 @@ impl Config { fn discovered_projects(&self) -> Vec { let exclude_dirs: Vec<_> = - self.files_excludeDirs().iter().map(|p| self.root_path.join(p)).collect(); + self.files_exclude().iter().map(|p| self.root_path.join(p)).collect(); let mut projects = vec![]; for fs_proj in &self.discovered_projects_from_filesystem { @@ -1903,7 +1903,7 @@ impl Config { } _ => FilesWatcher::Server, }, - exclude: self.files_excludeDirs().iter().map(|it| self.root_path.join(it)).collect(), + exclude: self.files_exclude().iter().map(|it| self.root_path.join(it)).collect(), } } diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 2b3c0a47a220..5ad28d0b909e 100644 --- a/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs @@ -1372,6 +1372,40 @@ pub fn foo() {} name = "bar" version = "0.0.0" +[dependencies] +foo = { path = "../foo" } + +//- /bar/src/lib.rs +"#, + ) + .root("foo") + .root("bar") + .root("baz") + .with_config(json!({ + "files": { + "exclude": ["foo"] + } + })) + .server() + .wait_until_workspace_is_loaded(); + + server.request::(Default::default(), json!([])); + + let server = Project::with_fixture( + r#" +//- /foo/Cargo.toml +[package] +name = "foo" +version = "0.0.0" + +//- /foo/src/lib.rs +pub fn foo() {} + +//- /bar/Cargo.toml +[package] +name = "bar" +version = "0.0.0" + //- /bar/src/lib.rs pub fn bar() {} @@ -1388,7 +1422,7 @@ version = "0.0.0" .root("baz") .with_config(json!({ "files": { - "excludeDirs": ["foo", "bar"] + "exclude": ["foo", "bar"] } })) .server() diff --git a/crates/vfs-notify/src/lib.rs b/crates/vfs-notify/src/lib.rs index 0ae8b7baf464..320033417640 100644 --- a/crates/vfs-notify/src/lib.rs +++ b/crates/vfs-notify/src/lib.rs @@ -280,8 +280,9 @@ impl NotifyActor { return false; } - root == path - || dirs.exclude.iter().chain(&dirs.include).all(|it| it != path) + // We want to filter out subdirectories that are roots themselves, because they will be visited separately. + dirs.exclude.iter().all(|it| it != path) + && (root == path || dirs.include.iter().all(|it| it != path)) }); let files = walkdir.filter_map(|it| it.ok()).filter_map(|entry| { diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index bd091db58d3f..501c76e02cc7 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -457,10 +457,10 @@ List of warnings that should be displayed with info severity. The warnings will be indicated by a blue squiggly underline in code and a blue icon in the `Problems Panel`. -- -[[rust-analyzer.files.excludeDirs]]rust-analyzer.files.excludeDirs (default: `[]`):: +[[rust-analyzer.files.exclude]]rust-analyzer.files.exclude (default: `[]`):: + -- -These directories will be ignored by rust-analyzer. They are +These paths (file/directories) will be ignored by rust-analyzer. They are relative to the workspace root, and globs are not supported. You may also need to add the folders to Code's `files.watcherExclude`. -- diff --git a/editors/code/package.json b/editors/code/package.json index 8b066377f2b2..e7ef50324c3c 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -1449,8 +1449,8 @@ { "title": "files", "properties": { - "rust-analyzer.files.excludeDirs": { - "markdownDescription": "These directories will be ignored by rust-analyzer. They are\nrelative to the workspace root, and globs are not supported. You may\nalso need to add the folders to Code's `files.watcherExclude`.", + "rust-analyzer.files.exclude": { + "markdownDescription": "These paths (file/directories) will be ignored by rust-analyzer. They are\nrelative to the workspace root, and globs are not supported. You may\nalso need to add the folders to Code's `files.watcherExclude`.", "default": [], "type": "array", "items": {