-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix vector nesting with SciMLStyle
and yas_style_nesting = true
#807
Conversation
src/styles/sciml/nest.jl
Outdated
@@ -183,7 +183,7 @@ for f in [ | |||
:n_curly!, | |||
:n_macrocall!, | |||
:n_ref!, | |||
:n_vect!, | |||
# :n_vect!, don't use YAS style vector formatting with `yas_style_nesting = true` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would change the nesting behaviour imposed in #792 so that it would put all arguments on one line instead of trying to best fit the arguments among the fewest lines while trying to fit within the maximum margin.
The entire point of #792 was that the former behaviour was unwanted amongst people in the SciML organization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for vect specifically if this is fine then I'm ok with the PR but I'm not sure if there's a concensus on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I guess we want to best fit, but still allow the line break with vector definitions. I'll have another look tomorrow. Or can you point me in the right direction how to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but still allow the line break with vector definitions
can you give an example of what this means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant that I would like to combine the vector definition style that I restored in this PR with the best fit feature you implemented.
Okay, so I tried to make the best fit feature work with julia> str = """
test = (arg1, arg2, arg3, arg4, arg5)
""";
julia> print(format_text(str, SciMLStyle(), yas_style_nesting = true, margin = 34))
test = (arg1, arg2, arg3, arg4,
arg5) So I guess this PR really only fixes the bug and doesn't break anything else. But it would be a nice feature to have best fit with |
This reverts commit 5ea87bb.
1e3d291
to
61ca3fb
Compare
It's called here https://github.com/domluna/JuliaFormatter.jl/blob/master/src/styles/sciml/nest.jl#L100-L121 which is dispatched as SciMLStyle. YAS style hasn't changed. When yas_style_nesting=true the YASStyle dispatch is used instead which is why you're getting the old YAS behaviour. I believe YAS folks would be fine with using the new nesting in YAS as well. |
Then I suggest merging this PR for now, and I'll see if I can find time to make the best fit feature work with YAS in a new PR. |
Update: This PR is messing up julia> print(format_text(str3, SciMLStyle(), margin = 32))
test = [arg1, arg2, arg3,
arg4, arg5] This PR: julia> print(format_text(str3, SciMLStyle(), margin = 32))
test = [
arg1,
arg2,
arg3,
arg4,
arg5
] |
Now, this PR should not be breaking any SciML style features. It should only affect formatting with |
fstr = """ | ||
test = [arg1, arg2, | ||
arg3, | ||
arg4, arg5] | ||
""" | ||
@test format_text(str, SciMLStyle(), margin = 20) == fstr | ||
# should be 19? might be a unnesting off by 1 error | ||
# @test format_text(str, SciMLStyle(), margin = 19) == fstr | ||
|
||
fstr = """ | ||
test = [ | ||
arg1, arg2, | ||
arg3, | ||
arg4, arg5) | ||
body | ||
end | ||
""" | ||
@test format_text(str, SciMLStyle(), margin = 24) == fstr | ||
arg4, arg5] | ||
""" | ||
@test format_text(str, SciMLStyle(), margin = 19) == fstr | ||
# should be 15? might be a unnesting off by 1 error | ||
@test format_text(str, SciMLStyle(), margin = 16) == fstr | ||
|
||
fstr = """ | ||
test = [ | ||
arg1, arg2, | ||
arg3, | ||
arg4, | ||
arg5] | ||
""" | ||
@test format_text(str, SciMLStyle(), margin = 15) == fstr | ||
|
||
fstr = """ | ||
function foo( | ||
fstr = """ | ||
test = [arg1, | ||
arg2, | ||
arg3, | ||
arg4, | ||
arg5] | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look a bit weird. But this is how it's formatted on master. I only added these tests here to check that best optimal nesting still works with vector definitions because my previous attempt broke this.
looks good to me the nightly test failure is because of the new Memory type. I'm not sure what that's about. |
Do we have to wait for the nightly tests, or can we merge and release before that? |
we can merge it |
Before #792, default style
p_vect
andn_vect!
have always been used inSciMLStyle
, even withyas_style_nesting = true
. I restored this behavior.Closes #806.