From ccef48b6c3a04b0104a68a947558994ea3e6a069 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 4 Feb 2019 21:42:37 +0100 Subject: Make it possible to have multiple crate in a mock analysis fixture --- crates/ra_ide_api/src/mock_analysis.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs index 0f2d22ab2..834b30541 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -86,17 +86,25 @@ impl MockAnalysis { let mut change = AnalysisChange::new(); change.add_root(source_root, true); let mut crate_graph = CrateGraph::default(); + let mut root_crate = None; for (i, (path, contents)) in self.files.into_iter().enumerate() { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let file_id = FileId(i as u32 + 1); if path == "/lib.rs" || path == "/main.rs" { - crate_graph.add_crate_root(file_id); + root_crate = Some(crate_graph.add_crate_root(file_id)); + } else if path.ends_with("/lib.rs") { + let other_crate = crate_graph.add_crate_root(file_id); + let crate_name = path.parent().unwrap().file_name().unwrap(); + if let Some(root_crate) = root_crate { + crate_graph + .add_dep(root_crate, crate_name.into(), other_crate) + .unwrap(); + } } change.add_file(source_root, file_id, path, Arc::new(contents)); } change.set_crate_graph(crate_graph); - // change.set_file_resolver(Arc::new(file_map)); host.apply_change(change); host } -- cgit v1.2.3 From 699ce06ac3d857c7d4eaf01c523964f01d1b35f2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 4 Feb 2019 22:09:56 +0100 Subject: Complete extern prelude (again) --- crates/ra_ide_api/src/completion/complete_scope.rs | 14 ++++++++++++++ .../snapshots/completion_item__extern_prelude.snap | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 44514ab2b..8674b1e66 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -110,6 +110,20 @@ mod tests { ); } + #[test] + fn completes_extern_prelude() { + check_reference_completion( + "extern_prelude", + r" + //- /lib.rs + use <|>; + + //- /other_crate/lib.rs + // nothing here + ", + ); + } + #[test] fn completes_module_items_in_nested_modules() { check_reference_completion( diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap new file mode 100644 index 000000000..d0e3a6188 --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap @@ -0,0 +1,22 @@ +--- +created: "2019-02-04T21:08:32.615556587+00:00" +creator: insta@0.5.3 +expression: kind_completions +source: crates/ra_ide_api/src/completion/completion_item.rs +--- +[ + CompletionItem { + completion_kind: Reference, + label: "other_crate", + kind: Some( + Module + ), + detail: None, + documentation: None, + lookup: None, + insert_text: None, + insert_text_format: PlainText, + source_range: [4; 4), + text_edit: None + } +] -- cgit v1.2.3