Skip to content

Commit 145bad4

Browse files
committed
Auto merge of rust-lang#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 rust-lang#7755
2 parents 732eb9a + 1ee8fef commit 145bad4

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

crates/rust-analyzer/src/config.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,22 @@ impl Config {
697697
match self.data.linkedProjects.as_slice() {
698698
[] => match self.discovered_projects.as_ref() {
699699
Some(discovered_projects) => {
700-
discovered_projects.iter().cloned().map(LinkedProject::from).collect()
700+
let exclude_dirs: Vec<_> = self
701+
.data
702+
.files_excludeDirs
703+
.iter()
704+
.map(|p| self.root_path.join(p))
705+
.collect();
706+
discovered_projects
707+
.iter()
708+
.filter(|p| {
709+
let (ProjectManifest::ProjectJson(path)
710+
| ProjectManifest::CargoToml(path)) = p;
711+
!exclude_dirs.iter().any(|p| path.starts_with(p))
712+
})
713+
.cloned()
714+
.map(LinkedProject::from)
715+
.collect()
701716
}
702717
None => Vec::new(),
703718
},

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

+39-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use lsp_types::{
2020
notification::DidOpenTextDocument,
2121
request::{
2222
CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest,
23-
WillRenameFiles,
23+
WillRenameFiles, WorkspaceSymbol,
2424
},
2525
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
2626
DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
@@ -1056,3 +1056,41 @@ fn main() {}
10561056
}),
10571057
);
10581058
}
1059+
1060+
#[test]
1061+
fn test_exclude_config_works() {
1062+
if skip_slow_tests() {
1063+
return;
1064+
}
1065+
1066+
let server = Project::with_fixture(
1067+
r#"
1068+
//- /foo/Cargo.toml
1069+
[package]
1070+
name = "foo"
1071+
version = "0.0.0"
1072+
1073+
//- /foo/src/lib.rs
1074+
pub fn foo() {}
1075+
1076+
//- /bar/Cargo.toml
1077+
[package]
1078+
name = "bar"
1079+
version = "0.0.0"
1080+
1081+
//- /bar/src/lib.rs
1082+
pub fn bar() {}
1083+
"#,
1084+
)
1085+
.root("foo")
1086+
.root("bar")
1087+
.with_config(json!({
1088+
"files": {
1089+
"excludeDirs": ["foo", "bar"]
1090+
}
1091+
}))
1092+
.server()
1093+
.wait_until_workspace_is_loaded();
1094+
1095+
server.request::<WorkspaceSymbol>(Default::default(), json!([]));
1096+
}

0 commit comments

Comments
 (0)