1 //! Formatting of chained expressions, i.e., expressions that are chained by
2 //! dots: struct and enum field access, method calls, and try shorthand (`?`).
4 //! Instead of walking these subexpressions one-by-one, as is our usual strategy
5 //! for expression formatting, we collect maximal sequences of these expressions
6 //! and handle them simultaneously.
8 //! Whenever possible, the entire chain is put on a single line. If that fails,
9 //! we put each subexpression on a separate, much like the (default) function
10 //! argument function argument strategy.
12 //! Depends on config options: `chain_indent` is the indent to use for
13 //! blocks in the parent/root/base of the chain (and the rest of the chain's
15 //! E.g., `let foo = { aaaa; bbb; ccc }.bar.baz();`, we would layout for the
16 //! following values of `chain_indent`:
40 //! If the first item in the chain is a block expression, we align the dots with
61 use rustc_ast::{ast, ptr};
62 use rustc_span::{symbol, BytePos, Span};
64 use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
65 use crate::config::{IndentStyle, Version};
66 use crate::expr::rewrite_call;
67 use crate::lists::extract_pre_comment;
68 use crate::macros::convert_try_mac;
69 use crate::rewrite::{Rewrite, RewriteContext};
70 use crate::shape::Shape;
71 use crate::source_map::SpanUtils;
73 self, filtered_str_fits, first_line_width, last_line_extendable, last_line_width, mk_sp,
74 rewrite_ident, trimmed_last_line_width, wrap_str,
77 /// Provides the original input contents from the span
78 /// of a chain element with trailing spaces trimmed.
79 fn format_overflow_style(span: Span, context: &RewriteContext<'_>) -> Option<String> {
80 context.snippet_provider.span_to_snippet(span).map(|s| {
82 .map(|l| l.trim_end())
90 context: &RewriteContext<'_>,
95 item.rewrite(context, rewrite_shape)
96 .or_else(|| format_overflow_style(item.span, context))
98 item.rewrite(context, rewrite_shape)
102 fn get_block_child_shape(
103 prev_ends_with_block: bool,
104 context: &RewriteContext<'_>,
107 if prev_ends_with_block {
108 shape.block_indent(0)
110 shape.block_indent(context.config.tab_spaces())
112 .with_max_width(context.config)
115 fn get_visual_style_child_shape(
116 context: &RewriteContext<'_>,
119 parent_overflowing: bool,
121 if !parent_overflowing {
123 .with_max_width(context.config)
125 .map(|s| s.visual_indent(0))
127 Some(shape.visual_indent(offset))
131 pub(crate) fn rewrite_chain(
133 context: &RewriteContext<'_>,
135 ) -> Option<String> {
136 let chain = Chain::from_ast(expr, context);
137 debug!("rewrite_chain {:?} {:?}", chain, shape);
139 // If this is just an expression with some `?`s, then format it trivially and
141 if chain.children.is_empty() {
142 return chain.parent.rewrite(context, shape);
145 chain.rewrite(context, shape)
149 enum CommentPosition {
154 // An expression plus trailing `?`s to be formatted together.
162 // FIXME: we can't use a reference here because to convert `try!` to `?` we
163 // synthesise the AST node. However, I think we could use `Cow` and that
164 // would remove a lot of cloning.
170 Vec<ast::GenericArg>,
171 Vec<ptr::P<ast::Expr>>,
173 StructField(symbol::Ident),
174 TupleField(symbol::Ident, bool),
176 Comment(String, CommentPosition),
180 fn is_block_like(&self, context: &RewriteContext<'_>, reps: &str) -> bool {
182 ChainItemKind::Parent(ref expr) => utils::is_block_expr(context, expr, reps),
183 ChainItemKind::MethodCall(..)
184 | ChainItemKind::StructField(..)
185 | ChainItemKind::TupleField(..)
186 | ChainItemKind::Await
187 | ChainItemKind::Comment(..) => false,
191 fn is_tup_field_access(expr: &ast::Expr) -> bool {
193 ast::ExprKind::Field(_, ref field) => {
194 field.name.to_string().chars().all(|c| c.is_digit(10))
200 fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
201 let (kind, span) = match expr.kind {
202 ast::ExprKind::MethodCall(ref call) => {
203 let types = if let Some(ref generic_args) = call.seg.args {
204 if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
207 .filter_map(|x| match x {
208 ast::AngleBracketedArg::Arg(ref generic_arg) => {
209 Some(generic_arg.clone())
220 let span = mk_sp(call.receiver.span.hi(), expr.span.hi());
221 let kind = ChainItemKind::MethodCall(call.seg.clone(), types, call.args.clone());
224 ast::ExprKind::Field(ref nested, field) => {
225 let kind = if Self::is_tup_field_access(expr) {
226 ChainItemKind::TupleField(field, Self::is_tup_field_access(nested))
228 ChainItemKind::StructField(field)
230 let span = mk_sp(nested.span.hi(), field.span.hi());
233 ast::ExprKind::Await(ref nested) => {
234 let span = mk_sp(nested.span.hi(), expr.span.hi());
235 (ChainItemKind::Await, span)
237 _ => return (ChainItemKind::Parent(expr.clone()), expr.span),
240 // Remove comments from the span.
241 let lo = context.snippet_provider.span_before(span, ".");
242 (kind, mk_sp(lo, span.hi()))
246 impl Rewrite for ChainItem {
247 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
248 let shape = shape.sub_width(self.tries)?;
249 let rewrite = match self.kind {
250 ChainItemKind::Parent(ref expr) => expr.rewrite(context, shape)?,
251 ChainItemKind::MethodCall(ref segment, ref types, ref exprs) => {
252 Self::rewrite_method_call(segment.ident, types, exprs, self.span, context, shape)?
254 ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)),
255 ChainItemKind::TupleField(ident, nested) => format!(
257 if nested && context.config.version() == Version::One {
262 rewrite_ident(context, ident)
264 ChainItemKind::Await => ".await".to_owned(),
265 ChainItemKind::Comment(ref comment, _) => {
266 rewrite_comment(comment, false, shape, context.config)?
269 Some(format!("{}{}", rewrite, "?".repeat(self.tries)))
274 fn new(context: &RewriteContext<'_>, expr: &ast::Expr, tries: usize) -> ChainItem {
275 let (kind, span) = ChainItemKind::from_ast(context, expr);
276 ChainItem { kind, tries, span }
279 fn comment(span: Span, comment: String, pos: CommentPosition) -> ChainItem {
281 kind: ChainItemKind::Comment(comment, pos),
287 fn is_comment(&self) -> bool {
288 matches!(self.kind, ChainItemKind::Comment(..))
291 fn rewrite_method_call(
292 method_name: symbol::Ident,
293 types: &[ast::GenericArg],
294 args: &[ptr::P<ast::Expr>],
296 context: &RewriteContext<'_>,
298 ) -> Option<String> {
299 let type_str = if types.is_empty() {
302 let type_list = types
304 .map(|ty| ty.rewrite(context, shape))
305 .collect::<Option<Vec<_>>>()?;
307 format!("::<{}>", type_list.join(", "))
309 let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
310 rewrite_call(context, &callee_str, &args, span, shape)
317 children: Vec<ChainItem>,
321 fn from_ast(expr: &ast::Expr, context: &RewriteContext<'_>) -> Chain {
322 let subexpr_list = Self::make_subexpr_list(expr, context);
324 // Un-parse the expression tree into ChainItems
325 let mut rev_children = vec![];
326 let mut sub_tries = 0;
327 for subexpr in &subexpr_list {
329 ast::ExprKind::Try(_) => sub_tries += 1,
331 rev_children.push(ChainItem::new(context, subexpr, sub_tries));
337 fn is_tries(s: &str) -> bool {
338 s.chars().all(|c| c == '?')
341 fn is_post_comment(s: &str) -> bool {
342 let comment_start_index = s.chars().position(|c| c == '/');
343 if comment_start_index.is_none() {
347 let newline_index = s.chars().position(|c| c == '\n');
348 if newline_index.is_none() {
352 comment_start_index.unwrap() < newline_index.unwrap()
355 fn handle_post_comment(
356 post_comment_span: Span,
357 post_comment_snippet: &str,
358 prev_span_end: &mut BytePos,
359 children: &mut Vec<ChainItem>,
361 let white_spaces: &[_] = &[' ', '\t'];
362 if post_comment_snippet
363 .trim_matches(white_spaces)
369 let trimmed_snippet = trim_tries(post_comment_snippet);
370 if is_post_comment(&trimmed_snippet) {
371 children.push(ChainItem::comment(
373 trimmed_snippet.trim().to_owned(),
374 CommentPosition::Back,
376 *prev_span_end = post_comment_span.hi();
380 let parent = rev_children.pop().unwrap();
381 let mut children = vec![];
382 let mut prev_span_end = parent.span.hi();
383 let mut iter = rev_children.into_iter().rev().peekable();
384 if let Some(first_chain_item) = iter.peek() {
385 let comment_span = mk_sp(prev_span_end, first_chain_item.span.lo());
386 let comment_snippet = context.snippet(comment_span);
387 if !is_tries(comment_snippet.trim()) {
396 while let Some(chain_item) = iter.next() {
397 let comment_snippet = context.snippet(chain_item.span);
398 // FIXME: Figure out the way to get a correct span when converting `try!` to `?`.
400 !(context.config.use_try_shorthand() || is_tries(comment_snippet.trim()));
404 let pre_comment_span = mk_sp(prev_span_end, chain_item.span.lo());
405 let pre_comment_snippet = trim_tries(context.snippet(pre_comment_span));
406 let (pre_comment, _) = extract_pre_comment(&pre_comment_snippet);
408 Some(ref comment) if !comment.is_empty() => {
409 children.push(ChainItem::comment(
412 CommentPosition::Top,
419 prev_span_end = chain_item.span.hi();
420 children.push(chain_item);
423 if !handle_comment || iter.peek().is_none() {
427 let next_lo = iter.peek().unwrap().span.lo();
428 let post_comment_span = mk_sp(prev_span_end, next_lo);
429 let post_comment_snippet = context.snippet(post_comment_span);
432 post_comment_snippet,
438 Chain { parent, children }
441 // Returns a Vec of the prefixes of the chain.
442 // E.g., for input `a.b.c` we return [`a.b.c`, `a.b`, 'a']
443 fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext<'_>) -> Vec<ast::Expr> {
444 let mut subexpr_list = vec![expr.clone()];
446 while let Some(subexpr) = Self::pop_expr_chain(subexpr_list.last().unwrap(), context) {
447 subexpr_list.push(subexpr.clone());
453 // Returns the expression's subexpression, if it exists. When the subexpr
454 // is a try! macro, we'll convert it to shorthand when the option is set.
455 fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
457 ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
458 ast::ExprKind::Field(ref subexpr, _)
459 | ast::ExprKind::Try(ref subexpr)
460 | ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),
465 fn convert_try(expr: &ast::Expr, context: &RewriteContext<'_>) -> ast::Expr {
467 ast::ExprKind::MacCall(ref mac) if context.config.use_try_shorthand() => {
468 if let Some(subexpr) = convert_try_mac(mac, context) {
479 impl Rewrite for Chain {
480 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
481 debug!("rewrite chain {:?} {:?}", self, shape);
483 let mut formatter = match context.config.indent_style() {
484 IndentStyle::Block => {
485 Box::new(ChainFormatterBlock::new(self)) as Box<dyn ChainFormatter>
487 IndentStyle::Visual => {
488 Box::new(ChainFormatterVisual::new(self)) as Box<dyn ChainFormatter>
492 formatter.format_root(&self.parent, context, shape)?;
493 if let Some(result) = formatter.pure_root() {
494 return wrap_str(result, context.config.max_width(), shape);
497 // Decide how to layout the rest of the chain.
498 let child_shape = formatter.child_shape(context, shape)?;
500 formatter.format_children(context, child_shape)?;
501 formatter.format_last_child(context, shape, child_shape)?;
503 let result = formatter.join_rewrites(context, child_shape)?;
504 wrap_str(result, context.config.max_width(), shape)
508 // There are a few types for formatting chains. This is because there is a lot
509 // in common between formatting with block vs visual indent, but they are
510 // different enough that branching on the indent all over the place gets ugly.
511 // Anything that can format a chain is a ChainFormatter.
512 trait ChainFormatter {
513 // Parent is the first item in the chain, e.g., `foo` in `foo.bar.baz()`.
514 // Root is the parent plus any other chain items placed on the first line to
515 // avoid an orphan. E.g.,
520 // If `bar` were not part of the root, then foo would be orphaned and 'float'.
524 context: &RewriteContext<'_>,
527 fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape>;
528 fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()>;
529 fn format_last_child(
531 context: &RewriteContext<'_>,
535 fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String>;
536 // Returns `Some` if the chain is only a root, None otherwise.
537 fn pure_root(&mut self) -> Option<String>;
540 // Data and behaviour that is shared by both chain formatters. The concrete
541 // formatters can delegate much behaviour to `ChainFormatterShared`.
542 struct ChainFormatterShared<'a> {
543 // The current working set of child items.
544 children: &'a [ChainItem],
545 // The current rewrites of items (includes trailing `?`s, but not any way to
546 // connect the rewrites together).
547 rewrites: Vec<String>,
548 // Whether the chain can fit on one line.
549 fits_single_line: bool,
550 // The number of children in the chain. This is not equal to `self.children.len()`
551 // because `self.children` will change size as we process the chain.
553 // Whether elements are allowed to overflow past the max_width limit
554 allow_overflow: bool,
557 impl<'a> ChainFormatterShared<'a> {
558 fn new(chain: &'a Chain) -> ChainFormatterShared<'a> {
559 ChainFormatterShared {
560 children: &chain.children,
561 rewrites: Vec::with_capacity(chain.children.len() + 1),
562 fits_single_line: false,
563 child_count: chain.children.len(),
564 // TODO(calebcartwright)
565 allow_overflow: false,
569 fn pure_root(&mut self) -> Option<String> {
570 if self.children.is_empty() {
571 assert_eq!(self.rewrites.len(), 1);
572 Some(self.rewrites.pop().unwrap())
578 fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> {
579 for item in &self.children[..self.children.len() - 1] {
580 let rewrite = format_chain_item(item, context, child_shape, self.allow_overflow)?;
581 self.rewrites.push(rewrite);
586 // Rewrite the last child. The last child of a chain requires special treatment. We need to
587 // know whether 'overflowing' the last child make a better formatting:
589 // A chain with overflowing the last child:
591 // parent.child1.child2.last_child(
598 // A chain without overflowing the last child (in vertical layout):
603 // .last_child(a, b, c)
606 // In particular, overflowing is effective when the last child is a method with a multi-lined
607 // block-like argument (e.g., closure):
609 // parent.child1.child2.last_child(|a, b, c| {
610 // let x = foo(a, b, c);
611 // let y = bar(a, b, c);
618 fn format_last_child(
621 context: &RewriteContext<'_>,
625 let last = self.children.last()?;
626 let extendable = may_extend && last_line_extendable(&self.rewrites[0]);
627 let prev_last_line_width = last_line_width(&self.rewrites[0]);
629 // Total of all items excluding the last.
630 let almost_total = if extendable {
635 .map(|rw| utils::unicode_str_width(rw))
638 let one_line_budget = if self.child_count == 1 {
641 min(shape.width, context.config.chain_width())
643 .saturating_sub(almost_total);
645 let all_in_one_line = !self.children.iter().any(ChainItem::is_comment)
646 && self.rewrites.iter().all(|s| !s.contains('\n'))
647 && one_line_budget > 0;
648 let last_shape = if all_in_one_line {
649 shape.sub_width(last.tries)?
650 } else if extendable {
651 child_shape.sub_width(last.tries)?
653 child_shape.sub_width(shape.rhs_overhead(context.config) + last.tries)?
656 let mut last_subexpr_str = None;
657 if all_in_one_line || extendable {
658 // First we try to 'overflow' the last child and see if it looks better than using
660 let one_line_shape = if context.use_block_indent() {
661 last_shape.offset_left(almost_total)
664 .visual_indent(almost_total)
665 .sub_width(almost_total)
668 if let Some(one_line_shape) = one_line_shape {
669 if let Some(rw) = last.rewrite(context, one_line_shape) {
670 // We allow overflowing here only if both of the following conditions match:
671 // 1. The entire chain fits in a single line except the last child.
672 // 2. `last_child_str.lines().count() >= 5`.
673 let line_count = rw.lines().count();
674 let could_fit_single_line = first_line_width(&rw) <= one_line_budget;
675 if could_fit_single_line && line_count >= 5 {
676 last_subexpr_str = Some(rw);
677 self.fits_single_line = all_in_one_line;
679 // We could not know whether overflowing is better than using vertical
680 // layout, just by looking at the overflowed rewrite. Now we rewrite the
681 // last child on its own line, and compare two rewrites to choose which is
683 let last_shape = child_shape
684 .sub_width(shape.rhs_overhead(context.config) + last.tries)?;
685 match last.rewrite(context, last_shape) {
686 Some(ref new_rw) if !could_fit_single_line => {
687 last_subexpr_str = Some(new_rw.clone());
689 Some(ref new_rw) if new_rw.lines().count() >= line_count => {
690 last_subexpr_str = Some(rw);
691 self.fits_single_line = could_fit_single_line && all_in_one_line;
693 new_rw @ Some(..) => {
694 last_subexpr_str = new_rw;
697 last_subexpr_str = Some(rw);
698 self.fits_single_line = could_fit_single_line && all_in_one_line;
706 let last_shape = if context.use_block_indent() {
709 child_shape.sub_width(shape.rhs_overhead(context.config) + last.tries)?
712 last_subexpr_str = last_subexpr_str.or_else(|| last.rewrite(context, last_shape));
713 self.rewrites.push(last_subexpr_str?);
717 fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
718 let connector = if self.fits_single_line {
719 // Yay, we can put everything on one line.
723 if context.force_one_line_chain.get() {
726 child_shape.to_string_with_newline(context.config)
729 let mut rewrite_iter = self.rewrites.iter();
730 let mut result = rewrite_iter.next().unwrap().clone();
731 let children_iter = self.children.iter();
732 let iter = rewrite_iter.zip(children_iter);
734 for (rewrite, chain_item) in iter {
735 match chain_item.kind {
736 ChainItemKind::Comment(_, CommentPosition::Back) => result.push(' '),
737 ChainItemKind::Comment(_, CommentPosition::Top) => result.push_str(&connector),
738 _ => result.push_str(&connector),
740 result.push_str(rewrite);
747 // Formats a chain using block indent.
748 struct ChainFormatterBlock<'a> {
749 shared: ChainFormatterShared<'a>,
750 root_ends_with_block: bool,
753 impl<'a> ChainFormatterBlock<'a> {
754 fn new(chain: &'a Chain) -> ChainFormatterBlock<'a> {
755 ChainFormatterBlock {
756 shared: ChainFormatterShared::new(chain),
757 root_ends_with_block: false,
762 impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
766 context: &RewriteContext<'_>,
769 let mut root_rewrite: String = parent.rewrite(context, shape)?;
771 let mut root_ends_with_block = parent.kind.is_block_like(context, &root_rewrite);
772 let tab_width = context.config.tab_spaces().saturating_sub(shape.offset);
774 while root_rewrite.len() <= tab_width && !root_rewrite.contains('\n') {
775 let item = &self.shared.children[0];
776 if let ChainItemKind::Comment(..) = item.kind {
779 let shape = shape.offset_left(root_rewrite.len())?;
780 match &item.rewrite(context, shape) {
781 Some(rewrite) => root_rewrite.push_str(rewrite),
785 root_ends_with_block = last_line_extendable(&root_rewrite);
787 self.shared.children = &self.shared.children[1..];
788 if self.shared.children.is_empty() {
792 self.shared.rewrites.push(root_rewrite);
793 self.root_ends_with_block = root_ends_with_block;
797 fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape> {
798 let block_end = self.root_ends_with_block;
799 Some(get_block_child_shape(block_end, context, shape))
802 fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> {
803 self.shared.format_children(context, child_shape)
806 fn format_last_child(
808 context: &RewriteContext<'_>,
813 .format_last_child(true, context, shape, child_shape)
816 fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
817 self.shared.join_rewrites(context, child_shape)
820 fn pure_root(&mut self) -> Option<String> {
821 self.shared.pure_root()
825 // Format a chain using visual indent.
826 struct ChainFormatterVisual<'a> {
827 shared: ChainFormatterShared<'a>,
828 // The extra offset from the chain's shape to the position of the `.`
832 impl<'a> ChainFormatterVisual<'a> {
833 fn new(chain: &'a Chain) -> ChainFormatterVisual<'a> {
834 ChainFormatterVisual {
835 shared: ChainFormatterShared::new(chain),
841 impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
845 context: &RewriteContext<'_>,
848 let parent_shape = shape.visual_indent(0);
849 let mut root_rewrite = parent.rewrite(context, parent_shape)?;
850 let multiline = root_rewrite.contains('\n');
851 self.offset = if multiline {
852 last_line_width(&root_rewrite).saturating_sub(shape.used_width())
854 trimmed_last_line_width(&root_rewrite)
857 if !multiline || parent.kind.is_block_like(context, &root_rewrite) {
858 let item = &self.shared.children[0];
859 if let ChainItemKind::Comment(..) = item.kind {
860 self.shared.rewrites.push(root_rewrite);
863 let child_shape = parent_shape
864 .visual_indent(self.offset)
865 .sub_width(self.offset)?;
866 let rewrite = item.rewrite(context, child_shape)?;
867 if filtered_str_fits(&rewrite, context.config.max_width(), shape) {
868 root_rewrite.push_str(&rewrite);
870 // We couldn't fit in at the visual indent, try the last
872 let rewrite = item.rewrite(context, parent_shape)?;
873 root_rewrite.push_str(&rewrite);
877 self.shared.children = &self.shared.children[1..];
880 self.shared.rewrites.push(root_rewrite);
884 fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape> {
885 get_visual_style_child_shape(
889 // TODO(calebcartwright): self.shared.permissibly_overflowing_parent,
894 fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> {
895 self.shared.format_children(context, child_shape)
898 fn format_last_child(
900 context: &RewriteContext<'_>,
905 .format_last_child(false, context, shape, child_shape)
908 fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
909 self.shared.join_rewrites(context, child_shape)
912 fn pure_root(&mut self) -> Option<String> {
913 self.shared.pure_root()
917 /// Removes try operators (`?`s) that appear in the given string. If removing
918 /// them leaves an empty line, remove that line as well unless it is the first
919 /// line (we need the first newline for detecting pre/post comment).
920 fn trim_tries(s: &str) -> String {
921 let mut result = String::with_capacity(s.len());
922 let mut line_buffer = String::with_capacity(s.len());
923 for (kind, rich_char) in CharClasses::new(s.chars()) {
924 match rich_char.get_char() {
926 if result.is_empty() || !line_buffer.trim().is_empty() {
927 result.push_str(&line_buffer);
932 '?' if kind == FullCodeCharKind::Normal => continue,
933 c => line_buffer.push(c),
936 if !line_buffer.trim().is_empty() {
937 result.push_str(&line_buffer);