Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,16 @@ impl<'a> Formatter<'a> {

/// Format a subexpression
fn format_subexpression(&mut self, block_id: nu_protocol::BlockId) {
self.write("(");
let block = self.working_set.get_block(block_id);
// Special case: subexpressions containing only a string interpolation don't need parentheses
if block.pipelines.len() == 1 && block.pipelines[0].elements.len() == 1 {
if let Expr::StringInterpolation(_) = &block.pipelines[0].elements[0].expr.expr {
self.format_block(block);
return;
}
}

self.write("(");
let is_simple = block.pipelines.len() == 1 && block.pipelines[0].elements.len() <= 3;

if is_simple {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/expected/issue76.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def pretty-print-command [] { ($"`(ansi default_dimmed)(ansi default_italic)($in)(ansi reset)`") }
1 change: 1 addition & 0 deletions tests/fixtures/expected/subexpression.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
let result = (1 + 2) * 3
let value = ($x + (($y * 2)))
print (echo "hello")
let msg = $"Hello ($name)"
if (true) { print "yes" }
1 change: 1 addition & 0 deletions tests/fixtures/input/issue76.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def pretty-print-command [] { ($"`(ansi default_dimmed)(ansi default_italic)($in)(ansi reset)`") }
1 change: 1 addition & 0 deletions tests/fixtures/input/subexpression.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
let result = (1 + 2) * 3
let value = ($x + (($y * 2)))
print (echo "hello")
let msg = ($"Hello ($name)")
if (true) { print "yes" }
Loading