Formatter questions and alternatives [gnatformat, gnatpp]

Hi,

I have just installed gnatformat and gnatpp, but they both seem to be quite big for just an Ada code formatter.

Is there any other alternative available? For example, in C I use astyle.

I prefer for the code to be formatted on save (stdin β†’ stdout), is there any way of doing it with gnatformat or gnatpp?

Best regards
– zen

Probably counter intuitive but the ada_language_server has the ability to format code. (See Ada Language Server configuration β€” Ada & SPARK VS Code Extension User's Guide documentation)

It’s much larger then gnatformat and gnatpp tho!

Depending on your IDE and/or development style you would want to install it anyways for auto code completion.

You can try to run strip on executable to drop debug information from it. It should reduce size a lot.

It indeed reduced its size a lot.

$ du -sh *
67M	gnatformat
115M	gnatformat_heavy
70M	gnatpp
126M	gnatpp_heavy
$ du -sh /usr/bin/astyle
488K	/usr/bin/astyle

It feels to mee too heavy still for what appears to be a not too complex thing.

However, it does indeed format well I must say.

Is there a way to pipe (stdin β†’ gnatformat β†’ stdout) to format?

gnatformat --pipe should do the trick!

(At least the out part)

I think I will stick with gnatformat and gnatpp, but take note.

Yeah, that takes it to stdout, the issue is in taking stdin :thinking: .

I tried to pipe a file but it runs the formatter over the whole directory and the outputs it to stdout. Good if you are exporting to a pdf or similar I guess :slight_smile: .

When you say it’s too heavy, is it that you cannot use the tools ?

I can run gnatformat without issues, and the formatting is pretty good.

I had the intent of using it as a format on save, but I have not found an option to do that (stdin β†’ gnatformat β†’ stdout).

What I meant for too heavy is that it seems to take a while to load, at least running gnatformat --help has a noticeable delay. Not sure if that answers your question.

Best regards
– zen