Skip to content

Commit

Permalink
fix #387
Browse files Browse the repository at this point in the history
Handles the edge case where the first argument of a Call node
is nestable. For example:

```
new{T1,T2}(arg1,arg2)
```

In this case if the indent is set to the offset of the first argument after
`(` and `new{T1,T2}` is nested, the indentation will be incorrect.

before (aligned to after the initial position of `(`):

```
new{T1,
    T2}(arg1,
           arg2)
```

after (aligned to after new position of `(`):

```
new{T1,
    T2}(arg1,
        arg2)
```
  • Loading branch information
domluna committed Apr 2, 2021
1 parent c3709d5 commit 40619d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/styles/yas/nest.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
function n_call!(ys::YASStyle, fst::FST, s::State)
style = getstyle(ys)
fst.indent = s.line_offset + sum(length.(fst[1:2]))

f = n -> n.typ === PLACEHOLDER || n.typ === NEWLINE

for (i, n) in enumerate(fst.nodes)
if i == 3
# The indent is set here to handle the edge
# case where the first argument of Call is
# nestable.
# ref https://github.com/domluna/JuliaFormatter.jl/issues/387
fst.indent = s.line_offset
end

if n.typ === NEWLINE
s.line_offset = fst.indent
elseif n.typ === PLACEHOLDER
Expand Down
9 changes: 9 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,13 @@
"""
@test bluefmt(str_, always_for_in = true) == str
end

@testset "issue 387" begin
str_ = """new{T1,T2}(arg1,arg2)"""
str = """
new{T1,
T2}(arg1,
arg2)"""
@test yasfmt(str_, 4, 1) == str
end
end

0 comments on commit 40619d8

Please sign in to comment.