Skip to content

Commit

Permalink
V413-006 Fixing tabulations handling in code-fix
Browse files Browse the repository at this point in the history
Change-Id: I91d1c3720154bac50428f4a690cdfcd00979b475
Depends-On: I87bbdb69504ec92127c517e611346d057ecfa735
Depends-On: I6ffe8f79e75993c4a3e68a9ceb6de0df0715952d
  • Loading branch information
ogorodnik committed May 11, 2022
1 parent 389bae4 commit 0fc4233
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 118 deletions.
16 changes: 12 additions & 4 deletions codefix/core/src/codefix-ada_tools.adb
Expand Up @@ -281,7 +281,9 @@ package body Codefix.Ada_Tools is
Line => Get_Construct (Iterator).Sloc_Start.Line,
Column => To_Column_Index
(String_Index_Type
(Get_Construct (Iterator).Sloc_Start.Column), Line));
(Get_Construct (Iterator).Sloc_Start.Column),
Line,
Current_Text.Tab_Width (File_Name)));
end;

Append (Result, New_Clause);
Expand Down Expand Up @@ -374,7 +376,9 @@ package body Codefix.Ada_Tools is
(Current_Cursor,
To_Column_Index
(String_Index_Type
(Get_Construct (Last_Info).Sloc_End.Column) + 1, Line));
(Get_Construct (Last_Info).Sloc_End.Column) + 1,
Line,
Current_Text.Tab_Width (File_Name)));
end;
else
Set_Location (Current_Cursor, 0, 1);
Expand Down Expand Up @@ -454,7 +458,9 @@ package body Codefix.Ada_Tools is
(Current_Cursor,
To_Column_Index
(String_Index_Type
(Get_Construct (Last_Info).Sloc_End.Column) + 1, Line));
(Get_Construct (Last_Info).Sloc_End.Column) + 1,
Line,
Current_Text.Tab_Width (File_Name)));
end;
else
Set_Location (Current_Cursor, 0, 1);
Expand Down Expand Up @@ -499,7 +505,9 @@ package body Codefix.Ada_Tools is
(Result, Get_Construct (Iterator).Sloc_Start.Line,
To_Column_Index
(String_Index_Type
(Get_Construct (Iterator).Sloc_Start.Column), Line));
(Get_Construct (Iterator).Sloc_Start.Column),
Line,
Current_Text.Tab_Width (File_Name)));
end;

Lock.Unlock;
Expand Down
18 changes: 11 additions & 7 deletions codefix/core/src/codefix-formal_errors.adb
Expand Up @@ -725,14 +725,18 @@ package body Codefix.Formal_Errors is
if Apply_Also_On_Decl then
declare
File : constant Structured_File_Access :=
Current_Text.Get_Structured_File
(Message.Get_File);
Decl_Entity : constant Entity_Access := Find_Declaration
(Lang => Get_Tree_Language (File),
File => File,
Line => Word.Get_Line,
Column => String_Index_Type (Word.Get_Column));
Current_Text.Get_Structured_File
(Message.Get_File);
Decl_Entity : Entity_Access;
begin
if File /= null then
Decl_Entity := Find_Declaration
(Lang => Get_Tree_Language (File),
File => File,
Line => Word.Get_Line,
Column => String_Index_Type (Word.Get_Column));
end if;

if Decl_Entity /= Null_Entity_Access then
declare
Decl_Construct : constant access
Expand Down
7 changes: 3 additions & 4 deletions codefix/core/src/codefix-gnat_parser.adb
Expand Up @@ -2390,9 +2390,9 @@ package body Codefix.GNAT_Parser is
begin
Solutions :=
Unexpected
(Current_Text,
Message,
To_Unbounded_String
(Current_Text => Current_Text,
Message => Message,
String_Unexpected => To_Unbounded_String
(Get_Message (Message) (Matches (1).First .. Matches (1).Last)));
end Fix;

Expand Down Expand Up @@ -4140,7 +4140,6 @@ package body Codefix.GNAT_Parser is
if Length (Solutions) = 0 then
raise Uncorrectable_Message;
end if;

end Fix;

----------------
Expand Down
86 changes: 61 additions & 25 deletions codefix/core/src/codefix-text_manager-ada_commands.adb
Expand Up @@ -97,7 +97,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Close_Cursor.Set_Line (Sloc_Start.Line);
Close_Cursor.Set_Column
(To_Column_Index
(String_Index_Type (Sloc_Start.Column), Line));
(String_Index_Type (Sloc_Start.Column),
Line,
Current_Text.Tab_Width (Open_Cursor.File)));

