diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-03 10:08:20 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-03 10:08:20 +0100 |
commit | 5100f7707356046228eb4e0cde1f9db0d674bdd9 (patch) | |
tree | ba6b3e51ebb580184e2c44c90763efe12908904f | |
parent | ac4782ef11706c39117286ddffc3e44fb7e61888 (diff) | |
parent | ee181cf6833f338869f878eff11e026abe4e984e (diff) |
Merge #4723
4723: Derive local roots from Workspaces r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_project_model/src/json_project.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 24 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 49 |
4 files changed, 21 insertions, 67 deletions
diff --git a/crates/ra_project_model/src/json_project.rs b/crates/ra_project_model/src/json_project.rs index bd2bae15e..09c06fef9 100644 --- a/crates/ra_project_model/src/json_project.rs +++ b/crates/ra_project_model/src/json_project.rs | |||
@@ -5,6 +5,13 @@ use std::path::PathBuf; | |||
5 | use rustc_hash::{FxHashMap, FxHashSet}; | 5 | use rustc_hash::{FxHashMap, FxHashSet}; |
6 | use serde::Deserialize; | 6 | use serde::Deserialize; |
7 | 7 | ||
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 | |||
8 | /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in | 15 | /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in |
9 | /// all roots. Roots might be nested. | 16 | /// all roots. Roots might be nested. |
10 | #[derive(Clone, Debug, Deserialize)] | 17 | #[derive(Clone, Debug, Deserialize)] |
@@ -57,13 +64,6 @@ pub struct Dep { | |||
57 | pub(crate) name: String, | 64 | pub(crate) name: String, |
58 | } | 65 | } |
59 | 66 | ||
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 | |||
67 | #[cfg(test)] | 67 | #[cfg(test)] |
68 | mod tests { | 68 | mod tests { |
69 | use super::*; | 69 | use super::*; |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index f1287d52c..2e5499485 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -164,7 +164,6 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection) | |||
164 | } | 164 | } |
165 | 165 | ||
166 | WorldState::new( | 166 | WorldState::new( |
167 | ws_roots, | ||
168 | workspaces, | 167 | workspaces, |
169 | config.lru_capacity, | 168 | config.lru_capacity, |
170 | &globs, | 169 | &globs, |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 367272925..c1010e86a 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -58,7 +58,7 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &FlycheckConfig) -> | |||
58 | #[derive(Debug)] | 58 | #[derive(Debug)] |
59 | pub struct WorldState { | 59 | pub struct WorldState { |
60 | pub config: Config, | 60 | pub config: Config, |
61 | pub roots: Vec<PathBuf>, | 61 | pub local_roots: Vec<PathBuf>, |
62 | pub workspaces: Arc<Vec<ProjectWorkspace>>, | 62 | pub workspaces: Arc<Vec<ProjectWorkspace>>, |
63 | pub analysis_host: AnalysisHost, | 63 | pub analysis_host: AnalysisHost, |
64 | pub vfs: Arc<RwLock<Vfs>>, | 64 | pub vfs: Arc<RwLock<Vfs>>, |
@@ -81,7 +81,6 @@ pub struct WorldSnapshot { | |||
81 | 81 | ||
82 | impl WorldState { | 82 | impl WorldState { |
83 | pub fn new( | 83 | pub fn new( |
84 | folder_roots: Vec<PathBuf>, | ||
85 | workspaces: Vec<ProjectWorkspace>, | 84 | workspaces: Vec<ProjectWorkspace>, |
86 | lru_capacity: Option<usize>, | 85 | lru_capacity: Option<usize>, |
87 | exclude_globs: &[Glob], | 86 | exclude_globs: &[Glob], |
@@ -93,6 +92,7 @@ impl WorldState { | |||
93 | let extern_dirs: FxHashSet<_> = | 92 | let extern_dirs: FxHashSet<_> = |
94 | workspaces.iter().flat_map(ProjectWorkspace::out_dirs).collect(); | 93 | workspaces.iter().flat_map(ProjectWorkspace::out_dirs).collect(); |
95 | 94 | ||
95 | let mut local_roots = Vec::new(); | ||
96 | let roots: Vec<_> = { | 96 | let roots: Vec<_> = { |
97 | let create_filter = |is_member| { | 97 | let create_filter = |is_member| { |
98 | RustPackageFilterBuilder::default() | 98 | RustPackageFilterBuilder::default() |
@@ -100,12 +100,16 @@ impl WorldState { | |||
100 | .exclude(exclude_globs.iter().cloned()) | 100 | .exclude(exclude_globs.iter().cloned()) |
101 | .into_vfs_filter() | 101 | .into_vfs_filter() |
102 | }; | 102 | }; |
103 | folder_roots | 103 | workspaces |
104 | .iter() | 104 | .iter() |
105 | .map(|path| RootEntry::new(path.clone(), create_filter(true))) | 105 | .flat_map(ProjectWorkspace::to_roots) |
106 | .chain(workspaces.iter().flat_map(ProjectWorkspace::to_roots).map(|pkg_root| { | 106 | .map(|pkg_root| { |
107 | RootEntry::new(pkg_root.path().to_owned(), create_filter(pkg_root.is_member())) | 107 | let path = pkg_root.path().to_owned(); |
108 | })) | 108 | if pkg_root.is_member() { |
109 | local_roots.push(path.clone()); | ||
110 | } | ||
111 | RootEntry::new(path, create_filter(pkg_root.is_member())) | ||
112 | }) | ||
109 | .chain( | 113 | .chain( |
110 | extern_dirs | 114 | extern_dirs |
111 | .iter() | 115 | .iter() |
@@ -121,7 +125,7 @@ impl WorldState { | |||
121 | let mut extern_source_roots = FxHashMap::default(); | 125 | let mut extern_source_roots = FxHashMap::default(); |
122 | for r in vfs_roots { | 126 | for r in vfs_roots { |
123 | let vfs_root_path = vfs.root2path(r); | 127 | 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)); |
125 | change.add_root(SourceRootId(r.0), is_local); | 129 | change.add_root(SourceRootId(r.0), is_local); |
126 | change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string()); | 130 | change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string()); |
127 | 131 | ||
@@ -178,7 +182,7 @@ impl WorldState { | |||
178 | analysis_host.apply_change(change); | 182 | analysis_host.apply_change(change); |
179 | WorldState { | 183 | WorldState { |
180 | config, | 184 | config, |
181 | roots: folder_roots, | 185 | local_roots, |
182 | workspaces: Arc::new(workspaces), | 186 | workspaces: Arc::new(workspaces), |
183 | analysis_host, | 187 | analysis_host, |
184 | vfs: Arc::new(RwLock::new(vfs)), | 188 | vfs: Arc::new(RwLock::new(vfs)), |
@@ -216,7 +220,7 @@ impl WorldState { | |||
216 | match c { | 220 | match c { |
217 | VfsChange::AddRoot { root, files } => { | 221 | VfsChange::AddRoot { root, files } => { |
218 | let root_path = self.vfs.read().root2path(root); | 222 | 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)); |
220 | if is_local { | 224 | if is_local { |
221 | *roots_scanned += 1; | 225 | *roots_scanned += 1; |
222 | for (file, path, text) in files { | 226 | for (file, path, text) in files { |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index c80745945..69dc719c5 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -59,55 +59,6 @@ use std::collections::Spam; | |||
59 | } | 59 | } |
60 | 60 | ||
61 | #[test] | 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 | |||
110 | #[test] | ||
111 | fn test_runnables_project() { | 62 | fn test_runnables_project() { |
112 | if skip_slow_tests() { | 63 | if skip_slow_tests() { |
113 | return; | 64 | return; |