Skip to content

Commit

Permalink
Auto merge of rust-lang#12341 - vemoo:exclude_dirs, r=Veykril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 27, 2022
2 parents 732eb9a + 1ee8fef commit 145bad4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
17 changes: 16 additions & 1 deletion crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down
40 changes: 39 additions & 1 deletion crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!([]));
}

0 comments on commit 145bad4

Please sign in to comment.