Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Oct 1, 2023
1 parent b00a0ba commit 3c849ed
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
30 changes: 21 additions & 9 deletions src/styles/sciml/nest.jl
Original file line number Diff line number Diff line change
@@ -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!,
Expand All @@ -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)
Expand Down Expand Up @@ -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
44 changes: 37 additions & 7 deletions test/sciml_style.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand All @@ -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
"""

Expand Down Expand Up @@ -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

0 comments on commit 3c849ed

Please sign in to comment.