Skip to content

Commit ac6b054

Browse files
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.
1 parent 0fd4fc3 commit ac6b054

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ config_data! {
8484
completion_snippets_custom: FxHashMap<String, SnippetDef> = Config::completion_snippets_default(),
8585

8686

87-
/// These directories will be ignored by rust-analyzer. They are
87+
/// These paths (file/directories) will be ignored by rust-analyzer. They are
8888
/// relative to the workspace root, and globs are not supported. You may
8989
/// also need to add the folders to Code's `files.watcherExclude`.
90-
files_excludeDirs: Vec<Utf8PathBuf> = vec![],
90+
files_exclude | files_excludeDirs: Vec<Utf8PathBuf> = vec![],
9191

9292

9393

@@ -1787,7 +1787,7 @@ impl Config {
17871787

17881788
fn discovered_projects(&self) -> Vec<ManifestOrProjectJson> {
17891789
let exclude_dirs: Vec<_> =
1790-
self.files_excludeDirs().iter().map(|p| self.root_path.join(p)).collect();
1790+
self.files_exclude().iter().map(|p| self.root_path.join(p)).collect();
17911791

17921792
let mut projects = vec![];
17931793
for fs_proj in &self.discovered_projects_from_filesystem {
@@ -1909,7 +1909,7 @@ impl Config {
19091909
}
19101910
_ => FilesWatcher::Server,
19111911
},
1912-
exclude: self.files_excludeDirs().iter().map(|it| self.root_path.join(it)).collect(),
1912+
exclude: self.files_exclude().iter().map(|it| self.root_path.join(it)).collect(),
19131913
}
19141914
}
19151915

crates/rust-analyzer/tests/slow-tests/main.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,40 @@ pub fn foo() {}
13721372
name = "bar"
13731373
version = "0.0.0"
13741374
1375+
[dependencies]
1376+
foo = { path = "../foo" }
1377+
1378+
//- /bar/src/lib.rs
1379+
"#,
1380+
)
1381+
.root("foo")
1382+
.root("bar")
1383+
.root("baz")
1384+
.with_config(json!({
1385+
"files": {
1386+
"exclude": ["foo"]
1387+
}
1388+
}))
1389+
.server()
1390+
.wait_until_workspace_is_loaded();
1391+
1392+
server.request::<WorkspaceSymbolRequest>(Default::default(), json!([]));
1393+
1394+
let server = Project::with_fixture(
1395+
r#"
1396+
//- /foo/Cargo.toml
1397+
[package]
1398+
name = "foo"
1399+
version = "0.0.0"
1400+
1401+
//- /foo/src/lib.rs
1402+
pub fn foo() {}
1403+
1404+
//- /bar/Cargo.toml
1405+
[package]
1406+
name = "bar"
1407+
version = "0.0.0"
1408+
13751409
//- /bar/src/lib.rs
13761410
pub fn bar() {}
13771411
@@ -1388,7 +1422,7 @@ version = "0.0.0"
13881422
.root("baz")
13891423
.with_config(json!({
13901424
"files": {
1391-
"excludeDirs": ["foo", "bar"]
1425+
"exclude": ["foo", "bar"]
13921426
}
13931427
}))
13941428
.server()

crates/vfs-notify/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ impl NotifyActor {
280280
return false;
281281
}
282282

283-
root == path
284-
|| dirs.exclude.iter().chain(&dirs.include).all(|it| it != path)
283+
// We want to filter out subdirectories that are roots themselves, because they will be visited separately.
284+
dirs.exclude.iter().all(|it| it != path)
285+
&& (root == path || dirs.include.iter().all(|it| it != path))
285286
});
286287

287288
let files = walkdir.filter_map(|it| it.ok()).filter_map(|entry| {

docs/book/src/configuration_generated.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ The warnings will be indicated by a blue squiggly underline in code
470470
and a blue icon in the `Problems Panel`.
471471

472472

473-
**rust-analyzer.files.excludeDirs** (default: [])
473+
**rust-analyzer.files.exclude** (default: [])
474474

475-
These directories will be ignored by rust-analyzer. They are
475+
These paths (file/directories) will be ignored by rust-analyzer. They are
476476
relative to the workspace root, and globs are not supported. You may
477477
also need to add the folders to Code's `files.watcherExclude`.
478478

editors/code/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,8 @@
14731473
{
14741474
"title": "files",
14751475
"properties": {
1476-
"rust-analyzer.files.excludeDirs": {
1477-
"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`.",
1476+
"rust-analyzer.files.exclude": {
1477+
"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`.",
14781478
"default": [],
14791479
"type": "array",
14801480
"items": {

0 commit comments

Comments
 (0)