julia-vscode / DocumentFormat.jl

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

Weird indent problem #141

Closed tk3369 closed 2 years ago

tk3369 commented 3 years ago

It's a little weird but VSCode randomly indent lines incorrectly. I have worked out a MWE below.

How to replicate.

  1. Copy the following code to Julia editor
  2. Run "Format Document"
  3. Result: the jc_today line got flushed left (i.e. no indent)

Note that the code does not make any sense because I have deleted everything that doesn't cause the indent problem. And funny enough, if I comment out any line then the problem goes away.

function commander(c::Client, m::Message, ::Val{:julia_con})
    arg = (occursin(r"[0-9]+", args[1]) ? "jc" : "") * args[1]
end

function jc_execute(c, m, ::Val{:now}, args)
    tz_arg = isempty(args) || !TimeZones.istimezone(args[1]) ? "UTC" : args[1]
    current = ZonedDateTime(now(), TimeZone(tz_arg))
end

function jc_execute(c, m, ::Val{:today}, args)
    tz_arg = isempty(args) || !TimeZones.istimezone(args[1]) ? "UTC" : args[1]
    dt = now(TimeZone(tz_arg))
    jc_today(c, m, dt)
    return nothing
end

My workaround is a little stupid:

    jc_today(c, m, dt)  # just adding a comment fixes indenting

The problem is that it's broken randomly. It's hard for me to catch every line that's broken and add a comment everywhere.