Skip to content

Commit 7960c8b

Browse files
committed
restore index-based gotodef
1 parent 84f2509 commit 7960c8b

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

crates/ra_analysis/src/imp.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl AnalysisImpl {
214214
{
215215
let scope = fn_descr.scope(&*self.db);
216216
// 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) {
218218
let mut vec = vec![];
219219
vec.push((
220220
position.file_id,
@@ -224,12 +224,11 @@ impl AnalysisImpl {
224224
kind: NAME,
225225
},
226226
));
227-
Ok(vec)
228-
} else {
229-
// If that fails try the index based approach.
230-
self.index_resolve(name_ref)
227+
return Ok(vec);
231228
};
232229
}
230+
// If that fails try the index based approach.
231+
return self.index_resolve(name_ref);
233232
}
234233
if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) {
235234
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {

crates/ra_analysis/tests/tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) {
1818
analysis.resolve_callable(position).unwrap().unwrap()
1919
}
2020

21+
#[test]
22+
fn 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+
2138
#[test]
2239
fn test_resolve_module() {
2340
let (analysis, pos) = analysis_and_position(

0 commit comments

Comments
 (0)