Skip to content

Commit

Permalink
chore: update prettyplease including latest upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bram209 committed Jan 30, 2025
1 parent aaa1e0b commit 6c77d28
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ leptosfmt-prettyplease = { path = "./prettyplease", version = "0.1.32", features
leptosfmt-formatter = { path = "./formatter", version = "0.1.32" }
leptosfmt-pretty-printer = { version = "0.1.32" }

syn = { version = "2.0.59", features = ["visit", "full", "extra-traits"] }
syn = { version = "2.0.96", features = ["visit", "full", "extra-traits"] }
proc-macro2 = { version = "1.0.80", features = ["span-locations"] }

[patch.crates-io]
Expand Down
2 changes: 1 addition & 1 deletion formatter/src/formatter/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Formatter<'_> {
&mut self.line_offset,
comments_or_whitespace,
)),
|p| p.expr(expr),
|p| p.expr_without_fixup(expr),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion prettyplease
19 changes: 14 additions & 5 deletions printer/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct BreakToken {
pub offset: isize,
pub blank_space: usize,
pub pre_break: Option<char>,
pub post_break: Option<char>,
pub post_break: &'static str,
pub no_break: Option<char>,
pub if_nonempty: bool,
pub never_break: bool,
Expand Down Expand Up @@ -225,9 +225,18 @@ impl Printer {
self.scan_end();
}

pub fn ends_with(&self, ch: char) -> bool {
for i in self.buf.index_range().rev() {
if let Token::String(token) = &self.buf[i].token {
return token.ends_with(ch);
}
}
self.out.ends_with(ch)
}

fn check_stream(&mut self) {
while self.right_total - self.left_total > self.space {
if *self.scan_stack.front().unwrap() == self.buf.index_of_first() {
if *self.scan_stack.front().unwrap() == self.buf.index_range().start {
self.scan_stack.pop_front().unwrap();
self.buf.first_mut().size = SIZE_INFINITY;
}
Expand Down Expand Up @@ -343,10 +352,10 @@ impl Printer {
let indent = self.indent as isize + token.offset;
self.pending_indentation = usize::try_from(indent).unwrap();
self.space = cmp::max(self.settings.margin - indent, self.settings.min_space);
if let Some(post_break) = token.post_break {
if !token.post_break.is_empty() {
self.print_indent();
self.out.push(post_break);
self.space -= post_break.len_utf8() as isize;
self.out.push_str(token.post_break);
self.space -= token.post_break.len() as isize;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion printer/src/ring.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::VecDeque;
use std::ops::{Index, IndexMut};
use std::ops::{Index, IndexMut, Range};

pub struct RingBuffer<T> {
data: VecDeque<T>,
Expand Down Expand Up @@ -37,6 +37,10 @@ impl<T> RingBuffer<T> {
self.offset
}

pub fn index_range(&self) -> Range<usize> {
self.offset..self.offset + self.data.len()
}

pub fn first(&self) -> &T {
&self.data[0]
}
Expand Down

0 comments on commit 6c77d28

Please sign in to comment.