Skip to content

Commit a46b3c5

Browse files
committed
better formatting sensitivity
1 parent b2fc524 commit a46b3c5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/patch/cst.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ function precedence_level(cst::EXPR, loc::Location)
1515
end
1616
end
1717

18+
# Get the range at loc, including trailing trivia from the previous node.
19+
function separator_range(cst, loc)
20+
i = loc.ii[end]
21+
loc = CSTParser.parent(loc)
22+
start = charrange(cst, CSTParser.child(loc, i-1))[1][1]+1
23+
stop = charrange(cst, CSTParser.child(loc, i))[1][end]
24+
return start:stop
25+
end
26+
1827
function separator(cst, loc, x::EXPR{Call}, i)
1928
length(x.args) == 3 && return ""
2029
length(x.args) == 4 && return ", "
21-
charrange(cst, CSTParser.child(loc, max(i-1, 4)))[1]
30+
separator_range(cst, CSTParser.child(loc, max(i-1,4)))
2231
end
2332

2433
function separator(cst, loc, x::CSTParser.BinaryOpCall, i)
25-
charrange(cst, CSTParser.child(loc, 2))[1]
34+
separator_range(cst, CSTParser.child(loc, 2))
2635
end
2736

2837
function separator(cst::EXPR, loc::Location)

test/patch.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ testrep(ex, text) = textmap(_ -> Expr(:file, ex), text)
2929
@test testrep(:(f(c, a, b)), "f(a, b)") == "f(c, a, b)"
3030
@test testrep(:(c(f, a, b)), "f(a, b)") == "c(f, a, b)"
3131

32+
@test testrep(:(f(a, b, c)), "f(a , b)") == "f(a , b , c)"
33+
@test testrep(:(a+b+c), "a + b") == "a + b + c"
34+
@test testrep(:(a+b+c), "a+b") == "a+b+c"
35+
3236
# Deletion
3337

3438
@test testrep(:(f()), "f(a)") == "f()"

0 commit comments

Comments
 (0)