diff options
author | Aleksey Kladov <[email protected]> | 2020-06-24 09:22:02 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-24 09:28:28 +0100 |
commit | 08e2149eab4495bd816a30b3caf586bef2cd9649 (patch) | |
tree | 26fec828b7cc8c64f80ba23c65cdd81ab3e7dc08 /crates | |
parent | c544f9a137bd675fd6e9cc4c244ff4366ededb50 (diff) |
Simplify
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 40 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 8 |
2 files changed, 21 insertions, 27 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 | } |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 7e93fbcd6..fad8f7e2c 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -8,7 +8,7 @@ use stdx::{lines_with_ends, split_delim, trim_indent}; | |||
8 | pub struct Fixture { | 8 | pub struct Fixture { |
9 | pub path: String, | 9 | pub path: String, |
10 | pub text: String, | 10 | pub text: String, |
11 | pub crate_name: Option<String>, | 11 | pub krate: Option<String>, |
12 | pub deps: Vec<String>, | 12 | pub deps: Vec<String>, |
13 | pub cfg_atoms: Vec<String>, | 13 | pub cfg_atoms: Vec<String>, |
14 | pub cfg_key_values: Vec<(String, String)>, | 14 | pub cfg_key_values: Vec<(String, String)>, |
@@ -56,7 +56,7 @@ impl Fixture { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | 58 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo |
59 | pub fn parse_meta_line(meta: &str) -> Fixture { | 59 | fn parse_meta_line(meta: &str) -> Fixture { |
60 | assert!(meta.starts_with("//-")); | 60 | assert!(meta.starts_with("//-")); |
61 | let meta = meta["//-".len()..].trim(); | 61 | let meta = meta["//-".len()..].trim(); |
62 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); | 62 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); |
@@ -98,7 +98,7 @@ impl Fixture { | |||
98 | Fixture { | 98 | Fixture { |
99 | path, | 99 | path, |
100 | text: String::new(), | 100 | text: String::new(), |
101 | crate_name: krate, | 101 | krate: krate, |
102 | deps, | 102 | deps, |
103 | cfg_atoms, | 103 | cfg_atoms, |
104 | cfg_key_values, | 104 | cfg_key_values, |
@@ -136,7 +136,7 @@ fn parse_fixture_gets_full_meta() { | |||
136 | let meta = &parsed[0]; | 136 | let meta = &parsed[0]; |
137 | assert_eq!("mod m;\n", meta.text); | 137 | assert_eq!("mod m;\n", meta.text); |
138 | 138 | ||
139 | assert_eq!("foo", meta.crate_name.as_ref().unwrap()); | 139 | assert_eq!("foo", meta.krate.as_ref().unwrap()); |
140 | assert_eq!("/lib.rs", meta.path); | 140 | assert_eq!("/lib.rs", meta.path); |
141 | assert_eq!(2, meta.env.len()); | 141 | assert_eq!(2, meta.env.len()); |
142 | } | 142 | } |