From 3c849ed8ab73717f804bd3afd65b05d78eca66be Mon Sep 17 00:00:00 2001 From: Dominique Luna Date: Sat, 30 Sep 2023 21:30:46 -0400 Subject: [PATCH] ok --- src/styles/sciml/nest.jl | 30 +++++++++++++++++++-------- test/sciml_style.jl | 44 +++++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/styles/sciml/nest.jl b/src/styles/sciml/nest.jl index e5f26350a..87a5bb777 100644 --- a/src/styles/sciml/nest.jl +++ b/src/styles/sciml/nest.jl @@ -1,10 +1,8 @@ for f in [ - # :n_call!, :n_curly!, :n_ref!, :n_macrocall!, :n_typedcomprehension!, - # :n_tuple!, :n_braces!, :n_parameters!, :n_invisbrackets!, @@ -21,6 +19,8 @@ for f in [ :n_chainopcall!, :n_comparison!, :n_for!, + # :n_tuple!, + # :n_call!, #:n_vect! ] @eval function $f(ss::SciMLStyle, fst::FST, s::State) @@ -52,16 +52,28 @@ function n_binaryopcall!(ss::SciMLStyle, fst::FST, s::State; indent::Int = -1) nest!(style, fst[end], s) end -n_call!(ds::SciMLStyle, fst::FST, s::State) = n_tuple!(ds, fst, s) +function n_call!(ds::SciMLStyle, fst::FST, s::State) + style = getstyle(ds) + if s.opts.yas_style_nesting + n_call!(YASStyle(style), fst, s) + return + end + n_tuple!(ds, fst, s) +end + function n_tuple!(ds::SciMLStyle, fst::FST, s::State) style = getstyle(ds) + if s.opts.yas_style_nesting + n_tuple!(YASStyle(style), fst, s) + return + end + n_tuple!(DefaultStyle(style), fst, s) - if fst.ref !== nothing && - parent_is(fst.ref[], n -> is_function_or_macro_def(n) || n.head == :macrocall) - add_indent!(fst, s, s.opts.indent) - if is_closer(fst[end]) + if fst.ref !== nothing && + parent_is(fst.ref[], n -> is_function_or_macro_def(n) || n.head == :macrocall) + add_indent!(fst, s, s.opts.indent) + if is_closer(fst[end]) fst[end].indent -= s.opts.indent - end end - return + end end diff --git a/test/sciml_style.jl b/test/sciml_style.jl index 73e13d239..76e36cfe5 100644 --- a/test/sciml_style.jl +++ b/test/sciml_style.jl @@ -36,11 +36,11 @@ """ formatted_str = raw""" function BipartiteGraph( - fadj::AbstractVector, - badj::Union{AbstractVector, Integer} = maximum(maximum, fadj); - metadata = nothing, + fadj::AbstractVector, + badj::Union{AbstractVector, Integer} = maximum(maximum, fadj); + metadata = nothing, ) - BipartiteGraph(mapreduce(length, +, fadj; init = 0), fadj, badj, metadata) + BipartiteGraph(mapreduce(length, +, fadj; init = 0), fadj, badj, metadata) end """ @test format_text(str, SciMLStyle()) == formatted_str @@ -71,8 +71,8 @@ formatted_str = raw""" function my_large_function(argument1, argument2, - argument3, argument4, - argument5, x, y, z) + argument3, argument4, + argument5, x, y, z) foo(x) + goo(y) end """ @@ -81,7 +81,7 @@ function my_large_function(argument1, argument2, argument3, argument4, argument5, x, y, z) - foo(x) + goo(y) + foo(x) + goo(y) end """ @@ -302,4 +302,34 @@ @test format_text(str, SciMLStyle(), variable_call_indent = ["test"]) == formatted_str @test format_text(str, SciMLStyle(), variable_call_indent = ["SVector", "test"]) == formatted_str + + @testset "741" begin + s = """ + function get_num_majumps(smaj::SpatialMassActionJump{Nothing,B,S,U,V}) where {B,S,U,V} + return size(smaj.spatial_rates, 1) + end + """ + fs = """ + function get_num_majumps( + smaj::SpatialMassActionJump{Nothing, B, S, U, V}, + ) where {B, S, U, V} + return size(smaj.spatial_rates, 1) + end + """ + @test format_text(s, SciMLStyle()) == fs + + s = """ + macro get_num_majumps(smaj::SpatialMassActionJump{Nothing,B,S,U,V}) where {B,S,U,V} + return size(smaj.spatial_rates, 1) + end + """ + fs = """ + macro get_num_majumps( + smaj::SpatialMassActionJump{Nothing, B, S, U, V}, + ) where {B, S, U, V} + return size(smaj.spatial_rates, 1) + end + """ + @test format_text(s, SciMLStyle(), margin=89) == fs + end end