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
This commit is contained in:
bors
2022-05-27 12:35:48 +00:00
2 changed files with 55 additions and 2 deletions
+16 -1
View File
@@ -697,7 +697,22 @@ pub fn linked_projects(&self) -> Vec<LinkedProject> {
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(),
},
+39 -1
View File
@@ -20,7 +20,7 @@
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!([]));
}