mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
Complicate
Fixing test fallout unfortunately requires more work, we need to do it, but let's merge something at least!
This commit is contained in:
parent
a34f9b7fb3
commit
295c8d4f7f
2 changed files with 52 additions and 6 deletions
|
@ -74,9 +74,8 @@ 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 (_, files) = with_files(&mut db, text);
|
||||
assert!(files.len() == 1);
|
||||
(db, files[0])
|
||||
let file_id = with_single_file(&mut db, text);
|
||||
(db, file_id)
|
||||
}
|
||||
|
||||
fn with_files(ra_fixture: &str) -> Self {
|
||||
|
@ -103,6 +102,52 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
|
|||
|
||||
impl<DB: SourceDatabaseExt + Default + 'static> 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_single(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,
|
||||
|
|
|
@ -55,8 +55,7 @@ The offending line: {:?}"#,
|
|||
let mut res: Vec<Fixture> = Vec::new();
|
||||
for line in lines.by_ref() {
|
||||
if line.starts_with("//-") {
|
||||
let meta = line["//-".len()..].trim().to_string();
|
||||
let meta = Fixture::parse_single(&meta);
|
||||
let meta = Fixture::parse_single(line);
|
||||
res.push(meta)
|
||||
} else if let Some(entry) = res.last_mut() {
|
||||
entry.text.push_str(line);
|
||||
|
@ -67,7 +66,9 @@ The offending line: {:?}"#,
|
|||
}
|
||||
|
||||
//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
|
||||
fn parse_single(meta: &str) -> Fixture {
|
||||
pub fn parse_single(meta: &str) -> Fixture {
|
||||
assert!(meta.starts_with("//-"));
|
||||
let meta = meta["//-".len()..].trim();
|
||||
let components = meta.split_ascii_whitespace().collect::<Vec<_>>();
|
||||
|
||||
let path = components[0].to_string();
|
||||
|
|
Loading…
Reference in a new issue