feat: add prettifier for Pat

This commit is contained in:
roife 2024-09-09 03:52:04 +08:00
parent 5004371a4a
commit 60c42c25c7
2 changed files with 31 additions and 0 deletions

View file

@ -227,6 +227,17 @@ impl Body {
pretty::print_expr_hir(db, self, owner, expr, edition)
}
pub fn pretty_print_pat(
&self,
db: &dyn DefDatabase,
owner: DefWithBodyId,
pat: PatId,
oneline: bool,
edition: Edition,
) -> String {
pretty::print_pat_hir(db, self, owner, pat, oneline, edition)
}
fn new(
db: &dyn DefDatabase,
owner: DefWithBodyId,

View file

@ -121,6 +121,26 @@ pub(super) fn print_expr_hir(
p.buf
}
pub(super) fn print_pat_hir(
db: &dyn DefDatabase,
body: &Body,
_owner: DefWithBodyId,
pat: PatId,
oneline: bool,
edition: Edition,
) -> String {
let mut p = Printer {
db,
body,
buf: String::new(),
indent_level: 0,
line_format: if oneline { LineFormat::Oneline } else { LineFormat::Newline },
edition,
};
p.print_pat(pat);
p.buf
}
macro_rules! w {
($dst:expr, $($arg:tt)*) => {
{ let _ = write!($dst, $($arg)*); }