return True;
end if;
Expand Down Expand Up @@ -201,10 +203,11 @@ package body Codefix.Text_Manager.Ada_Commands is
loop
declare
Full_Line : constant String :=
Get_Line (Current_Text, End_Cursor, 1);
J : String_Index_Type :=
To_Char_Index
(Get_Column (End_Cursor), Full_Line) - 1;
Get_Line (Current_Text, End_Cursor, 1);
J : String_Index_Type := To_Char_Index
(Get_Column (End_Cursor),
Full_Line,
Current_Text.Tab_Width (End_Cursor.Get_File)) - 1;

begin
-- Skip previous blanks
Expand All @@ -222,7 +225,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Set_Location
(End_Cursor,
Get_Line (End_Cursor),
To_Column_Index (J, Full_Line) + 1);
To_Column_Index
(J, Full_Line,
Current_Text.Tab_Width (End_Cursor.Get_File)) + 1);

exit;

Expand All @@ -244,7 +249,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Set_Location
(End_Cursor,
Get_Line (End_Cursor),
To_Column_Index (J, Full_Line));
To_Column_Index
(J, Full_Line,
Current_Text.Tab_Width (End_Cursor.Get_File)));

exit;
end if;
Expand Down Expand Up @@ -876,7 +883,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Set_Location
(Position,
Get_Construct (Declaration).Sloc_End.Line,
To_Column_Index (Char_Ind, Line));
To_Column_Index
(Char_Ind, Line,
Current_Text.Tab_Width (Cursor.Get_File)));
end;
end Add_Pragma;

Expand Down Expand Up @@ -909,7 +918,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Set_Location
(Position,
Get_Construct (Clause).Sloc_End.Line,
To_Column_Index (Char_Ind, Line));
To_Column_Index
(Char_Ind, Line,
Current_Text.Tab_Width (Cursor.Get_File)));
end;
end Add_Clause_Pragma;

Expand Down Expand Up @@ -943,7 +954,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Set_Location
(Position,
Get_Construct (Declaration).Sloc_End.Line,
To_Column_Index (Char_Ind, Line));
To_Column_Index
(Char_Ind, Line,
Current_Text.Tab_Width (Cursor.Get_File)));
end;
end Add_Literal_Pragma;

Expand Down Expand Up @@ -971,7 +984,9 @@ package body Codefix.Text_Manager.Ada_Commands is
(Position, Get_Construct (Declaration).Sloc_Entity.Line,
To_Column_Index
(String_Index_Type
(Get_Construct (Declaration).Sloc_Entity.Column), Line));
(Get_Construct (Declaration).Sloc_Entity.Column),
Line,
Current_Text.Tab_Width (Cursor.Get_File)));
end;

Garbage := Position;
Expand Down Expand Up @@ -1292,7 +1307,8 @@ package body Codefix.Text_Manager.Ada_Commands is
Begin_Cursor.Line := Sloc_Start.Line;
Begin_Cursor.Col := To_Column_Index
(String_Index_Type (Sloc_Start.Column),
Get_Line (Current_Text, Begin_Cursor, 1));
Get_Line (Current_Text, Begin_Cursor, 1),
Current_Text.Tab_Width (Begin_Cursor.Get_File));
end if;
end Begin_Of_Profile;

