diff options
| author | bors <bors@rust-lang.org> | 2022-05-27 12:35:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-27 12:35:48 +0000 |
| commit | 145bad473d048181affade57c3bec0e79af31d2e (patch) | |
| tree | 636e60c3f514fccc3782e65acf7b157ecbf750fa | |
| parent | 732eb9a16799ea04331d99d4f9040d58e70edda7 (diff) | |
| parent | 1ee8fefcff6d60652945c63c485ba55b5e2bf581 (diff) | |
| download | rust-145bad473d048181affade57c3bec0e79af31d2e.tar.gz rust-145bad473d048181affade57c3bec0e79af31d2e.zip | |
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 110575e85cb..c347913fb2f 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 5bb925f62be..6d2788d337d 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!([])); +} |
