aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/imp.rs9
-rw-r--r--crates/ra_analysis/tests/tests.rs17
2 files changed, 21 insertions, 5 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index fe1dfefea..ab6d111c2 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -214,7 +214,7 @@ impl AnalysisImpl {
214 { 214 {
215 let scope = fn_descr.scope(&*self.db); 215 let scope = fn_descr.scope(&*self.db);
216 // First try to resolve the symbol locally 216 // First try to resolve the symbol locally
217 return if let Some(entry) = scope.resolve_local_name(name_ref) { 217 if let Some(entry) = scope.resolve_local_name(name_ref) {
218 let mut vec = vec![]; 218 let mut vec = vec![];
219 vec.push(( 219 vec.push((
220 position.file_id, 220 position.file_id,
@@ -224,12 +224,11 @@ impl AnalysisImpl {
224 kind: NAME, 224 kind: NAME,
225 }, 225 },
226 )); 226 ));
227 Ok(vec) 227 return Ok(vec);
228 } else {
229 // If that fails try the index based approach.
230 self.index_resolve(name_ref)
231 }; 228 };
232 } 229 }
230 // If that fails try the index based approach.
231 return self.index_resolve(name_ref);
233 } 232 }
234 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { 233 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) {
235 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 234 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs
index fbe89f444..71d20dbe9 100644
--- a/crates/ra_analysis/tests/tests.rs
+++ b/crates/ra_analysis/tests/tests.rs
@@ -19,6 +19,23 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) {
19} 19}
20 20
21#[test] 21#[test]
22fn approximate_resolve_works_in_items() {
23 let (analysis, pos) = analysis_and_position(
24 "
25 //- /lib.rs
26 struct Foo;
27 enum E { X(Foo<|>) }
28 ",
29 );
30
31 let symbols = analysis.approximately_resolve_symbol(pos).unwrap();
32 assert_eq_dbg(
33 r#"[(FileId(1), FileSymbol { name: "Foo", node_range: [0; 11), kind: STRUCT_DEF })]"#,
34 &symbols,
35 );
36}
37
38#[test]
22fn test_resolve_module() { 39fn test_resolve_module() {
23 let (analysis, pos) = analysis_and_position( 40 let (analysis, pos) = analysis_and_position(
24 " 41 "