Helix + LanguageServer.jl + JuliaFormatter.jl

I used the experimental juliac to build a statically linked formatter:

$ cat jlfmt.jl 
using JuliaFormatter
function @main(ARGS::Vector{String})::Cint
    try
        for f in ARGS
            if f == "-"
                print(format_text(read(stdin, String)))
            else
                format_file(f)
            end
        end
        return 0
    catch e
        @error "err:" e
        return 1
    end
end

This didn’t work unfortunately, there were too many functions that can’t be trimmed yet I guess

julia /usr/share/julia/juliac/juliac.jl --experimental --output-exe ./jlfmt --trim ./jlfmt.jl 

This did

julia /usr/share/julia/juliac/juliac.jl --output-exe ./jlfmt ./jlfmt.jl 

It unfortunately took minutes and made a very large binary

$ ls -lh jlfmt
-rwxr-xr-x 1 kousu kousu 264M Nov  9 01:27 jlfmt

but it worked in the end.

Here’s my config now:

$ cat ~/.config/helix/config.toml 
theme = "autumn_night"

$ cat ~/.config/helix/languages.toml 
[[language]]
name = "julia"
auto-format = true
formatter = { command = "/home/kousu/src/jlfmt", args = ["-"] }

With this, formatting on save or with = works instantly.

This doesn’t seem like a good solution. The language server is supposed to handle formatting. I wish to get it to a point where it does, out of the box.

Unfortunately, format-on-save swallows errors silently; if I mangle the code enough it can’t be formatted then = shows an error (but only the first line of the error, and quickly) and format-on-save doesn’t at all.

1 Like