Expand All @@ -1306,7 +1322,8 @@ package body Codefix.Text_Manager.Ada_Commands is
End_Cursor.Line := Last_Entity_Line;
End_Cursor.Col := To_Column_Index
(String_Index_Type (Last_Entity_Column),
Get_Line (Current_Text, End_Cursor, 1));
Get_Line (Current_Text, End_Cursor, 1),
Current_Text.Tab_Width (End_Cursor.Get_File));

if Begin_Cursor = Null_File_Cursor then
End_Cursor.Col := End_Cursor.Col + 1;
Expand Down Expand Up @@ -1389,7 +1406,8 @@ package body Codefix.Text_Manager.Ada_Commands is
To_Column_Index
(String_Index_Type
(Get_Construct (Position_It).Sloc_Start.Column),
Get_Line (Current_Text, Begin_Analyze_Cursor, 1)));
Get_Line (Current_Text, Begin_Analyze_Cursor, 1),
Current_Text.Tab_Width (Begin_Analyze_Cursor.Get_File)));

Last_Entity_Column := Integer (Begin_Analyze_Cursor.Col);
Last_Entity_Line := Begin_Analyze_Cursor.Line;
Expand Down Expand Up @@ -1720,7 +1738,10 @@ package body Codefix.Text_Manager.Ada_Commands is
(Get_File (Line_Cursor)).Indent_Line (Line_Cursor);
else
Char_Ind := To_Char_Index
(This.Force_Column, Get_Line (Current_Text, Line_Cursor, 1));
(This.Force_Column,
Get_Line (Current_Text, Line_Cursor, 1),
Current_Text.Tab_Width (Line_Cursor.Get_File));

Indent_Size := Natural (Char_Ind) - 1;

declare
Expand Down Expand Up @@ -1929,7 +1950,9 @@ package body Codefix.Text_Manager.Ada_Commands is
(This => Cursor,
Line => Sloc_End.Line,
Column => To_Column_Index
(String_Index_Type (Sloc_End.Column), Line));
(String_Index_Type (Sloc_End.Column),
Line,
Current_Text.Tab_Width (Cursor.Get_File)));
end if;

return Stop_Scanning;
Expand Down Expand Up @@ -2207,7 +2230,9 @@ package body Codefix.Text_Manager.Ada_Commands is

End_Line := Sloc_End.Line;
End_Column := To_Column_Index
(String_Index_Type (Sloc_End.Column), Line);
(String_Index_Type (Sloc_End.Column),
Line,
Current_Text.Tab_Width (Cursor.Get_File));

return False;
end Scan_Forward_Callback;
Expand Down Expand Up @@ -2288,8 +2313,8 @@ package body Codefix.Text_Manager.Ada_Commands is
Current_Text.Get_Current_Cursor (This.Cursor.all);
Line : constant String := Get_Line (Current_Text, Cursor, 1);
New_Id : String (1 .. Line'Length);
Index : String_Index_Type :=
To_Char_Index (Get_Column (Cursor), Line);
Index : String_Index_Type := To_Char_Index
(Get_Column (Cursor), Line, Current_Text.Tab_Width (Cursor.Get_File));
New_Id_Index : Integer := 1;
Start_Index : String_Index_Type;
begin
Expand Down Expand Up @@ -2325,7 +2350,8 @@ package body Codefix.Text_Manager.Ada_Commands is
end if;
end loop;

Cursor.Col := To_Column_Index (Start_Index, Line);
Cursor.Col := To_Column_Index
(Start_Index, Line, Current_Text.Tab_Width (Cursor.Get_File));

Current_Text.Replace
(Cursor,
Expand Down Expand Up @@ -2384,7 +2410,8 @@ package body Codefix.Text_Manager.Ada_Commands is
Pragma_Cursor.Set_Column
(To_Column_Index
(String_Index_Type (Get_Construct (It).Sloc_Start.Column),
Current_Text.Get_Line (Pragma_Cursor, 0)));
Current_Text.Get_Line (Pragma_Cursor, 0),
Current_Text.Tab_Width (Pragma_Cursor.Get_File)));

