mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Add an HIR pretty-printer
This commit is contained in:
parent
b6d59f2bb4
commit
dcbe892d7c
12 changed files with 914 additions and 203 deletions
|
@ -1,4 +1,4 @@
|
|||
use hir::{Function, Semantics};
|
||||
use hir::{DefWithBody, Semantics};
|
||||
use ide_db::base_db::FilePosition;
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||
|
@ -19,8 +19,12 @@ fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
|
|||
let sema = Semantics::new(db);
|
||||
let source_file = sema.parse(position.file_id);
|
||||
|
||||
let function = find_node_at_offset::<ast::Fn>(source_file.syntax(), position.offset)?;
|
||||
|
||||
let function: Function = sema.to_def(&function)?;
|
||||
Some(function.debug_hir(db))
|
||||
let item = find_node_at_offset::<ast::Item>(source_file.syntax(), position.offset)?;
|
||||
let def: DefWithBody = match item {
|
||||
ast::Item::Fn(it) => sema.to_def(&it)?.into(),
|
||||
ast::Item::Const(it) => sema.to_def(&it)?.into(),
|
||||
ast::Item::Static(it) => sema.to_def(&it)?.into(),
|
||||
_ => return None,
|
||||
};
|
||||
Some(def.debug_hir(db))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue