Preserve SciML for tuple bindings#998
Conversation
| lineage[end-1][1] === CartesianIterator && | ||
| op_kind(fst) in KSet"in ∈" && | ||
| fst[1].typ === TupleN && | ||
| s.line_offset + length(fst[1]) <= s.opts.margin |
There was a problem hiding this comment.
Is this perhaps a bit too lenient? After the for (...), there's still on top of that an in (...) which has to fit on the same line. Basically here you're saying that, as long as the for (...) fits on this line, put it on this line.
This works nicely when we're well under the margin, because the formatter can then choose to nest the in (...) section instead, like in the example you demonstrated.
However, if we're close to the margin this can result in things going over margin quite drastically:
str = """
@threaded destination.scheduler for (dest_id, src_id, aaaa, bbbb, ccccc, dddd) in zip(eachindex(destination),
eachindex(source))
@inbounds destination[dest_id] = source[src_id]
end
"""
using JuliaFormatter
format_text(str, SciMLStyle(); yas_style_nesting=true, margin=92) |> printlnIn this example, ddddd) goes up to column 78, which is well under the margin of 92.
Disabling nesting causes the line to go up to column 109:
julia> format_text(str, SciMLStyle(); yas_style_nesting=true, margin=92) |> println
@threaded destination.scheduler for (dest_id, src_id, aaaa, bbbb, ccccc, dddd) in zip(eachindex(destination),
eachindex(source))
@inbounds destination[dest_id] = source[src_id]
endwhereas on the current release the nesting is indeed a bit ugly, but at least it respects the margins:
julia> format_text(str, SciMLStyle(); yas_style_nesting=true, margin=92) |> println
@threaded destination.scheduler for (dest_id, src_id, aaaa, bbbb, ccccc,
dddd) in zip(eachindex(destination),
eachindex(source))
@inbounds destination[dest_id] = source[src_id]
end
Before:
After: