diff options
| author | Aleksey Kladov <[email protected]> | 2020-06-23 19:38:36 +0100 |
|---|---|---|
| committer | Aleksey Kladov <[email protected]> | 2020-06-23 19:38:36 +0100 |
| commit | 295c8d4f7f9ce9d3dc67e8a988914d90424c1b7e (patch) | |
| tree | a3fc00ca2a19fa1294cf93030ff0d4a8d80f647f /crates/ra_db/src | |
| parent | a34f9b7fb343114446be08c7867b699b2210710f (diff) | |
Complicate
Fixing test fallout unfortunately requires more work, we need to do
it, but let's merge something at least!
Diffstat (limited to 'crates/ra_db/src')
| -rw-r--r-- | crates/ra_db/src/fixture.rs | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index ea52ec563..20f291568 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
| @@ -74,9 +74,8 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0); | |||
| 74 | pub trait WithFixture: Default + SourceDatabaseExt + 'static { | 74 | pub 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 (_, files) = with_files(&mut db, text); | 77 | let file_id = with_single_file(&mut db, text); |
| 78 | assert!(files.len() == 1); | 78 | (db, file_id) |
| 79 | (db, files[0]) | ||
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | fn with_files(ra_fixture: &str) -> Self { | 81 | fn with_files(ra_fixture: &str) -> Self { |
| @@ -103,6 +102,52 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
| 103 | 102 | ||
| 104 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} | 103 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} |
| 105 | 104 | ||
| 105 | fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId { | ||
| 106 | let file_id = FileId(0); | ||
| 107 | let mut file_set = vfs::file_set::FileSet::default(); | ||
| 108 | file_set.insert(file_id, vfs::VfsPath::new_virtual_path("/main.rs".to_string())); | ||
| 109 | |||
| 110 | let source_root = SourceRoot::new_local(file_set); | ||
| 111 | |||
| 112 | let crate_graph = if let Some(meta) = ra_fixture.lines().find(|it| it.contains("//-")) { | ||
| 113 | let entry = Fixture::parse_single(meta.trim()); | ||
| 114 | let meta = match ParsedMeta::from(&entry) { | ||
| 115 | ParsedMeta::File(it) => it, | ||
| 116 | }; | ||
| 117 | |||
| 118 | let mut crate_graph = CrateGraph::default(); | ||
| 119 | crate_graph.add_crate_root( | ||
| 120 | file_id, | ||
| 121 | meta.edition, | ||
| 122 | meta.krate.map(|name| { | ||
| 123 | CrateName::new(&name).expect("Fixture crate name should not contain dashes") | ||
| 124 | }), | ||
| 125 | meta.cfg, | ||
| 126 | meta.env, | ||
| 127 | Default::default(), | ||
| 128 | ); | ||
| 129 | crate_graph | ||
| 130 | } else { | ||
| 131 | let mut crate_graph = CrateGraph::default(); | ||
| 132 | crate_graph.add_crate_root( | ||
| 133 | file_id, | ||
| 134 | Edition::Edition2018, | ||
| 135 | None, | ||
| 136 | CfgOptions::default(), | ||
| 137 | Env::default(), | ||
| 138 | Default::default(), | ||
| 139 | ); | ||
| 140 | crate_graph | ||
| 141 | }; | ||
| 142 | |||
| 143 | db.set_file_text(file_id, Arc::new(ra_fixture.to_string())); | ||
| 144 | db.set_file_source_root(file_id, WORKSPACE); | ||
| 145 | db.set_source_root(WORKSPACE, Arc::new(source_root)); | ||
| 146 | db.set_crate_graph(Arc::new(crate_graph)); | ||
| 147 | |||
| 148 | file_id | ||
| 149 | } | ||
| 150 | |||
| 106 | fn with_files( | 151 | fn with_files( |
| 107 | db: &mut dyn SourceDatabaseExt, | 152 | db: &mut dyn SourceDatabaseExt, |
| 108 | fixture: &str, | 153 | fixture: &str, |
