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

Odd formatting of expression functions. #1

Open
pyjarrett opened this issue Nov 2, 2024 · 1 comment
Open

Odd formatting of expression functions. #1

pyjarrett opened this issue Nov 2, 2024 · 1 comment
Assignees

Comments

@pyjarrett
Copy link

Strange scenario here:

with Ada.Directories;
with Ada.Strings.Unbounded;

package Foo is
   package AD renames Ada.Directories;
   package ASU renames Ada.Strings.Unbounded;

   type Site_Config is tagged limited record
      Dry_Run : Boolean := True;
      Site_Root : ASU.Unbounded_String;
   end record;

   function "+"(S : ASU.Unbounded_String) return String renames ASU.To_String;

   function Root_Dir (Config : Site_Config) return String is (+Config.Site_Root & "/");
   function Output_Dir (Config : Site_Config) return String is (+Config.Site_Root & "/html");
   function Source_Dir (Config : Site_Config) return String is (+Config.Site_Root & "/md");
   function Config_Dir (Config : Site_Config) return String is (+Config.Site_Root & "/config");

   procedure Build_Site (Root : String);
end Foo;

The center lines with expression functions reformat split lines, even though I'd rather keep them together:

   function Root_Dir (Config : Site_Config) return String
   is (+Config.Site_Root & "/");
   function Output_Dir (Config : Site_Config) return String
   is (+Config.Site_Root & "/html");
   function Source_Dir (Config : Site_Config) return String
   is (+Config.Site_Root & "/md");
   function Config_Dir (Config : Site_Config) return String
   is (+Config.Site_Root & "/config");

This still occurs even with these Package settings:

    package Format is
       for Width ("Ada") use "120";
    end Format;

This continuation of expression functions along the same line might not be wanted by everyone. With the old formatter, I could use --!pp off and --!pp on to ignore lines. While GnatFormat works great in a lot of situations, it'd be great if I could ignore lines to get the behavior I want.

@joaopsazevedo joaopsazevedo self-assigned this Nov 26, 2024
@joaopsazevedo
Copy link
Collaborator

Hello @pyjarrett

What you're observing is intentional, i.e., for expression functions, there is always a hard line break before the is keyword.

For GNATformat, we decided to have an opinionated formatter approach, therefore, in AdaCore, our goal for the coming months is to reach a consensus on a formatting style that most Ada developers (both from the community and customers) are happy to use. With that said, I'm afraid that this case has already been discussed and we decided to always have a hard line break before the is.

However, I encourage you to keep reporting possible style issues since they will taken into account.

We also realize that there might be some disagreement on the style chosen for certain constructs, so we will provide two work arounds:

  1. As you mentioned, a way to deactivate formatting on certain ranges (using directives like --!pp off)
  2. Allow overriding the formatting style configuration. GNATformat is an AST based formatter. There is a style configuration for each node, which you will be able to override. This requires getting familiar with the AST produced by Libadalang and with the configuration language. There will be proper documentation for those who would like to explore this feature. For a simple example like this one, it should not be difficult.

I'll leave the issue open until these two features are implemented.

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

2 participants