VSCode formatting

Good day folks!

Is this canonical Ada formatting or is there a way to improve it in Visual Studio Code?

  type Size is
    (Device, Config, Intface, Endpoint, Audio_Endpoint, HUB_NonVAR,
     SS_Endpoint_Companion, BOS, Capability);
  for Size use
    (Device         => 18, Config => 9, Intface => 9, Endpoint => 7,
     Audio_Endpoint => 9, HUB_NonVAR => 7, SS_Endpoint_Companion => 6,
     BOS            => 5, Capability => 3);
  for Size'Size use Interfaces.C.unsigned_char'Size;
Thanks, Joel

The formatting is OK (personally I’d put each enumeration vaue on its own line).

It doesn’t compile, because the enumeration values (Endpoint => 7, etc) need to be (a) ordered the same as the enumerals (as you have it, Capability would have to be first) and (b) distinct.

The naming looks a bit odd. I don’t know what Device, Config etc are, but they’re probably not sizes.

type Thing is (Device, Config, ...);
Thing_Size: constant array (Thing) of Interfaces.C.unsigned_char :=
  (Device => 18,
   Config => 9,

This is a chunk of my libusb bindings code which I extracted out of context.

To narrow down my question, how do I make the VSCode Ada extension formatter put enumeration values each on a separate line? The formatting I posted is the one I get from the extension.

The only way I found to get the formatting I want is to put a comment after each enumeration value which is not ideal from my perspective.

It looks as though the formatting is done by gnatpp, which has an option (--vertical-enum-types) to put each enumeral on a separate line, but none that do what you want.

Thank you Simon!

As you said, it doesn’t quite do what I want. It verticall formats type ... is but doesn’t touch for ... use at all :-(.

This Github issue was very helpful.

That said, I cannot figure out how this works as I can’t find gnatpp in my Linux installation.

Anybody knows where it is?

It’s in crate libadalang_tools.

I couldn’t find where gnatpp gets installed by alr but --use-on-new-line formats use clauses the way I want it. Thanks Simon!

You can have gnatpp options in your project file and VSCode extension will take them into account. I have these for example:

   package Pretty_Printer is
      for Default_Switches ("ada") use
   end Pretty_Printer;

1 Like

libadalang_tools is installed using alr with libadalang_tools. That seems to be a per-project installation, rather than a toolchain installation. Do I understand that correctly? Will I have to re-install it for each project I work on, and if so, will it install multiple copies of the same thing?

Using Alire 2.0.0-beta1, you can install binary crates:

alr install libadalang_tools
1 Like

excellent, worked for me, thanks

Is the --no-vertical-enum-types option not yet available in gnatpp? It’s listed as a Legacy option on the documentation page at AdaCore.