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

Formatting control #1217

Open
simonjwright opened this issue Oct 23, 2024 · 1 comment
Open

Formatting control #1217

simonjwright opened this issue Oct 23, 2024 · 1 comment
Assignees

Comments

@simonjwright
Copy link
Contributor

Formatting gives different results, depending on the formatting tool used (gnatpp, gnatstudio, ada-ts-mode), particularly for subwords.

Using ALS 25.0.20241014 on aarch64 macOS Sequoia 15.0.1.

Source code in formatting_control.zip.

I have this project demo.gpr

project demo is
   package pretty_printer is
      for default_switches ("ada") use
        ("--name-mixed-case",
         "--dictionary=case_exceptions.txt");
   end pretty_printer;
end demo;

with this case exception dictionary case_exceptions.txt

HTTP
ID

and this Ada source demo.adb

with ada.text_io;
with gnat.io;
with ada.containers.vectors;
procedure demo is
   package vectors is new ada.containers.vectors
     (index_type => natural, element_type => positive);
   package http renames vectors;
   subtype http_id is http.vector;
   subtype id is positive;
begin
   gnat.io.put_line ("test");
end demo;

With gnatpp 24.0.0, the formatted output is

$ gnatpp -Pdemo --pipe demo.adb
with Ada.Text_IO;
with GNAT.IO;
with Ada.Containers.Vectors;
procedure Demo is
   package Vectors is new Ada.Containers.Vectors
     (Index_Type => Natural, Element_Type => Positive);
   package HTTP renames Vectors;
   subtype Http_Id is HTTP.Vector;
   subtype ID is Positive;
begin
   GNAT.IO.Put_Line ("test");
end Demo;

where we see that http and id have been upcased, but http_id has merely been title-cased, whereas we’d have expected them to have been upcased too, as subwords.

With GNATStudio 25, as provided at Sourceforge by Blady, we get

with Ada.Text_IO;
with GNAT.IO;
with Ada.Containers.Vectors;
procedure Demo is
   package Vectors is new Ada.Containers.Vectors
     (Index_Type => Natural, Element_Type => Positive);
   package Http renames Vectors;
   subtype Http_Id is Http.Vector;
   subtype Id is Positive;
begin
   GNAT.IO.Put_Line ("test");
end Demo;

and neither http nor id has been upcased.

The same happens with ada-ts-mode, which is ALS-based.

If I alter case_exceptions.txt to what I believe to be an older way of specifying subwords

*HTTP*
*ID*

then gnatpp -Pdemo --pipe demo.adb gives

with Ada.Text_IO;
with GNAT.IO;
with Ada.Containers.Vectors;
procedure Demo is
   package Vectors is new Ada.Containers.Vectors
     (Index_Type => Natural, Element_Type => Positive);
   package HTTP renames Vectors;
   subtype HTTP_ID is HTTP.Vector;
   subtype ID is Positive;
begin
   GNAT.IO.Put_Line ("test");
end Demo;

(http and id are upcased everywhere! Great!)

GNATStudio gives

with Ada.Text_Io;
with Gnat.Io;
with Ada.Containers.Vectors;
procedure Demo is
   package Vectors is new Ada.Containers.Vectors
     (Index_Type => Natural, Element_Type => Positive);
   package Http renames Vectors;
   subtype Http_Id is Http.Vector;
   subtype Id is Positive;
begin
   Gnat.Io.Put_Line ("test");
end Demo;

(gnat, http, id, and io are title-cased).

ada-ts-mode gives

with Ada.Text_IO;
with GNAT.IO;
with Ada.Containers.Vectors;
procedure Demo is
   package Vectors is new Ada.Containers.Vectors
     (Index_Type => Natural, Element_Type => Positive);
   package Http renames Vectors;
   subtype Http_Id is Http.Vector;
   subtype Id is Positive;
begin
   GNAT.IO.Put_Line ("test");
end Demo;

(at least gnat and io are upcased).

@AnthonyLeonardoGracio
Copy link
Collaborator

Hello @simonjwright,

The current discrepancies are all explained under: #1216

To resume, the plan is to harmonize everything and rely only in the GNATformat engine in the future, baselining GNATpp and replacing GNAT Studio's current ad-hoc formatter by proper LSP formatting requests (which will use the GNATformat engine behind the scene).

Regards,

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

3 participants