mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-18 19:21:38 +00:00
feat: add prettifier for Pat
This commit is contained in:
parent
5004371a4a
commit
60c42c25c7
2 changed files with 31 additions and 0 deletions
|
|
@ -227,6 +227,17 @@ impl Body {
|
||||||
pretty::print_expr_hir(db, self, owner, expr, edition)
|
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(
|
fn new(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,26 @@ pub(super) fn print_expr_hir(
|
||||||
p.buf
|
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 {
|
macro_rules! w {
|
||||||
($dst:expr, $($arg:tt)*) => {
|
($dst:expr, $($arg:tt)*) => {
|
||||||
{ let _ = write!($dst, $($arg)*); }
|
{ let _ = write!($dst, $($arg)*); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue