Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/semantics.rs')
-rw-r--r--crates/hir/src/semantics.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 39130d1659..c0f99e09e3 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -20,7 +20,7 @@ use hir_def::{
type_ref::Mutability,
};
use hir_expand::{
- ExpandResult, FileRange, InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt,
+ ExpandResult, FileRange, HirFileIdExt, InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt,
attrs::collect_attrs,
builtin::{BuiltinFnLikeExpander, EagerExpander},
db::ExpandDatabase,
@@ -739,6 +739,35 @@ impl<'db> SemanticsImpl<'db> {
}
}
+ pub fn debug_hir_at(&self, token: SyntaxToken) -> Option<String> {
+ self.analyze_no_infer(&token.parent()?).and_then(|it| {
+ Some(match it.body_or_sig.as_ref()? {
+ crate::source_analyzer::BodyOrSig::Body { def, body, .. } => {
+ hir_def::expr_store::pretty::print_body_hir(
+ self.db,
+ body,
+ *def,
+ it.file_id.edition(self.db),
+ )
+ }
+ &crate::source_analyzer::BodyOrSig::VariantFields { def, .. } => {
+ hir_def::expr_store::pretty::print_variant_body_hir(
+ self.db,
+ def,
+ it.file_id.edition(self.db),
+ )
+ }
+ &crate::source_analyzer::BodyOrSig::Sig { def, .. } => {
+ hir_def::expr_store::pretty::print_signature(
+ self.db,
+ def,
+ it.file_id.edition(self.db),
+ )
+ }
+ })
+ })
+ }
+
/// Maps a node down by mapping its first and last token down.
pub fn descend_node_into_attributes<N: AstNode>(&self, node: N) -> SmallVec<[N; 1]> {
// This might not be the correct way to do this, but it works for now