Autoformatting in VS Code extension

I’m really enjoying getting to grips with Julia, and I’m finding VS Code a very nice way to code with Julia.

I’ve noticed that there is great auto formatting for indenting code in functions or for loops. For example…

But if you try to span line 14 over two lines then you get this by default


which is not as satisfying as something like this

Are there any plans to develop the auto formatting along these lines in the Julia VS Code extension?

EDIT: Hang on, I didn’t realise Julia for VS Code (not what I have?) is different from the Julia language support extension for VS Code (what I do have), or is it???

2 Likes

Those are one and the same :slight_smile:
I don’t think this is on the roadmap atm (or particularly easy to implement, for that matter), but feel free to open an issue over at GitHub - julia-vscode/julia-vscode: Julia extension for Visual Studio Code.

3 Likes

You could also try JuliaFormatter, which has more width-sensitive formatting than the formatter used by the VSCode extension. (IMO ideally someday the VSCode extension could switch over, ref https://github.com/julia-vscode/LanguageServer.jl/pull/759 This is now implemented in VSCode; see below). You can run JuliaFormatter from the command line, or via another extension, https://marketplace.visualstudio.com/items?itemName=singularitti.vscode-julia-formatter.

3 Likes

Yep, we plan to switch to JuliaFormatter once the code churn around the transition to CSTParser 3 has calmed down.

5 Likes

Nice. I’ll just wait patiently :slight_smile:

Using Julia in VS Code is really nice. Notebooks are fine, and I love the look of Pluto, but my preference is for VS Code at the moment. Fingers crossed it will get more an more fully featured - it should help people jump from things like Matlab or R into Julia :slight_smile:

Just to update this, the Julia VSCode extension now does use JuliaFormatter (since v1.5.0 of the extension). It’s configured by placing a .JuliaFormatter.toml file in the workspace, and run just by calling ”format document” in VSCode.

6 Likes