julia-vscode / DocumentFormat.jl

Auto-formatter for Julia
Other
62 stars 18 forks source link

Function definitions within begin blocks are improperly indented #138

Closed jrising closed 2 years ago

jrising commented 3 years ago

DocumentFormat.jl does not seem to recognize function definitions as indent-needing blocks when they are contained within other begin blocks (or maybe just macro begin blocks?). The example is from the Mimi.jl framework, where this is common.

Here is the example:

@defcomp MyGreatComponent begin
    myoutput = Variable(index=[time])

    function run_timestep(p, v, d, t)
        if mytest
            v.myoutput[t] = 1
        else
            v.myoutput[t] = 0
        end
    end
end

which gets formatted as:

@defcomp MyGreatComponent begin
    myoutput = Variable(index=[time])

    function run_timestep(p, v, d, t)
    if mytest
        v.myoutput[t] = 1
    else
        v.myoutput[t] = 0
    end
end
end

There are a bunch of indentation oddities in how DocumentFormat.jl works on Mimi models (see https://github.com/openmodels/MimiPAGE2020.jl/pull/70), but this seems to be one of the easier ones to isolate (actual code in src/compute_scc.jl).