Skip to content

Commit

Permalink
fix JuliaFormatter config extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 3, 2021
1 parent 1af53df commit 74044e2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/formatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ handle("format") do data
end
end

# HACK: extract keyword arguments of `format_text`; `Base.kwarg_decl` isn't available as of v1.0
const FORMAT_TEXT_KWARGS = try
s = filter!(collect(methods(format_text))) do m
return m.module == JuliaFormatter &&
length(m.sig.types) === 2
end |> first |> string
m = match(r";(.+)\)", s)
m === nothing ? Symbol[] : Symbol.(strip.(split(m.captures[1]), Ref((' ', ','))))
catch
Symbol[]
const FORMAT_TEXT_KWARGS = @static if isdefined(JuliaFormatter, :Options)
fieldnames(JuliaFormatter.Options)
else
# HACK: extract keyword arguments of `format_text`; `Base.kwarg_decl` isn't available as of v1.0
try
s = filter!(collect(methods(format_text))) do m
return m.module == JuliaFormatter &&
length(m.sig.types) === 2
end |> first |> string
m = match(r";(.+)\)", s)
m === nothing ? Symbol[] : Symbol.(strip.(split(m.captures[1]), Ref((' ', ','))))
catch
Symbol[]
end
end

isempty(FORMAT_TEXT_KWARGS) && @warn """
Expand Down

0 comments on commit 74044e2

Please sign in to comment.