AdaCore / ada_language_server

Server implementing the Microsoft Language Protocol for Ada and SPARK
GNU General Public License v3.0
226 stars 54 forks source link

Format: With "--source-line-breaks" switch, result is sometimes incorrect #1175

Open JHag6694 opened 6 months ago

JHag6694 commented 6 months ago

With switch "--source-line-breaks" activated in Pretty_Printer package, I face 2 problems when formating code with comments

  1. "Format Selection" on a comment line delete 2 trailing characters

  2. "Format Document" shift case / if instructions when preceded with a comment line.

Source example:

-- TOP OF FILE
with Ada.Text_Io;
package body Messages is
   use type Ada.Text_Io.Count;

   First_Hello : Boolean := False;

   -- #2 : 'Format selection' on this comment line delete 2 trailing chars

   procedure Hello_Hello is null;

   procedure You_Say_Hello is
   begin
      -- #3 : This comment makes the case instruction is right shifted on 'format document'
      case First_Hello is
         when True =>
            Ada.Text_Io.Put_Line ("Hello");
         when False =>
            Ada.Text_Io.Put_Line ("Hello again");
      end case;
   end;

   procedure I_Say_Goodbye is
   begin
      case First_Hello is
         when True =>null;
         when False =>Ada.Text_Io.Put_Line ("Goodbye");
      end case;
   end;

end Messages;

Full source code and project settings to reproduce the issue: https://github.com/JHag6694/AdaTest