diff options
Diffstat (limited to 'crates/ra_db/src/fixture.rs')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index ddf46e6c4..4f4fb4494 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -132,10 +132,17 @@ fn with_files( | |||
132 | 132 | ||
133 | let mut file_position = None; | 133 | let mut file_position = None; |
134 | 134 | ||
135 | for entry in fixture.iter() { | 135 | for entry in fixture { |
136 | let meta = match ParsedMeta::from(entry) { | 136 | let text = if entry.text.contains(CURSOR_MARKER) { |
137 | ParsedMeta::File(it) => it, | 137 | let (range_or_offset, text) = extract_range_or_offset(&entry.text); |
138 | assert!(file_position.is_none()); | ||
139 | file_position = Some((file_id, range_or_offset)); | ||
140 | text.to_string() | ||
141 | } else { | ||
142 | entry.text.clone() | ||
138 | }; | 143 | }; |
144 | |||
145 | let meta = FileMeta::from(entry); | ||
139 | assert!(meta.path.starts_with(&source_root_prefix)); | 146 | assert!(meta.path.starts_with(&source_root_prefix)); |
140 | 147 | ||
141 | if let Some(krate) = meta.krate { | 148 | if let Some(krate) = meta.krate { |
@@ -157,15 +164,6 @@ fn with_files( | |||
157 | default_crate_root = Some(file_id); | 164 | default_crate_root = Some(file_id); |
158 | } | 165 | } |
159 | 166 | ||
160 | let text = if entry.text.contains(CURSOR_MARKER) { | ||
161 | let (range_or_offset, text) = extract_range_or_offset(&entry.text); | ||
162 | assert!(file_position.is_none()); | ||
163 | file_position = Some((file_id, range_or_offset)); | ||
164 | text.to_string() | ||
165 | } else { | ||
166 | entry.text.to_string() | ||
167 | }; | ||
168 | |||
169 | db.set_file_text(file_id, Arc::new(text)); | 167 | db.set_file_text(file_id, Arc::new(text)); |
170 | db.set_file_source_root(file_id, source_root_id); | 168 | db.set_file_source_root(file_id, source_root_id); |
171 | let path = VfsPath::new_virtual_path(meta.path); | 169 | let path = VfsPath::new_virtual_path(meta.path); |
@@ -198,10 +196,6 @@ fn with_files( | |||
198 | (file_position, files) | 196 | (file_position, files) |
199 | } | 197 | } |
200 | 198 | ||
201 | enum ParsedMeta { | ||
202 | File(FileMeta), | ||
203 | } | ||
204 | |||
205 | struct FileMeta { | 199 | struct FileMeta { |
206 | path: String, | 200 | path: String, |
207 | krate: Option<String>, | 201 | krate: Option<String>, |
@@ -211,22 +205,22 @@ struct FileMeta { | |||
211 | env: Env, | 205 | env: Env, |
212 | } | 206 | } |
213 | 207 | ||
214 | impl From<&Fixture> for ParsedMeta { | 208 | impl From<Fixture> for FileMeta { |
215 | fn from(f: &Fixture) -> Self { | 209 | fn from(f: Fixture) -> FileMeta { |
216 | let mut cfg = CfgOptions::default(); | 210 | let mut cfg = CfgOptions::default(); |
217 | f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); | 211 | f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); |
218 | f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); | 212 | f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); |
219 | 213 | ||
220 | Self::File(FileMeta { | 214 | FileMeta { |
221 | path: f.path.to_owned(), | 215 | path: f.path, |
222 | krate: f.crate_name.to_owned(), | 216 | krate: f.krate, |
223 | deps: f.deps.to_owned(), | 217 | deps: f.deps, |
224 | cfg, | 218 | cfg, |
225 | edition: f | 219 | edition: f |
226 | .edition | 220 | .edition |
227 | .as_ref() | 221 | .as_ref() |
228 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), | 222 | .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), |
229 | env: Env::from(f.env.iter()), | 223 | env: Env::from(f.env.iter()), |
230 | }) | 224 | } |
231 | } | 225 | } |
232 | } | 226 | } |