Skip to content

Commit 75a0437

Browse files
committed
feat: add prettifier for Pat
1 parent d76eac2 commit 75a0437

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

crates/hir-def/src/body.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ impl Body {
227227
pretty::print_expr_hir(db, self, owner, expr, edition)
228228
}
229229

230+
pub fn pretty_print_pat(
231+
&self,
232+
db: &dyn DefDatabase,
233+
owner: DefWithBodyId,
234+
pat: PatId,
235+
oneline: bool,
236+
edition: Edition,
237+
) -> String {
238+
pretty::print_pat_hir(db, self, owner, pat, oneline, edition)
239+
}
240+
230241
fn new(
231242
db: &dyn DefDatabase,
232243
owner: DefWithBodyId,

crates/hir-def/src/body/pretty.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ pub(super) fn print_expr_hir(
121121
p.buf
122122
}
123123

124+
pub(super) fn print_pat_hir(
125+
db: &dyn DefDatabase,
126+
body: &Body,
127+
_owner: DefWithBodyId,
128+
pat: PatId,
129+
oneline: bool,
130+
edition: Edition,
131+
) -> String {
132+
let mut p = Printer {
133+
db,
134+
body,
135+
buf: String::new(),
136+
indent_level: 0,
137+
line_format: if oneline { LineFormat::Oneline } else { LineFormat::Newline },
138+
edition,
139+
};
140+
p.print_pat(pat);
141+
p.buf
142+
}
143+
124144
macro_rules! w {
125145
($dst:expr, $($arg:tt)*) => {
126146
{ let _ = write!($dst, $($arg)*); }

0 commit comments

Comments
 (0)