Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #12341 - vemoo:exclude_dirs, r=Veykril
make `files.excludeDirs` work
There's a small issue because if all projects are excluded, this: https://github.com/rust-lang/rust-analyzer/blob/01d412f4d7bd7ef21a7e8f0461e9ba3439e3c4bf/crates/rust-analyzer/src/main_loop.rs#L114 will be shown.
I thought about not showing it if `files.excludeDirs` is set, but that is not necessarily correct.
Fixes #7755
| -rw-r--r-- | crates/rust-analyzer/src/config.rs | 17 | ||||
| -rw-r--r-- | crates/rust-analyzer/tests/slow-tests/main.rs | 40 |
2 files changed, 55 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 110575e85c..c347913fb2 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -697,7 +697,22 @@ impl Config { match self.data.linkedProjects.as_slice() { [] => match self.discovered_projects.as_ref() { Some(discovered_projects) => { - discovered_projects.iter().cloned().map(LinkedProject::from).collect() + let exclude_dirs: Vec<_> = self + .data + .files_excludeDirs + .iter() + .map(|p| self.root_path.join(p)) + .collect(); + discovered_projects + .iter() + .filter(|p| { + let (ProjectManifest::ProjectJson(path) + | ProjectManifest::CargoToml(path)) = p; + !exclude_dirs.iter().any(|p| path.starts_with(p)) + }) + .cloned() + .map(LinkedProject::from) + .collect() } None => Vec::new(), }, diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 5bb925f62b..6d2788d337 100644 --- a/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs @@ -20,7 +20,7 @@ use lsp_types::{ notification::DidOpenTextDocument, request::{ CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest, - WillRenameFiles, + WillRenameFiles, WorkspaceSymbol, }, CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams, DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams, @@ -1056,3 +1056,41 @@ fn main() {} }), ); } + +#[test] +fn test_exclude_config_works() { + if skip_slow_tests() { + return; + } + + 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() {} +"#, + ) + .root("foo") + .root("bar") + .with_config(json!({ + "files": { + "excludeDirs": ["foo", "bar"] + } + })) + .server() + .wait_until_workspace_is_loaded(); + + server.request::<WorkspaceSymbol>(Default::default(), json!([])); +} |