Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make rust-analyzer.files.excludeDirs work, actually #18998

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ config_data! {
completion_snippets_custom: FxHashMap<String, SnippetDef> = 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<Utf8PathBuf> = vec![],
files_exclude | files_excludeDirs: Vec<Utf8PathBuf> = vec![],



Expand Down Expand Up @@ -1781,7 +1781,7 @@ impl Config {

fn discovered_projects(&self) -> Vec<ManifestOrProjectJson> {
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 {
Expand Down Expand Up @@ -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(),
}
}

Expand Down
36 changes: 35 additions & 1 deletion crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<WorkspaceSymbolRequest>(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() {}

Expand All @@ -1388,7 +1422,7 @@ version = "0.0.0"
.root("baz")
.with_config(json!({
"files": {
"excludeDirs": ["foo", "bar"]
"exclude": ["foo", "bar"]
}
}))
.server()
Expand Down
5 changes: 3 additions & 2 deletions crates/vfs-notify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
4 changes: 2 additions & 2 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
--
Expand Down
4 changes: 2 additions & 2 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading