Skip to content

Commit

Permalink
Fix parentheses breaking in pipelines (#2677)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- authored Apr 5, 2024
1 parent d932245 commit 7d480eb
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"previousLineText": "^\\s*(?:#|$)",
"beforeText": "^\\s*[^#]+[=\\+\\-\\*?/\\^><!&\\|~%\\$:@\\?]\\s*(?:#|$)",
"action": { "indent": "indent" }
},
},

// A line ending with an operator, preceded by a line not ending with an operator.
{
Expand All @@ -73,6 +73,7 @@
{
"previousLineText": "^\\s*[^#]+[=\\+\\-\\*?/\\^><!&\\|~%\\$:@\\?]\\s*(?:#|$)",
"beforeText": "^(?!.*[=\\+\\-\\*?/\\^><!&\\|~%\\$:@\\?]\\s*(?:#|$))[^#]+.*$",
"afterText": "^\\s*(#|$)",
"action": { "indent": "outdent" }
},

Expand Down
115 changes: 104 additions & 11 deletions extensions/positron-r/src/test/snapshots/indentation-cases.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,100 @@
# process them separately to prevent interferences between test cases.

# ---
# Starting a pipeline (+ operator)
1 +"<>"

# ---
1 +
2 +"<>"

# ---
# Starting a pipeline (pipe operator)
data |>"<>"

# ---
# Starting a pipeline (one empty line)
# FIXME
data |>
fn()"<>"
"<>"

# ---
# https://github.com/posit-dev/positron/issues/1727
# Starting a pipeline (multiple empty lines)
# FIXME
data |>
fn()
"<>"

"<>"

# ---
# Continuing a pipeline
1 +
2 +"<>"

# ---
# Continuing a one-liner pipeline
# https://github.com/posit-dev/positron/issues/1316
data |>
fn() |>"<>"

# ---
# With trailing whitespace
# Continuing a one-liner pipeline (trailing whitespace)
# https://github.com/posit-dev/positron/pull/1655#issuecomment-1780093395
data |>
fn() |> "<>"

# ---
# Continuing a one-liner pipeline (trailing comment)
data |>
fn() |> "<>" # foo

# ---
# Continuing a one-liner pipeline (comment line)
# FIXME
data |>
fn1() |>
# foo"<>"

# ---
# Continuing a one-liner pipeline (after a comment line)
# FIXME (once we merge the sticky dedent PR)
data |>
fn1() |>
# foo
"<>"

# ---
# Continuing a one-liner pipeline (longer pipeline)
data |>
fn1() |>
fn2() |>"<>"


# ---
# Continuing a multi-liner pipeline
# FIXME
data |>
fn1(
x,
y
) |>"<>"

# ---
# Continuing a multi-liner pipeline (trailing expression)
# FIXME
data |>
fn1(
x,
y
) |> "<>" fn2()

# ---
# Dedent after pipeline
data |>
fn()"<>"

# ---
# Dedent after pipeline (trailing comment)
data |>
fn()"<>" # foo

# ---
# Dedent after pipeline (multiple lines)
# FIXME
data |>
fn1() |>
Expand All @@ -54,18 +111,29 @@ data |>
)"<>"

# ---
# https://github.com/posit-dev/positron-beta/discussions/46
# Stickiness of dedent after pipeline
# https://github.com/posit-dev/positron/issues/1727
# FIXME
data |>
fn()
"<>"

# ---
# Stickiness of dedent after pipeline (trailing comment)
# FIXME
data |>
fn("<>")
fn()
"<>" # foo

# ---
# Indent after function in call
# FIXME
{
fn(function() {}"<>")
}

# ---
# Indent after function in call (multiple lines)
# FIXME
{
fn(function() {
Expand All @@ -74,9 +142,34 @@ data |>
}

# ---
# Indent after finished loop (literal)
for (i in NA) NULL"<>"

# ---
# Indent after finished loop (call)
# https://github.com/posit-dev/positron/issues/1880
# FIXME
for (i in 1) fn()"<>"

# ---
# Breaking parentheses
foo("<>") +
bar()

# ---
# Breaking parentheses in a pipeline
# https://github.com/posit-dev/positron/issues/2650
# https://github.com/posit-dev/positron-beta/discussions/46
foo() +
bar("<>")

# ---
# Breaking parentheses in a pipeline (comment in the way)
foo() +
bar("<>") # foo

# ---
# Breaking parentheses in the middle of a pipeline
foo() +
bar("<>") +
baz()
Loading

0 comments on commit 7d480eb

Please sign in to comment.