mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Merge #7068
7068: Add VSCode command to view the hir of a function body r=theotherphil a=theotherphil Will fix https://github.com/rust-analyzer/rust-analyzer/issues/7061. Very rough initial version just to work out where I needed to wire everything up. @matklad would you be happy merging a hir visualiser of some kind? If so, do you have any thoughts on what you'd like it show, and how? I've spent very little time on this thus far, so I'm fine with throwing away the contents of this PR, but I want to avoid taking the time to make this more polished/interactive/useful only to discover that no-one else has any interest in this functionality.  Co-authored-by: Phil Ellison <phil.j.ellison@gmail.com>
This commit is contained in:
commit
1cc73d60bb
12 changed files with 143 additions and 2 deletions
|
@ -39,7 +39,7 @@ use hir_ty::{
|
|||
TyDefId, TyKind, TypeCtor,
|
||||
};
|
||||
use rustc_hash::FxHashSet;
|
||||
use stdx::impl_from;
|
||||
use stdx::{format_to, impl_from};
|
||||
use syntax::{
|
||||
ast::{self, AttrsOwner, NameOwner},
|
||||
AstNode, SmolStr,
|
||||
|
@ -797,6 +797,19 @@ impl Function {
|
|||
pub fn has_body(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).has_body
|
||||
}
|
||||
|
||||
/// A textual representation of the HIR of this function for debugging purposes.
|
||||
pub fn debug_hir(self, db: &dyn HirDatabase) -> String {
|
||||
let body = db.body(self.id.into());
|
||||
|
||||
let mut result = String::new();
|
||||
format_to!(result, "HIR expressions in the body of `{}`:\n", self.name(db));
|
||||
for (id, expr) in body.exprs.iter() {
|
||||
format_to!(result, "{:?}: {:?}\n", id, expr);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// Note: logically, this belongs to `hir_ty`, but we are not using it there yet.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue