aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-23 23:48:38 +0100
committerAleksey Kladov <[email protected]>2020-06-23 23:48:38 +0100
commitd016cb486738c1ab2574a322924183fa8a870b06 (patch)
tree841871b66bc008a18a5a1053f5a33415c3a54ad9 /crates/ra_db/src
parente5101ae150db5faa7ddf8393e375032ef371f5e5 (diff)
Use only one code-path for parsing fixtures
This removes leading newlines everywhere, shifting all ranges in tests by one
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r--crates/ra_db/src/fixture.rs51
1 files changed, 3 insertions, 48 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 541815fe7..ddf46e6c4 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -74,8 +74,9 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
74pub trait WithFixture: Default + SourceDatabaseExt + 'static { 74pub trait WithFixture: Default + SourceDatabaseExt + 'static {
75 fn with_single_file(text: &str) -> (Self, FileId) { 75 fn with_single_file(text: &str) -> (Self, FileId) {
76 let mut db = Self::default(); 76 let mut db = Self::default();
77 let file_id = with_single_file(&mut db, text); 77 let (_, files) = with_files(&mut db, text);
78 (db, file_id) 78 assert_eq!(files.len(), 1);
79 (db, files[0])
79 } 80 }
80 81
81 fn with_files(ra_fixture: &str) -> Self { 82 fn with_files(ra_fixture: &str) -> Self {
@@ -112,52 +113,6 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
112 113
113impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} 114impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {}
114 115
115fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId {
116 let file_id = FileId(0);
117 let mut file_set = vfs::file_set::FileSet::default();
118 file_set.insert(file_id, vfs::VfsPath::new_virtual_path("/main.rs".to_string()));
119
120 let source_root = SourceRoot::new_local(file_set);
121
122 let crate_graph = if let Some(meta) = ra_fixture.lines().find(|it| it.contains("//-")) {
123 let entry = Fixture::parse_meta_line(meta.trim());
124 let meta = match ParsedMeta::from(&entry) {
125 ParsedMeta::File(it) => it,
126 };
127
128 let mut crate_graph = CrateGraph::default();
129 crate_graph.add_crate_root(
130 file_id,
131 meta.edition,
132 meta.krate.map(|name| {
133 CrateName::new(&name).expect("Fixture crate name should not contain dashes")
134 }),
135 meta.cfg,
136 meta.env,
137 Default::default(),
138 );
139 crate_graph
140 } else {
141 let mut crate_graph = CrateGraph::default();
142 crate_graph.add_crate_root(
143 file_id,
144 Edition::Edition2018,
145 None,
146 CfgOptions::default(),
147 Env::default(),
148 Default::default(),
149 );
150 crate_graph
151 };
152
153 db.set_file_text(file_id, Arc::new(ra_fixture.to_string()));
154 db.set_file_source_root(file_id, WORKSPACE);
155 db.set_source_root(WORKSPACE, Arc::new(source_root));
156 db.set_crate_graph(Arc::new(crate_graph));
157
158 file_id
159}
160
161fn with_files( 116fn with_files(
162 db: &mut dyn SourceDatabaseExt, 117 db: &mut dyn SourceDatabaseExt,
163 fixture: &str, 118 fixture: &str,