Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide more control over formatting. #1076

Open
stephe-ada-guru opened this issue Nov 8, 2022 · 6 comments
Open

provide more control over formatting. #1076

stephe-ada-guru opened this issue Nov 8, 2022 · 6 comments
Assignees

Comments

@stephe-ada-guru
Copy link

ada_language_server uses the gnatpp code to do formatting. That code supports several options that control the formatting. In particular, some combination of settings results in "just indent", which is what Emacs ada-mode wants when the user invokes indent-line.

So it would be nice if there was a way to pass those options to the server, perhaps via an LSP extension command ada_format_options.

In addition, the gnatpp code has a set of formatting rules that can be specified in a file (at least, it did last time I looked; it seems that feature was only intended for internal development). It would be nice to allow the user to specify a file to replace the formatting rules; then we could implement any formatting style using ada_language_server.

@kevlar700
Copy link

kevlar700 commented Nov 9, 2022

I'm not from Adacore but Gnat Studio edits the .gpr project file when setting formatting options.

Package Pretty_Printer is
           for Default_Switches ("ada") use ("--call-threshold=1");
end Pretty_Printer;

@stephe-ada-guru
Copy link
Author

@kevlar700; yes, Gnat Studio calls gnatpp more directly; it doesn't go thru the LSP interface.

@AnthonyLeonardoGracio
Copy link
Collaborator

Hello @stephe-ada-guru ,

The Ada Language Server normally reads the gnatpp options specified in your project file, is it not the case for you?

@stephe-ada-guru
Copy link
Author

@AnthonyLeonardoGracio I was not aware of the gnatpp package in a project file (and I did not make the connection that it implies that ada_language_server reads those options). I gather the list of options is given by "gnatpp --help"; that is quite extensive, but it's not powerful enough to match my style, nor Eurocontrol's. --source-line-breaks may be enough for Emacs indent. I'll have to experiment and submit more suggestions for the controls I need.

Thanks for the nudge :).

@stephe-ada-guru
Copy link
Author

Adding a Pretty_Printer package in the project file does allow setting --source-line-breaks. But it's inconvenient to have to add that in every project file, so it would be better if als accepted all pretty printer parameters via the LSP interface.

@joaopsazevedo joaopsazevedo self-assigned this Dec 14, 2022
@joelreymont
Copy link

joelreymont commented Oct 18, 2023

What binary does the formatting and where is it located?

I added the --vertical-enum-types option and it formatted type Kind is... below, but left the for Kind use... unformatted :-(. I'd like to figure out what options are required for the for ... is part as neither of the following

Package Pretty_Printer is
      for Default_Switches ("ada") use 
      ("--vertical-enum-types",
       "--no-align-modes",
       "--no-separate-is",
       "--call-threshold=1",
       "--par-threshold=2",
       "--vertical-named-aggregates");
   end Pretty_Printer;

properly formats this code

    type Kind is
     (Device,
      Config,
      String,
      Intface,
      Endpoint,
      BOS,
      Capability,
      HID,
      Report,
      Physical,
      HUB,
      Superspeed_HUB,
      SS_Endpoint_Companion);
    for Kind use
     (Device => 16#01#, Config => 16#02#, String => 16#03#, Iface => 16#04#,
      Endpoint => 16#05#, BOS => 16#0F#, Capability => 16#10#, HID => 16#21#,
      Report         => 16#22#, Physical => 16#23#, HUB => 16#29#,
      Superspeed_HUB => 16#2A#, SS_Endpoint_Companion => 16#30#);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants