Groovy formatter/beautifier in Visual Studio Code [closed]
Asked Answered
L

3

25

For supported files in VSCode we get an option (when you right click on the file editor) to Format Document (ALT+SHIFT+F).

But unfortunately for Groovy this option is not available. And according to the VSCode community, there are no plans to implement this feature.

Is there an alternative solution available, specifically for VSCode?

Loosen answered 14/7, 2018 at 4:59 Comment(0)
M
19

I don't know how well this works for formatting other than indentation, but I simply changed the file extension from .groovy to .js, right clicked in the file, and selected "Format Document". It fixed the indentation for me.

Manolo answered 20/9, 2018 at 21:18 Comment(3)
isn't .java formatter even more suitable for .groovy? Will have to try it myself...Yonita
Nice one, but it doesn't indent sh inside steps properly. More importantly, it can mess up the sh code by changing something like git checkout -b to git checkout - b, notice the unwanted "beauty" space! With that caveat, it's a fine workaround.Varsity
Pretty close to what I wanted, so +1 :)Incogitant
P
11

There is now a Visual Studio Code extension to Lint, Format and Auto-fix Groovy and Jenkinsfiles ! :)

https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint Visual Studio Code extension embedding npm-groovy-lint, itself embedding CodeNarc

Propylaeum answered 26/3, 2020 at 18:12 Comment(8)
meh, installed it, I try to run format and nothing happensLeveret
at least if doesn't correct indentation, it changed something it seemsLeveret
Please can you post your issue there ? github.com/nvuillam/vscode-groovy-lint/issuesPropylaeum
(you can also try to install java on your computer if you don't have it yet)Propylaeum
This didn't work for me. Doesn't fix indentationHastings
The formatter was not enabled by default, I had to press Shift + Alt + F and configure it as the default formatter for .groovy files. Once I did this, it started formatting on save.Andromede
it doesn't work for me. I'm still looking for a solution (or maybe even another IDE)Backstairs
npm-groovy-lint currently have maintenance issues, but it will work again somedayPropylaeum
P
5

It would only be available via an extension, which you can search for in the marketplace.

Unfortunately it doesn't look like there are many extensions for Groovy at all. And if that can be considered an indication of the language's popularity, it's highly unlikely that broad support would ever be added to VS Code out of the box.

Polack answered 14/7, 2018 at 5:31 Comment(7)
Incoming... I'm building a vscode extension for npm-groovy-lint, and formatting is in progress 🤓Propylaeum
@NicolasVuillamy is this built yet?Faefaeces
@KevinSummersill , marketplace.visualstudio.com/… , I'll publish a version with "Format" soon ( you can already format by using "Fix errors", but it also fix other errors than format like import order etc .... )Propylaeum
@KevinSummersill I just released 0.5.1, which contains support of "Format document" VsCode command ! :) marketplace.visualstudio.com/…Propylaeum
Unable to install 'nicolasvuillamy.vscode-groovy-lint' extension because it is not compatible with the current version of VS Code (version 1.40.1).Illustrate
Just upgrade your vscode to the latest version :)Propylaeum
Did you start writing the answer, then notice there was no plugin?! :DIncogitant

© 2022 - 2024 — McMap. All rights reserved.