From 0ad13b9477fc6b15cbfbd521a79ea97bc0e79953 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 30 Dec 2018 00:03:52 +0100 Subject: Add a test for self field completion Needed to add a default crate graph in the analysis for that. --- crates/ra_analysis/src/completion/complete_dot.rs | 15 +++++++++++++++ crates/ra_analysis/src/mock_analysis.rs | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs index f24835d17..031d8b98f 100644 --- a/crates/ra_analysis/src/completion/complete_dot.rs +++ b/crates/ra_analysis/src/completion/complete_dot.rs @@ -72,6 +72,21 @@ mod tests { ); } + #[test] + fn test_struct_field_completion_self() { + check_ref_completion( + r" + struct A { the_field: u32 } + impl A { + fn foo(self) { + self.<|> + } + } + ", + r#"the_field"#, + ); + } + #[test] fn test_no_struct_field_completion_for_method_call() { check_ref_completion( diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 960529404..846c76cfe 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -4,7 +4,7 @@ use relative_path::RelativePathBuf; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; use ra_db::mock::FileMap; -use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, FileRange, SourceRootId}; +use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId}; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -87,12 +87,17 @@ impl MockAnalysis { let source_root = SourceRootId(0); let mut change = AnalysisChange::new(); change.add_root(source_root, true); + let mut crate_graph = CrateGraph::default(); for (path, contents) in self.files.into_iter() { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let file_id = file_map.add(path.clone()); + if path == "/lib.rs" || path == "/main.rs" { + crate_graph.add_crate_root(file_id); + } 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