Skip to content

Commit

Permalink
add check to the pass instead
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Sep 9, 2023
1 parent 14c11bf commit 6b1799b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ end
function short_to_long_function_def!(fst::FST, s::State)
(fst[1].typ !== Call && fst[1].typ !== Where) && return false

# do not apply if parent is a function or macro definition
parent_is(
fst.ref[],
n -> is_function_or_macro_def(n) || n.head == :macrocall;
ignore = n -> is_block(n),
) && return false

# 3 cases
#
# case 1
Expand Down
9 changes: 1 addition & 8 deletions src/styles/sciml/nest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ function n_binaryopcall!(ss::SciMLStyle, fst::FST, s::State; indent::Int = -1)
line_margin = s.line_offset + length(fst) + fst.extra_margin
if line_margin > s.opts.margin &&
fst.ref !== nothing &&
(
!parent_is(
fst.ref[],
n -> is_function_or_macro_def(n) || n.head == :macrocall;
ignore = n -> is_block(n),
)
)
CSTParser.defines_function(fst.ref[])
CSTParser.defines_function(fst.ref[])
transformed = short_to_long_function_def!(fst, s)
transformed && nest!(style, fst, s)
end
Expand Down
21 changes: 21 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1706,4 +1706,25 @@
"""
@test fmt(str_, 4, 92, join_lines_based_on_source = true) == str
end

@testset "753" begin
str_ = """
using ModelingToolkit
@mtkmodel A begin
@variables begin
i(t) = 0.0, [description = "Line longer than the char limit of 94 characters", unit = u"A"]
end
end
"""
str = """
using ModelingToolkit
@mtkmodel A begin
@variables begin
i(t) = 0.0,
[description = "Line longer than the char limit of 94 characters", unit = u"A"]
end
end
"""
@test format_text(str_, SciMLStyle()) == str
end
end

0 comments on commit 6b1799b

Please sign in to comment.