Skip to content

Commit 2e410cc

Browse files
Make rust-analyzer.files.excludeDirs work, actually
I have no idea what the original writer of the code thought (CC @matklad, I don't expect you to remember but it was you), 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 2c040c0 commit 2e410cc

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-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

@@ -1781,7 +1781,7 @@ impl Config {
17811781

17821782
fn discovered_projects(&self) -> Vec<ManifestOrProjectJson> {
17831783
let exclude_dirs: Vec<_> =
1784-
self.files_excludeDirs().iter().map(|p| self.root_path.join(p)).collect();
1784+
self.files_exclude().iter().map(|p| self.root_path.join(p)).collect();
17851785

17861786
let mut projects = vec![];
17871787
for fs_proj in &self.discovered_projects_from_filesystem {
@@ -1903,7 +1903,7 @@ impl Config {
19031903
}
19041904
_ => FilesWatcher::Server,
19051905
},
1906-
exclude: self.files_excludeDirs().iter().map(|it| self.root_path.join(it)).collect(),
1906+
exclude: self.files_exclude().iter().map(|it| self.root_path.join(it)).collect(),
19071907
}
19081908
}
19091909

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ impl NotifyActor {
280280
return false;
281281
}
282282

283-
root == path
284-
|| dirs.exclude.iter().chain(&dirs.include).all(|it| it != path)
283+
dirs.exclude.iter().all(|it| it != path)
285284
});
286285

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

docs/user/generated_config.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ List of warnings that should be displayed with info severity.
457457
The warnings will be indicated by a blue squiggly underline in code
458458
and a blue icon in the `Problems Panel`.
459459
--
460-
[[rust-analyzer.files.excludeDirs]]rust-analyzer.files.excludeDirs (default: `[]`)::
460+
[[rust-analyzer.files.exclude]]rust-analyzer.files.exclude (default: `[]`)::
461461
+
462462
--
463-
These directories will be ignored by rust-analyzer. They are
463+
These paths (file/directories) will be ignored by rust-analyzer. They are
464464
relative to the workspace root, and globs are not supported. You may
465465
also need to add the folders to Code's `files.watcherExclude`.
466466
--

editors/code/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,8 @@
14491449
{
14501450
"title": "files",
14511451
"properties": {
1452-
"rust-analyzer.files.excludeDirs": {
1453-
"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`.",
1452+
"rust-analyzer.files.exclude": {
1453+
"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`.",
14541454
"default": [],
14551455
"type": "array",
14561456
"items": {

0 commit comments

Comments
 (0)