aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r--crates/hir/src/code_model.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 9b78944c6..f68299d3a 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -1,5 +1,5 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use std::{iter, sync::Arc}; 2use std::{fmt::Write, iter, sync::Arc};
3 3
4use arrayvec::ArrayVec; 4use arrayvec::ArrayVec;
5use base_db::{CrateDisplayName, CrateId, Edition, FileId}; 5use base_db::{CrateDisplayName, CrateId, Edition, FileId};
@@ -729,8 +729,7 @@ impl DefWithBody {
729 729
730#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 730#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
731pub struct Function { 731pub struct Function {
732 // DO NOT MERGE: this was previously pub(crate) 732 pub(crate) id: FunctionId,
733 pub id: FunctionId,
734} 733}
735 734
736impl Function { 735impl Function {
@@ -798,6 +797,19 @@ impl Function {
798 pub fn has_body(self, db: &dyn HirDatabase) -> bool { 797 pub fn has_body(self, db: &dyn HirDatabase) -> bool {
799 db.function_data(self.id).has_body 798 db.function_data(self.id).has_body
800 } 799 }
800
801 /// A textual representation of the HIR of this function for debugging purposes.
802 pub fn debug_hir(self, db: &dyn HirDatabase) -> String {
803 let body = db.body(self.id.into());
804
805 let mut result = String::new();
806 writeln!(&mut result, "HIR expressions in the body of `{}`:", self.name(db)).unwrap();
807 for (id, expr) in body.exprs.iter() {
808 writeln!(&mut result, "{:?}: {:?}", id, expr).unwrap();
809 }
810
811 result
812 }
801} 813}
802 814
803// Note: logically, this belongs to `hir_ty`, but we are not using it there yet. 815// Note: logically, this belongs to `hir_ty`, but we are not using it there yet.