Skip to content

Commit 4b21816

Browse files
authored
Remove MultilineHandling enum (#789)
1 parent 44c6dfd commit 4b21816

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

librubyfmt/src/format_prism.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
delimiters::BreakableDelims,
77
heredoc_string::HeredocKind,
88
parser_state::{FormattingContext, HashType, ParserState},
9-
render_targets::MultilineHandling,
109
types::SourceOffset,
1110
util::{const_to_str, loc_to_str},
1211
};
@@ -85,7 +84,7 @@ pub fn format_node<'src>(ps: &mut ParserState<'src>, node: prism::Node<'src>) {
8584
let has_block = call_node.block().and_then(|b| b.as_block_node()).is_some();
8685

8786
if is_last_call_in_chain && has_block {
88-
ps.breakable_call_chain_of(MultilineHandling::Prism(false), |ps| {
87+
ps.breakable_call_chain_of(false, |ps| {
8988
format_call_node(ps, call_node, false, is_last_call_in_chain, false);
9089
});
9190
} else {
@@ -2196,7 +2195,7 @@ fn format_call_chain_segments<'src>(
21962195

21972196
let is_user_multilined = call_chain_elements_are_user_multilined(ps, &chain_elements);
21982197

2199-
ps.breakable_call_chain_of(MultilineHandling::Prism(is_user_multilined), |ps| {
2198+
ps.breakable_call_chain_of(is_user_multilined, |ps| {
22002199
// Recurse and format previous segments inside this breakable
22012200
format_call_chain_segments(ps, segments);
22022201

librubyfmt/src/parser_state.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::file_comments::FileComments;
44
use crate::heredoc_string::{HeredocKind, HeredocString};
55
use crate::line_tokens::*;
66
use crate::render_queue_writer::{MAX_LINE_LENGTH, RenderQueueWriter};
7-
use crate::render_targets::{
8-
BaseQueue, Breakable, BreakableCallChainEntry, BreakableEntry, MultilineHandling,
9-
};
7+
use crate::render_targets::{BaseQueue, Breakable, BreakableCallChainEntry, BreakableEntry};
108
use crate::types::{ColNumber, LineNumber, SourceOffset};
119
use log::debug;
1210
use std::borrow::Cow;
@@ -304,15 +302,12 @@ impl<'src> ParserState<'src> {
304302
self.push_target(ConcreteLineTokenAndTargets::BreakableEntry(insert_be));
305303
}
306304

307-
pub(crate) fn breakable_call_chain_of<F>(
308-
&mut self,
309-
mulitiline_handling: MultilineHandling,
310-
f: F,
311-
) where
305+
pub(crate) fn breakable_call_chain_of<F>(&mut self, is_user_multilined: bool, f: F)
306+
where
312307
F: FnOnce(&mut ParserState<'src>),
313308
{
314309
self.shift_comments();
315-
let mut be = BreakableCallChainEntry::new(&self.formatting_context, mulitiline_handling);
310+
let mut be = BreakableCallChainEntry::new(&self.formatting_context, is_user_multilined);
316311
be.push_line_number(self.current_orig_line_number);
317312
self.breakable_entry_stack.push(Breakable::CallChain(be));
318313

librubyfmt/src/render_targets.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,10 @@ impl<'src> BreakableEntry<'src> {
199199
}
200200
}
201201

202-
/// This struct is a bit of a hack to support both
203-
/// the Ripper tree and the Prism tree at the same time.
204-
/// The Prism tree has more accurate offset handling that obviates
205-
/// the hacks put in to support Ripper, but for now we need to support
206-
/// and I didn't want to have to fork the implementation of BreakableCallChainEntry.
207-
/// Once Prism is fully featured, we should delete this Ripper handling entirely.
208-
#[derive(Debug, Clone)]
209-
pub enum MultilineHandling {
210-
Prism(bool),
211-
}
212-
213202
#[derive(Debug, Clone)]
214203
pub struct BreakableCallChainEntry<'src> {
215204
tokens: Vec<AbstractLineToken<'src>>,
216-
multiline_handling: MultilineHandling,
205+
is_user_multilined: bool,
217206
in_string_embexpr: bool,
218207
}
219208

@@ -338,9 +327,7 @@ impl<'src> AbstractTokenTarget<'src> for BreakableCallChainEntry<'src> {
338327
return true;
339328
}
340329

341-
match &self.multiline_handling {
342-
MultilineHandling::Prism(is_user_multilined) => *is_user_multilined,
343-
}
330+
self.is_user_multilined
344331
}
345332

346333
fn any_collapsing_newline_has_heredoc_content(&self) -> bool {
@@ -361,18 +348,15 @@ impl<'src> AbstractTokenTarget<'src> for BreakableCallChainEntry<'src> {
361348
}
362349

363350
impl<'src> BreakableCallChainEntry<'src> {
364-
pub fn new(
365-
formatting_context: &[FormattingContext],
366-
multiline_handling: MultilineHandling,
367-
) -> Self {
351+
pub fn new(formatting_context: &[FormattingContext], is_user_multilined: bool) -> Self {
368352
let in_string_embexpr = formatting_context
369353
.iter()
370354
.any(|fc| fc == &FormattingContext::StringEmbexpr);
371355

372356
BreakableCallChainEntry {
373357
tokens: Vec::new(),
374358
in_string_embexpr,
375-
multiline_handling,
359+
is_user_multilined,
376360
}
377361
}
378362

0 commit comments

Comments
 (0)