diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_dot.rs | 15 | ||||
-rw-r--r-- | crates/ra_analysis/src/mock_analysis.rs | 7 | ||||
-rw-r--r-- | crates/ra_analysis/tests/test/main.rs | 8 |
3 files changed, 25 insertions, 5 deletions
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 | |||
@@ -73,6 +73,21 @@ mod tests { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | #[test] | 75 | #[test] |
76 | fn test_struct_field_completion_self() { | ||
77 | check_ref_completion( | ||
78 | r" | ||
79 | struct A { the_field: u32 } | ||
80 | impl A { | ||
81 | fn foo(self) { | ||
82 | self.<|> | ||
83 | } | ||
84 | } | ||
85 | ", | ||
86 | r#"the_field"#, | ||
87 | ); | ||
88 | } | ||
89 | |||
90 | #[test] | ||
76 | fn test_no_struct_field_completion_for_method_call() { | 91 | fn test_no_struct_field_completion_for_method_call() { |
77 | check_ref_completion( | 92 | check_ref_completion( |
78 | r" | 93 | r" |
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; | |||
4 | use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; | 4 | use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; |
5 | use ra_db::mock::FileMap; | 5 | use ra_db::mock::FileMap; |
6 | 6 | ||
7 | use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, FileRange, SourceRootId}; | 7 | use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId}; |
8 | 8 | ||
9 | /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis | 9 | /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis |
10 | /// from a set of in-memory files. | 10 | /// from a set of in-memory files. |
@@ -87,12 +87,17 @@ impl MockAnalysis { | |||
87 | let source_root = SourceRootId(0); | 87 | let source_root = SourceRootId(0); |
88 | let mut change = AnalysisChange::new(); | 88 | let mut change = AnalysisChange::new(); |
89 | change.add_root(source_root, true); | 89 | change.add_root(source_root, true); |
90 | let mut crate_graph = CrateGraph::default(); | ||
90 | for (path, contents) in self.files.into_iter() { | 91 | for (path, contents) in self.files.into_iter() { |
91 | assert!(path.starts_with('/')); | 92 | assert!(path.starts_with('/')); |
92 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | 93 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); |
93 | let file_id = file_map.add(path.clone()); | 94 | let file_id = file_map.add(path.clone()); |
95 | if path == "/lib.rs" || path == "/main.rs" { | ||
96 | crate_graph.add_crate_root(file_id); | ||
97 | } | ||
94 | change.add_file(source_root, file_id, path, Arc::new(contents)); | 98 | change.add_file(source_root, file_id, path, Arc::new(contents)); |
95 | } | 99 | } |
100 | change.set_crate_graph(crate_graph); | ||
96 | // change.set_file_resolver(Arc::new(file_map)); | 101 | // change.set_file_resolver(Arc::new(file_map)); |
97 | host.apply_change(change); | 102 | host.apply_change(change); |
98 | host | 103 | host |
diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs index 859778024..beeae1e19 100644 --- a/crates/ra_analysis/tests/test/main.rs +++ b/crates/ra_analysis/tests/test/main.rs | |||
@@ -138,14 +138,14 @@ fn test_resolve_parent_module_for_inline() { | |||
138 | fn test_resolve_crate_root() { | 138 | fn test_resolve_crate_root() { |
139 | let mock = MockAnalysis::with_files( | 139 | let mock = MockAnalysis::with_files( |
140 | " | 140 | " |
141 | //- /lib.rs | 141 | //- /bar.rs |
142 | mod foo; | 142 | mod foo; |
143 | //- /foo.rs | 143 | //- /bar/foo.rs |
144 | // emtpy <|> | 144 | // emtpy <|> |
145 | ", | 145 | ", |
146 | ); | 146 | ); |
147 | let root_file = mock.id_of("/lib.rs"); | 147 | let root_file = mock.id_of("/bar.rs"); |
148 | let mod_file = mock.id_of("/foo.rs"); | 148 | let mod_file = mock.id_of("/bar/foo.rs"); |
149 | let mut host = mock.analysis_host(); | 149 | let mut host = mock.analysis_host(); |
150 | assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); | 150 | assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); |
151 | 151 | ||