Skip to content

Commit a6cb0df

Browse files
VB10-040 Adjust to latest gnatpp partial formatting API
Support partial formatting of Ada_List slices. Update tests baseline.
1 parent 5d43968 commit a6cb0df

File tree

5 files changed

+339
-422
lines changed

5 files changed

+339
-422
lines changed

source/ada/lsp-ada_completions.adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ package body LSP.Ada_Completions is
397397
Filename => "",
398398
Buffer => Full,
399399
Rule => Rule);
400-
Pp.Actions.Set_Partial_Gnatpp_Offset (Offset);
400+
Pp.Actions.Set_Partial_GNATPP_Offset (Offset);
401401
Pp.Actions.Format_Vector
402402
(Cmd => Cmd,
403403
Input => Input,
404404
Node => Root (Tmp_Unit),
405405
Output => Output,
406406
Messages => PP_Messages,
407-
Partial_Gnatpp => True);
408-
Pp.Actions.Set_Partial_Gnatpp_Offset (0);
407+
Partial_GNATPP => True);
408+
Pp.Actions.Set_Partial_GNATPP_Offset (0);
409409
exception
410410
when E : others =>
411411
-- Failed to pretty print the snippet, keep the previous

source/ada/lsp-ada_documents.adb

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ package body LSP.Ada_Documents is
609609
(Self : Document;
610610
Span : LSP.Messages.Span;
611611
New_Text : VSS.Strings.Virtual_String;
612-
Edit : out LSP.Messages.TextEdit_Vector)
612+
Edit : in out LSP.Messages.TextEdit_Vector)
613613
is
614614
use LSP.Types;
615615
use LSP.Messages;
@@ -1115,68 +1115,50 @@ package body LSP.Ada_Documents is
11151115
end loop;
11161116
end Append_PP_Messages;
11171117

1118-
Output : Char_Vector;
1119-
1120-
PP_Messages : Pp.Scanner.Source_Message_Vector;
1121-
1122-
Input_Selection_Range : constant Source_Location_Range :=
1123-
(if Span = LSP.Messages.Empty_Span then
1124-
No_Source_Location_Range
1125-
else
1126-
Make_Range
1127-
(Self.Get_Source_Location (Span.first),
1128-
Self.Get_Source_Location (Span.last)));
1129-
1130-
Output_Selection_Range : Source_Location_Range;
1131-
1132-
Unit : constant Analysis_Unit :=
1133-
Self.Unit (Context);
1134-
Enclosing_Node : Ada_Node;
1135-
11361118
begin
11371119
Context.Trace.Trace ("On Range_Formatting");
1120+
11381121
Context.Trace.Trace ("Format_Selection");
1139-
begin
1140-
Format_Selection
1141-
(Main_Unit => Unit,
1142-
Input_Selection_Range => Input_Selection_Range,
1143-
Output => Output,
1144-
Output_Selection_Range => Output_Selection_Range,
1145-
PP_Messages => PP_Messages,
1146-
Formatted_Node => Enclosing_Node,
1147-
PP_Options => PP_Options,
1148-
Force_Source_Line_Breaks => False);
1122+
declare
1123+
Unit : constant Analysis_Unit :=
1124+
Self.Unit (Context);
1125+
Input_Selection_Range : constant Source_Location_Range :=
1126+
(if Span = LSP.Messages.Empty_Span then No_Source_Location_Range
1127+
else Make_Range
1128+
(Self.Get_Source_Location (Span.first),
1129+
Self.Get_Source_Location (Span.last)));
1130+
Partial_Formatting_Edit :
1131+
constant Laltools.Partial_GNATPP.Partial_Formatting_Edit :=
1132+
Format_Selection (Unit, Input_Selection_Range, PP_Options);
11491133

1150-
exception
1151-
when others =>
1152-
Append_PP_Messages (PP_Messages);
1134+
begin
1135+
if not Partial_Formatting_Edit.Diagnostics.Is_Empty then
1136+
Append_PP_Messages (Partial_Formatting_Edit.Diagnostics);
1137+
Context.Trace.Trace
1138+
("Non empty diagnostics from GNATPP - "
1139+
& "not continuing with Range_Formatting");
11531140
return False;
1154-
end;
1141+
end if;
11551142

1156-
if not PP_Messages.Is_Empty then
1157-
Context.Trace.Trace
1158-
("Non empty PP_Messages - appending them to Messages");
1159-
Append_PP_Messages (PP_Messages);
1160-
return False;
1161-
end if;
1143+
Context.Trace.Trace ("Computing Range_Formatting Text_Edits");
1144+
Edit.Clear;
1145+
declare
1146+
Edit_Span : constant LSP.Messages.Span :=
1147+
Self.To_LSP_Range (Partial_Formatting_Edit.Edit.Location);
1148+
Edit_Text : constant VSS.Strings.Virtual_String :=
1149+
VSS.Strings.Conversions.To_Virtual_String
1150+
(Partial_Formatting_Edit.Edit.Text);
11621151

1163-
Context.Trace.Trace ("Computing Range_Formatting Text_Edits");
1164-
declare
1165-
Edit_Span : constant LSP.Messages.Span :=
1166-
Self.To_LSP_Range (Output_Selection_Range);
1167-
Output_Str : constant String :=
1168-
Char_Vectors.Elems (Output) (1 .. Char_Vectors.Last_Index (Output));
1169-
Edit_Text : constant VSS.Strings.Virtual_String :=
1170-
VSS.Strings.Conversions.To_Virtual_String (Output_Str);
1152+
begin
1153+
Edit.Append (TextEdit'(Edit_Span, Edit_Text));
1154+
end;
11711155

1172-
begin
1173-
Self.Diff_Symbols (Edit_Span, Edit_Text, Edit);
1156+
return True;
11741157
end;
11751158

1176-
return True;
1177-
11781159
exception
1179-
when others =>
1160+
when E : others =>
1161+
Log (Self.Trace, E, "in Range_Formatting");
11801162
return False;
11811163
end Range_Formatting;
11821164

source/ada/lsp-ada_documents.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private
393393
(Self : Document;
394394
Span : LSP.Messages.Span;
395395
New_Text : VSS.Strings.Virtual_String;
396-
Edit : out LSP.Messages.TextEdit_Vector);
396+
Edit : in out LSP.Messages.TextEdit_Vector);
397397
-- Create a diff between document Text inside Span and New_Chunk and
398398
-- return Text_Edit. Tests individual symbols instead of lines
399399
-- as above. Do not use it for large text slices because it

0 commit comments

Comments
 (0)