AdaCore / AdaCore/gnatformat

Odd formatting of expression functions.

Open
#1 1 comment 0 reactions 1 assignee View on GitHub

@joaopsazevedo is already working on this.

Since Nov 26, 2024.

Dominant language
Ada
Stars
21
Forks
2
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.