Skip to content

Commit 5438a3e

Browse files
indent deeply-nested EQ_FORMALS correctly
Problem: In apply_ref_indention_one(), the parse table is already flat, the indention of all tokens is absolute. However, for those where indention should be copied from another token, their indention must be relative, otherwise we'll double account for some indention. See tests: Formals need to be aligned with the absolute indention of the opening brace. If you add another time their absolute indention, they will be indented way to much. Solution: When flattening the parse table, keep the indention level of all tokens that have a ref_pos_id relative, so when added with an absolute indention, it will become absolute indention.
1 parent 69154c6 commit 5438a3e

File tree

4 files changed

+169
-27
lines changed

4 files changed

+169
-27
lines changed

R/visit.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ context_to_terminals <- function(pd_nested,
7474
}
7575

7676
pd_transformed <- context_towards_terminals(
77-
pd_nested, outer_lag_newlines, outer_indent, outer_spaces, outer_indention_refs
77+
pd_nested,
78+
outer_lag_newlines, outer_indent,
79+
outer_spaces, outer_indention_refs
7880
)
7981

8082
pd_transformed$child <- pmap(
@@ -110,7 +112,11 @@ context_towards_terminals <- function(pd_nested,
110112
outer_indent,
111113
outer_spaces,
112114
outer_indention_refs) {
113-
pd_nested$indent <- pd_nested$indent + outer_indent
115+
pd_nested$indent <- pd_nested$indent + ifelse(
116+
is.na(pd_nested$indention_ref_pos_id),
117+
outer_indent,
118+
0
119+
)
114120
ref_pos_id_is_na <- !is.na(pd_nested$indention_ref_pos_id)
115121
pd_nested$indention_ref_pos_id[!ref_pos_id_is_na] <- outer_indention_refs
116122
pd_nested$lag_newlines[1] <- pd_nested$lag_newlines[1] + outer_lag_newlines

tests/testthat/indention_operators/eq_sub_complex_indention-in.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ call(a =
66
5,
77
b
88
)
9+
10+
# multiple nested levels
11+
{
12+
v <- function(x =
13+
122,
14+
y) {
15+
}
16+
}
17+
18+
19+
{
20+
v <- function(x = 122,
21+
y) {
22+
}
23+
}
24+
25+
MyClass <- R6::R6Class(
26+
"MyClass",
27+
public = list(initialize = function(my_arg,
28+
my_named_arg = 1) {
29+
return(invisible())
30+
}
31+
),
32+
)

tests/testthat/indention_operators/eq_sub_complex_indention-in_tree

Lines changed: 113 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/indention_operators/eq_sub_complex_indention-out.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ call(a =
66
5,
77
b
88
)
9+
10+
# multiple nested levels
11+
{
12+
v <- function(x =
13+
122,
14+
y) {
15+
}
16+
}
17+
18+
19+
{
20+
v <- function(x = 122,
21+
y) {
22+
}
23+
}
24+
25+
MyClass <- R6::R6Class(
26+
"MyClass",
27+
public = list(initialize = function(my_arg,
28+
my_named_arg = 1) {
29+
return(invisible())
30+
}
31+
),
32+
)

0 commit comments

Comments
 (0)