aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body/tests.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-02-01 12:32:43 +0000
committerJonas Schievink <[email protected]>2021-02-03 14:33:25 +0000
commitda57f5dc17303cfd5ba318d1735c7f325f6b7130 (patch)
treee3df694209537a03437b6b041e4c3cb24c481563 /crates/hir_def/src/body/tests.rs
parent7eff6705cc1c1d4399a7c9da360d344a96df59b6 (diff)
Shortcut `block_def_map` if there's no inner items
This previously didn't work, but apparently only because of the wonky test setup
Diffstat (limited to 'crates/hir_def/src/body/tests.rs')
-rw-r--r--crates/hir_def/src/body/tests.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index da60072ce..404603360 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -43,7 +43,7 @@ fn block_def_map_at(ra_fixture: &str) -> Arc<DefMap> {
43 let mut block = 43 let mut block =
44 block_at_pos(&db, &def_map, position).expect("couldn't find enclosing function or block"); 44 block_at_pos(&db, &def_map, position).expect("couldn't find enclosing function or block");
45 loop { 45 loop {
46 let def_map = db.block_def_map(block); 46 let def_map = db.block_def_map(block).unwrap_or_else(|| def_map.clone());
47 let new_block = block_at_pos(&db, &def_map, position); 47 let new_block = block_at_pos(&db, &def_map, position);
48 match new_block { 48 match new_block {
49 Some(new_block) => { 49 Some(new_block) => {
@@ -58,6 +58,7 @@ fn block_def_map_at(ra_fixture: &str) -> Arc<DefMap> {
58} 58}
59 59
60fn block_at_pos(db: &dyn DefDatabase, def_map: &DefMap, position: FilePosition) -> Option<BlockId> { 60fn block_at_pos(db: &dyn DefDatabase, def_map: &DefMap, position: FilePosition) -> Option<BlockId> {
61 // Find the smallest (innermost) function containing the cursor.
61 let mut size = None; 62 let mut size = None;
62 let mut fn_def = None; 63 let mut fn_def = None;
63 for (_, module) in def_map.modules() { 64 for (_, module) in def_map.modules() {
@@ -73,7 +74,6 @@ fn block_at_pos(db: &dyn DefDatabase, def_map: &DefMap, position: FilePosition)
73 let ast = ast_map.get(item_tree[it.lookup(db).id.value].ast_id).to_node(&root); 74 let ast = ast_map.get(item_tree[it.lookup(db).id.value].ast_id).to_node(&root);
74 let range = ast.syntax().text_range(); 75 let range = ast.syntax().text_range();
75 76
76 // Find the smallest (innermost) function containing the cursor.
77 if !range.contains(position.offset) { 77 if !range.contains(position.offset) {
78 continue; 78 continue;
79 } 79 }