mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-09-20 06:22:10 +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)
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -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)*); }
|
||||
|
|
Loading…
Reference in a new issue