aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-05-09 19:25:10 +0100
committerveetaha <[email protected]>2020-05-09 19:26:59 +0100
commita42729a59d8874f03482275d13010456718d4ad9 (patch)
tree0d116d14bec312f35d6592bfef796d6ce6eba001
parent9970dd316b7e6b2d198dee7318c989fb312c6f5f (diff)
Simplify crate graph creation
-rw-r--r--crates/rust-analyzer/src/world.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 16020648d..6333c15b2 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -137,15 +137,6 @@ impl WorldState {
137 opts 137 opts
138 }; 138 };
139 139
140 // Create crate graph from all the workspaces
141 let mut crate_graph = CrateGraph::default();
142 let mut load = |path: &std::path::Path| {
143 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
144 let path = path.canonicalize().ok()?;
145 let vfs_file = vfs.load(&path);
146 vfs_file.map(|f| FileId(f.0))
147 };
148
149 let proc_macro_client = match &config.proc_macro_srv { 140 let proc_macro_client = match &config.proc_macro_srv {
150 None => ProcMacroClient::dummy(), 141 None => ProcMacroClient::dummy(),
151 Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) { 142 Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) {
@@ -161,19 +152,22 @@ impl WorldState {
161 }, 152 },
162 }; 153 };
163 154
164 workspaces 155 // Create crate graph from all the workspaces
165 .iter() 156 let mut crate_graph = CrateGraph::default();
166 .map(|ws| { 157 let mut load = |path: &Path| {
167 ws.to_crate_graph( 158 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
168 &default_cfg_options, 159 let path = path.canonicalize().ok()?;
169 &extern_source_roots, 160 let vfs_file = vfs.load(&path);
170 &proc_macro_client, 161 vfs_file.map(|f| FileId(f.0))
171 &mut load, 162 };
172 ) 163 for ws in workspaces.iter() {
173 }) 164 crate_graph.extend(ws.to_crate_graph(
174 .for_each(|graph| { 165 &default_cfg_options,
175 crate_graph.extend(graph); 166 &extern_source_roots,
176 }); 167 &proc_macro_client,
168 &mut load,
169 ));
170 }
177 change.set_crate_graph(crate_graph); 171 change.set_crate_graph(crate_graph);
178 172
179 let flycheck = config.check.as_ref().and_then(|c| create_flycheck(&workspaces, c)); 173 let flycheck = config.check.as_ref().and_then(|c| create_flycheck(&workspaces, c));