aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/view_hir.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/view_hir.rs')
-rw-r--r--crates/ide/src/view_hir.rs24
1 files changed, 5 insertions, 19 deletions
diff --git a/crates/ide/src/view_hir.rs b/crates/ide/src/view_hir.rs
index e48f2cfe0..cfcfb7cfb 100644
--- a/crates/ide/src/view_hir.rs
+++ b/crates/ide/src/view_hir.rs
@@ -1,11 +1,9 @@
1use hir::{Function, Semantics}; 1use hir::{Function, Semantics};
2use hir::db::DefDatabase;
3use ide_db::base_db::FilePosition; 2use ide_db::base_db::FilePosition;
4use ide_db::RootDatabase; 3use ide_db::RootDatabase;
5use syntax::{AstNode, algo::find_node_at_offset, ast}; 4use syntax::{algo::find_node_at_offset, ast, AstNode};
6use std::fmt::Write;
7 5
8// Feature: View hir 6// Feature: View Hir
9// 7//
10// |=== 8// |===
11// | Editor | Action Name 9// | Editor | Action Name
@@ -20,20 +18,8 @@ fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
20 let sema = Semantics::new(db); 18 let sema = Semantics::new(db);
21 let source_file = sema.parse(position.file_id); 19 let source_file = sema.parse(position.file_id);
22 20
23 let function = find_node_at_offset::<ast::Fn>( 21 let function = find_node_at_offset::<ast::Fn>(source_file.syntax(), position.offset)?;
24 source_file.syntax(),
25 position.offset,
26 )?;
27 22
28 let function: Function = sema.to_def(&function)?; 23 let function: Function = sema.to_def(&function)?;
29 let body = db.body(function.id.into()); 24 Some(function.debug_hir(db))
30 25}
31 let mut result = String::new();
32 writeln!(&mut result, "== Body expressions ==").ok()?;
33
34 for (id, expr) in body.exprs.iter() {
35 writeln!(&mut result, "{:?}: {:?}", id, expr).ok()?;
36 }
37
38 Some(result)
39} \ No newline at end of file