Skip to content

Preserve SciML for tuple bindings#998

Open
svchb wants to merge 2 commits into
JuliaEditorSupport:masterfrom
svchb:split/sciml-for-tuple-binding
Open

Preserve SciML for tuple bindings#998
svchb wants to merge 2 commits into
JuliaEditorSupport:masterfrom
svchb:split/sciml-for-tuple-binding

Conversation

@svchb
Copy link
Copy Markdown
Contributor

@svchb svchb commented May 28, 2026

Before:

@threaded destination.scheduler for (dest_id,
                                     src_id) in zip(eachindex(destination),
                                                    eachindex(source))

After:

@threaded destination.scheduler for (dest_id, src_id) in zip(eachindex(destination),
                                                             eachindex(source))

@svchb svchb marked this pull request as ready for review May 28, 2026 10:12
@svchb svchb mentioned this pull request May 28, 2026
Comment thread src/styles/sciml/nest.jl
lineage[end-1][1] === CartesianIterator &&
op_kind(fst) in KSet"in ∈" &&
fst[1].typ === TupleN &&
s.line_offset + length(fst[1]) <= s.opts.margin
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm May 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) |> println

In 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]
end

whereas 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants