Skip to content

Commit

Permalink
indent fargs
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Oct 1, 2023
1 parent 9edea60 commit e20cda3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 48 deletions.
15 changes: 13 additions & 2 deletions src/styles/sciml/nest.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
for f in [
:n_call!,
# :n_call!,
:n_curly!,
:n_ref!,
:n_macrocall!,
:n_typedcomprehension!,
:n_tuple!,
# :n_tuple!,
:n_braces!,
:n_parameters!,
:n_invisbrackets!,
Expand Down Expand Up @@ -51,3 +51,14 @@ function n_binaryopcall!(ss::SciMLStyle, fst::FST, s::State; indent::Int = -1)
walk(increment_line_offset!, (fst.nodes::Vector)[1:end-1], s, fst.indent)
nest!(style, fst[end], s)
end

n_call!(ds::SciMLStyle, fst::FST, s::State) = n_tuple!(ds, fst, s)
function n_tuple!(ds::SciMLStyle, fst::FST, s::State)
style = getstyle(ds)
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)
end
return
end
95 changes: 49 additions & 46 deletions src/styles/sciml/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,49 +210,52 @@ function p_unaryopcall(ds::SciMLStyle, cst::CSTParser.EXPR, s::State; kwargs...)
t
end

function p_functiondef(ds::SciMLStyle, cst::CSTParser.EXPR, s::State)
style = getstyle(ds)
t = FST(FunctionN, cst, nspaces(s))
add_node!(t, pretty(style, cst[1], s), s)
add_node!(t, Whitespace(1), s)
add_node!(t, pretty(style, cst[2], s), s, join_lines = true)
if length(cst) > 3
if cst[3].fullspan == 0
n = pretty(style, cst[4], s)
if s.opts.join_lines_based_on_source
join_lines = t.endline == n.startline
join_lines && (add_node!(t, Whitespace(1), s))
add_node!(t, n, s, join_lines = join_lines)
else
add_node!(t, Whitespace(1), s)
add_node!(t, n, s, join_lines = true)
end
else
indent = s.opts.indent * 2
s.indent += indent
n = pretty(style, cst[3], s, ignore_single_line = true)
s.opts.always_use_return && prepend_return!(n, s)
add_node!(t, n, s, max_padding = indent)
s.indent -= indent
add_node!(t, pretty(style, cst[4], s), s)
end
else
# function stub `function foo end`
n = pretty(style, cst[3], s)
if s.opts.join_lines_based_on_source
join_lines = t.endline == n.startline
join_lines && (add_node!(t, Whitespace(1), s))
add_node!(t, n, s, join_lines = join_lines)
else
add_node!(t, Whitespace(1), s)
add_node!(t, n, s, join_lines = true)
end
end
t
end

function p_macro(ds::SciMLStyle, cst::CSTParser.EXPR, s::State)
t = p_functiondef(ds, cst, s)
t.typ = Macro
t
end
# function p_functiondef(ds::SciMLStyle, cst::CSTParser.EXPR, s::State)
# style = getstyle(ds)
# t = FST(FunctionN, cst, nspaces(s))
# add_node!(t, pretty(style, cst[1], s), s)
# add_node!(t, Whitespace(1), s)
# fargs = pretty(style, cst[2], s)
# fargs.indent += s.opts.indent
# add_node!(t, fargs, s, join_lines = true)
# @info "" fargs.indent fargs.typ
# @info "" map(x -> x.typ, fargs)
# if length(cst) > 3
# if cst[3].fullspan == 0
# n = pretty(style, cst[4], s)
# if s.opts.join_lines_based_on_source
# join_lines = t.endline == n.startline
# join_lines && (add_node!(t, Whitespace(1), s))
# add_node!(t, n, s, join_lines = join_lines)
# else
# add_node!(t, Whitespace(1), s)
# add_node!(t, n, s, join_lines = true)
# end
# else
# s.indent += s.opts.indent
# n = pretty(style, cst[3], s, ignore_single_line = true)
# s.opts.always_use_return && prepend_return!(n, s)
# add_node!(t, n, s, max_padding = s.opts.indent)
# s.indent -= s.opts.indent
# add_node!(t, pretty(style, cst[4], s), s)
# end
# else
# # function stub `function foo end`
# n = pretty(style, cst[3], s)
# if s.opts.join_lines_based_on_source
# join_lines = t.endline == n.startline
# join_lines && (add_node!(t, Whitespace(1), s))
# add_node!(t, n, s, join_lines = join_lines)
# else
# add_node!(t, Whitespace(1), s)
# add_node!(t, n, s, join_lines = true)
# end
# end
# t
# end
#
# function p_macro(ds::SciMLStyle, cst::CSTParser.EXPR, s::State)
# t = p_functiondef(ds, cst, s)
# t.typ = Macro
# t
# end

0 comments on commit e20cda3

Please sign in to comment.