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: 01d412f4d7/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:
commit
145bad473d
@ -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(),
|
||||
},
|
||||
|
@ -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!([]));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user