AdaCore / gnatstudio

GNAT Studio is a powerful and lightweight IDE for Ada and SPARK.
409 stars 53 forks source link

Auto-fix for a -gnatwk warning hit applies wrong indentation #152

Closed zertovitch closed 11 months ago

zertovitch commented 1 year ago

Hereafter is a reproducer for the issue in title. When applying the suggested auto-fix, the indentation seems to imitate that of the previous line; at least not that of current line.

k_warning.adb:

with Ada.Text_IO;

procedure K_Warning is
   msg : String := "Hello!";  --  <---  Here the auto-fix is applied.
   use Ada.Text_IO;
begin
   Put_Line (msg);
   --
   --  Apply autofix for the following:
   --
   --  k_warning.adb:4:4: warning: "msg" is not modified, could be declared constant
   --
end K_Warning;

k_warning.gpr:

project K_Warning is

   for Object_Dir use "obj";
   for Main use ("k_warning.adb");
   for Create_Missing_Dirs use "True";

   package Compiler is
      for Switches ("ada") use ("-gnatwk");
   end Compiler;

end K_Warning;
AnthonyLeonardoGracio commented 1 year ago

Hello @zertovitch ,

I get

with Ada.Text_IO;

procedure K_Warning is
   msg : constant String := "Hello!";  --  <---  Here the auto-fix is applied.
   use Ada.Text_IO;
begin
   Put_Line (msg);
   --
   --  Apply autofix for the following:
   --
   --  k_warning.adb:4:4: warning: "msg" is not modified, could be declared constant
   --
end K_Warning;

with your reproducer, which seems correct to me. What is the result you would expect?

Regards,

zertovitch commented 1 year ago

Perhaps you have tested with Auto indentation (Preferences/Editor/Ada) on "Extended" or "None" ? If I set the Auto indentation on "Simple" (and only then) I get the following:

with Ada.Text_IO;

procedure K_Warning is
msg : constant String := "Hello!";  --  <---  Here the auto-fix is applied.
   use Ada.Text_IO;
begin
   Put_Line (msg);
   --
   --  Apply autofix for the following:
   --
   --  k_warning.adb:4:4: warning: "msg" is not modified, could be declared constant
   --
end K_Warning;