domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.
https://domluna.github.io/JuliaFormatter.jl/dev/
MIT License
569 stars 65 forks source link

How to integrate JuliaFormatter with Helix #868

Open arunoruto opened 2 weeks ago

arunoruto commented 2 weeks ago

I am currently using helix as my main "IDE" and I wanted to use it for Julia too. Configuring a formatter in helix is really straight forward: the contents will be passed to a command as stdin and the output is expected on stdout, as explained in this discussion. There are example in the README.md for formatting folders recursively and files. It would be nice if an example for stdin and stdout would be provided, if possible. If not, adding this feature would benefit. An example for an abstract language is also provided here by helix.

arunoruto commented 2 weeks ago

Well, after digging more into this (I am a bit new to Julia and its ecosystem), I found a suitable solution! The following configuration of helix works for me:

[[language]]
name = "julia"
...

[language.formatter]
args = ["--startup-file=no", "--history-file=no", "--quiet", "-e", "using JuliaFormatter; println(format_text(join(readlines(stdin), '\\n')))"]
command = "julia"

This will work for now, but it is a bit slowish. I am not sure if I am doing something wrong, so if there is a better/faster way, I am eager to learn it :)

I will keep the issue open for now, but if no one replies to it, I will close it.

domluna commented 1 week ago

that's probably the way to do it but it would probably be better if you used format(filename) because if you call format_text(...) then any configuration in your directory, such as a .JuliaFormatter.toml file won't be detected.

arunoruto commented 1 week ago

I will have to look into how or if helix provides a filename too. To my knowledge, only the to be formated text is provided via stdin and returned in stdout.