declare
List : Ada_Statement;
Expand Down Expand Up @@ -2581,7 +2608,8 @@ package body Codefix.Text_Manager.Ada_Commands is
End_Line : constant String :=
Current_Text.Get_Line (Src_End_Cursor, 0);
begin
Src_End_Cursor.Col := To_Column_Index (End_Line'Length, End_Line);
Src_End_Cursor.Col := To_Column_Index
(End_Line'Length, End_Line, Current_Text.Tab_Width (Cursor.File));
end;

if Prev_Entity = Null_Construct_Tree_Iterator then
Expand All @@ -2596,7 +2624,10 @@ package body Codefix.Text_Manager.Ada_Commands is
End_Line : constant String :=
Current_Text.Get_Line (Dst_Cursor, 0);
begin
Dst_Cursor.Col := To_Column_Index (End_Line'Length, End_Line) + 1;
Dst_Cursor.Col := To_Column_Index
(End_Line'Length,
End_Line,
Current_Text.Tab_Width (Dst_Cursor.Get_File)) + 1;
end;
else
-- If there is a subprogram before, place it after the end of that
Expand All @@ -2608,7 +2639,10 @@ package body Codefix.Text_Manager.Ada_Commands is
End_Line : constant String :=
Current_Text.Get_Line (Dst_Cursor, 0);
begin
Dst_Cursor.Col := To_Column_Index (End_Line'Length, End_Line) + 1;
Dst_Cursor.Col := To_Column_Index
(End_Line'Length,
End_Line,
Current_Text.Tab_Width (Dst_Cursor.Get_File)) + 1;
end;
end if;

Expand Down Expand Up @@ -2863,7 +2897,9 @@ package body Codefix.Text_Manager.Ada_Commands is
Name_Cursor.Set_Location
(Sloc_Start.Line,
To_Column_Index
(String_Index_Type (Sloc_Start.Column), Line));
(String_Index_Type (Sloc_Start.Column),
Line,
Current_Text.Tab_Width (Name_Cursor.Get_File)));

Name_Length := Sloc_End.Column - Sloc_Start.Column + 1;

Expand Down
22 changes: 13 additions & 9 deletions codefix/core/src/codefix-text_manager-commands.adb
Expand Up @@ -97,9 +97,9 @@ package body Codefix.Text_Manager.Commands is
Match : constant String := Word.Get_Matching_Word
(Current_Text);
Str_Parsed : constant String :=
Do_Tab_Expansion
(Current_Text.Get_Line (Word, Start_Col => 1),
Current_Text.Tab_Width (Get_File (Word)));
Do_Tab_Expansion
(Current_Text.Get_Line (Word, Start_Col => 1),
Current_Text.Tab_Width (Get_File (Word)));
Column : Natural := Natural (Get_Column (Word));

begin
Expand Down Expand Up @@ -161,13 +161,14 @@ package body Codefix.Text_Manager.Commands is
exit;
end if;

-- Check if we must remove another occurrence found immediately
-- after the removed text
-- Check if we must remove another occurrence found
-- immediately after the removed text

exit when not This.All_Occurrences;

declare
Str_Parsed : constant String := Current_Text.Get_Line (Word);
Str_Parsed : constant String :=
Current_Text.Get_Line (Word);

begin
exit when Str_Parsed'Length < Match'Length
Expand Down Expand Up @@ -269,12 +270,15 @@ package body Codefix.Text_Manager.Commands is

New_Pos.Col := To_Column_Index
(String_Index_Type (Matches (1).Last) + 1,
Get_Line (Current_Text, New_Pos, 1));
Get_Line (Current_Text, New_Pos, 1),
Current_Text.Tab_Width (New_Pos.File));
end;
end if;

Word_Char_Index :=
To_Char_Index (New_Pos.Col, Get_Line (Current_Text, Line_Cursor));
Word_Char_Index := To_Char_Index
(New_Pos.Col,
Get_Line (Current_Text, Line_Cursor),
Current_Text.Tab_Width (New_Pos.File));

if This.Position = Specified then
if This.Add_Spaces then
Expand Down

0 comments on commit 0fc4233

Please sign in to comment.