From d016cb486738c1ab2574a322924183fa8a870b06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 00:48:38 +0200 Subject: Use only one code-path for parsing fixtures This removes leading newlines everywhere, shifting all ranges in tests by one --- crates/ra_db/src/fixture.rs | 51 +++------------------------------------------ 1 file changed, 3 insertions(+), 48 deletions(-) (limited to 'crates/ra_db/src/fixture.rs') 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); pub trait WithFixture: Default + SourceDatabaseExt + 'static { fn with_single_file(text: &str) -> (Self, FileId) { let mut db = Self::default(); - let file_id = with_single_file(&mut db, text); - (db, file_id) + let (_, files) = with_files(&mut db, text); + assert_eq!(files.len(), 1); + (db, files[0]) } fn with_files(ra_fixture: &str) -> Self { @@ -112,52 +113,6 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { impl WithFixture for DB {} -fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId { - let file_id = FileId(0); - let mut file_set = vfs::file_set::FileSet::default(); - file_set.insert(file_id, vfs::VfsPath::new_virtual_path("/main.rs".to_string())); - - let source_root = SourceRoot::new_local(file_set); - - let crate_graph = if let Some(meta) = ra_fixture.lines().find(|it| it.contains("//-")) { - let entry = Fixture::parse_meta_line(meta.trim()); - let meta = match ParsedMeta::from(&entry) { - ParsedMeta::File(it) => it, - }; - - let mut crate_graph = CrateGraph::default(); - crate_graph.add_crate_root( - file_id, - meta.edition, - meta.krate.map(|name| { - CrateName::new(&name).expect("Fixture crate name should not contain dashes") - }), - meta.cfg, - meta.env, - Default::default(), - ); - crate_graph - } else { - let mut crate_graph = CrateGraph::default(); - crate_graph.add_crate_root( - file_id, - Edition::Edition2018, - None, - CfgOptions::default(), - Env::default(), - Default::default(), - ); - crate_graph - }; - - db.set_file_text(file_id, Arc::new(ra_fixture.to_string())); - db.set_file_source_root(file_id, WORKSPACE); - db.set_source_root(WORKSPACE, Arc::new(source_root)); - db.set_crate_graph(Arc::new(crate_graph)); - - file_id -} - fn with_files( db: &mut dyn SourceDatabaseExt, fixture: &str, -- cgit v1.2.3