JuliaFormatter and VSCode - how to change options?

I understand that the VSCode extension now uses the JuliaFormatter.jl package. This is great, but I’m a little perplexed as to where I’m supposed to put my .JuliaFormatter.toml since I can’t change it from the VSCode settings anymore?

1 Like

You need to put it in your github repo (or whatever) on a per-project basis. So put it in the root of the vscode project when you open it, and it will work great.

For what it is worth, I think this was the right call for the team. Settings should be reproducible for collaboration or if you download your project to another machine, and this helps formalize that.

1 Like

But is there a way to have a more system wide default formatting choice that is then overridden by the local .JuliaFormatter.toml file if present?

2 Likes

No.

I see. Would that be a possible feature, or is the current design incompatible with this?

It’s definitely possible to look at e.g. DEPOT_PATH[...]/config/.JuliaFormatter.toml, but I’m not sure that’s actually a good idea for the reasons that @jlperla pointed out above. It’s also subtly different to the normal JuliaFormatter.jl behaviour, which will search up the directory tree until it finds a config file.

What is the rationale not to search up the directory tree until it finds a config file? IMHO, it is convenient for a more global workspace format setting.

2 Likes

For what it is worth, I fully support @pfitzseb decision on this for several different reasons:

  1. It makes code changes and formatting fully reproducible for yourself and for others. You don’t copy around a file to distribute, or forget to modify it on your own machine.
  2. I think it will be a lot easier to maintain for the vscode developers. Otherwise they get involved with responding to users and debugging problems with paths/etc. global depots/etc. where they could have been working on better features ( like builtin Infiltrator.jl support :slight_smile: )
  3. There is essentially no case at this point where you shouldn’t have these inside of a directory, and in using vscode you definetely never would.
  4. python black and other inspirations for this have a similar setup without global configuration, which suggests they have already though through this issue.

It’s also subtly different to the normal JuliaFormatter.jl >behaviour, which will search up the directory tree until it >finds a config file.

If I understand this correctly, by putting the .JuliaFormatter.toml in my home directory in linux, Juliaformatter should find it and use that if of course my project is somewhere deepdown in my home, correct?

@Olivier_Merchiers from what I can tell, no, but perhaps because there’s another .JuliaFormatter.toml lurking somewhere.

Personally I don’t mind the way it’s set up (I can see both sides of the argument as it were). I would just say that in the VSCode documentation the following sentence:

The default formatting is fairly conservative and unintrusive, but you can customise it with a .JuliaFormatter.toml . Check out the relevant documentation here.

Could have the following added:

The default formatting is fairly conservative and unintrusive, but you can customise it with a .JuliaFormatter.toml which must be present in your workspace folder (see the documentation on search rules here. Check out the relevant documentation here.

Or similar. Since my post was motivated by the fact that this behaviour within VSCode changed and I wasn’t sure what to do because of this.

Thanks to @pfitzseb and others for all the hard work you’ve put into this and your responsiveness!

2 Likes

That’s already changed on /dev :slight_smile:

3 Likes

I agree, this would be a very useful addition to the docs! I was confused about this for about an hour this morning, after migrating from singularitti’s JuliaFormatter extension to the inbuilt one.

I made a strawman PR here: Clarify necessary location of .JuliaFormatter.toml by tpgillam · Pull Request #60 · julia-vscode/docs · GitHub

Somehow, I fail to use the formatting settings correctly.

In the extension settings there is a field “flag” which accepts formatting options. However, they are not respected in my case when I press Ctrl-K + Ctrl-F.
I have defined a .JuliaFormatter.toml in a parent directory, which is also not used.

However, if I call

using JuliaFormatter
Juliaformatter.fomat(<myfile>)

the settings from .JuliaFormatter.toml are appplied.

What am I doing wrong?

Perhaps the settings flags and .JuliaFormatter.toml are interacting badly?

Without a .JuliaFormatter.toml I also do not see any influence of the flags.

EDIT: I didn’t read carefully the posts above, it’s all there. The config file is only used for formatting, if it is located in one of the workspace folders. My bad!