Skip to content

Commit 5100f77

Browse files
bors[bot]matklad
andauthored
Merge #4723
4723: Derive local roots from Workspaces r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents ac4782e + ee181cf commit 5100f77

File tree

4 files changed

+21
-67
lines changed

4 files changed

+21
-67
lines changed

crates/ra_project_model/src/json_project.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ use std::path::PathBuf;
55
use rustc_hash::{FxHashMap, FxHashSet};
66
use serde::Deserialize;
77

8+
/// Roots and crates that compose this Rust project.
9+
#[derive(Clone, Debug, Deserialize)]
10+
pub struct JsonProject {
11+
pub(crate) roots: Vec<Root>,
12+
pub(crate) crates: Vec<Crate>,
13+
}
14+
815
/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
916
/// all roots. Roots might be nested.
1017
#[derive(Clone, Debug, Deserialize)]
@@ -57,13 +64,6 @@ pub struct Dep {
5764
pub(crate) name: String,
5865
}
5966

60-
/// Roots and crates that compose this Rust project.
61-
#[derive(Clone, Debug, Deserialize)]
62-
pub struct JsonProject {
63-
pub(crate) roots: Vec<Root>,
64-
pub(crate) crates: Vec<Crate>,
65-
}
66-
6767
#[cfg(test)]
6868
mod tests {
6969
use super::*;

crates/rust-analyzer/src/main_loop.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
164164
}
165165

166166
WorldState::new(
167-
ws_roots,
168167
workspaces,
169168
config.lru_capacity,
170169
&globs,

crates/rust-analyzer/src/world.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &FlycheckConfig) ->
5858
#[derive(Debug)]
5959
pub struct WorldState {
6060
pub config: Config,
61-
pub roots: Vec<PathBuf>,
61+
pub local_roots: Vec<PathBuf>,
6262
pub workspaces: Arc<Vec<ProjectWorkspace>>,
6363
pub analysis_host: AnalysisHost,
6464
pub vfs: Arc<RwLock<Vfs>>,
@@ -81,7 +81,6 @@ pub struct WorldSnapshot {
8181

8282
impl WorldState {
8383
pub fn new(
84-
folder_roots: Vec<PathBuf>,
8584
workspaces: Vec<ProjectWorkspace>,
8685
lru_capacity: Option<usize>,
8786
exclude_globs: &[Glob],
@@ -93,19 +92,24 @@ impl WorldState {
9392
let extern_dirs: FxHashSet<_> =
9493
workspaces.iter().flat_map(ProjectWorkspace::out_dirs).collect();
9594

95+
let mut local_roots = Vec::new();
9696
let roots: Vec<_> = {
9797
let create_filter = |is_member| {
9898
RustPackageFilterBuilder::default()
9999
.set_member(is_member)
100100
.exclude(exclude_globs.iter().cloned())
101101
.into_vfs_filter()
102102
};
103-
folder_roots
103+
workspaces
104104
.iter()
105-
.map(|path| RootEntry::new(path.clone(), create_filter(true)))
106-
.chain(workspaces.iter().flat_map(ProjectWorkspace::to_roots).map(|pkg_root| {
107-
RootEntry::new(pkg_root.path().to_owned(), create_filter(pkg_root.is_member()))
108-
}))
105+
.flat_map(ProjectWorkspace::to_roots)
106+
.map(|pkg_root| {
107+
let path = pkg_root.path().to_owned();
108+
if pkg_root.is_member() {
109+
local_roots.push(path.clone());
110+
}
111+
RootEntry::new(path, create_filter(pkg_root.is_member()))
112+
})
109113
.chain(
110114
extern_dirs
111115
.iter()
@@ -121,7 +125,7 @@ impl WorldState {
121125
let mut extern_source_roots = FxHashMap::default();
122126
for r in vfs_roots {
123127
let vfs_root_path = vfs.root2path(r);
124-
let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it));
128+
let is_local = local_roots.iter().any(|it| vfs_root_path.starts_with(it));
125129
change.add_root(SourceRootId(r.0), is_local);
126130
change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string());
127131

@@ -178,7 +182,7 @@ impl WorldState {
178182
analysis_host.apply_change(change);
179183
WorldState {
180184
config,
181-
roots: folder_roots,
185+
local_roots,
182186
workspaces: Arc::new(workspaces),
183187
analysis_host,
184188
vfs: Arc::new(RwLock::new(vfs)),
@@ -216,7 +220,7 @@ impl WorldState {
216220
match c {
217221
VfsChange::AddRoot { root, files } => {
218222
let root_path = self.vfs.read().root2path(root);
219-
let is_local = self.roots.iter().any(|r| root_path.starts_with(r));
223+
let is_local = self.local_roots.iter().any(|r| root_path.starts_with(r));
220224
if is_local {
221225
*roots_scanned += 1;
222226
for (file, path, text) in files {

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -58,55 +58,6 @@ use std::collections::Spam;
5858
eprintln!("completion took {:?}", completion_start.elapsed());
5959
}
6060

61-
#[test]
62-
fn test_runnables_no_project() {
63-
if skip_slow_tests() {
64-
return;
65-
}
66-
67-
let server = project(
68-
r"
69-
//- lib.rs
70-
#[test]
71-
fn foo() {
72-
}
73-
",
74-
);
75-
server.wait_until_workspace_is_loaded();
76-
server.request::<Runnables>(
77-
RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
78-
json!([
79-
{
80-
"args": {
81-
"cargoArgs": ["test"],
82-
"executableArgs": ["foo", "--nocapture"],
83-
},
84-
"kind": "cargo",
85-
"label": "test foo",
86-
"location": {
87-
"targetRange": {
88-
"end": { "character": 1, "line": 2 },
89-
"start": { "character": 0, "line": 0 }
90-
},
91-
"targetSelectionRange": {
92-
"end": { "character": 6, "line": 1 },
93-
"start": { "character": 3, "line": 1 }
94-
},
95-
"targetUri": "file:///[..]/lib.rs"
96-
}
97-
},
98-
{
99-
"args": {
100-
"cargoArgs": ["check", "--workspace"],
101-
"executableArgs": [],
102-
},
103-
"kind": "cargo",
104-
"label": "cargo check --workspace"
105-
}
106-
]),
107-
);
108-
}
109-
11061
#[test]
11162
fn test_runnables_project() {
11263
if skip_slow_tests() {

0 commit comments

Comments
 (0)