Skip to content

Commit 41cb092

Browse files
committed
VB10-040 Adjust to latest gnatpp partial formatting API
Support partial formatting of Ada_List slices. Update tests baseline.
1 parent 5687655 commit 41cb092

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
@@ -615,7 +615,7 @@ package body LSP.Ada_Documents is
615615
(Self : Document;
616616
Span : LSP.Messages.Span;
617617
New_Text : VSS.Strings.Virtual_String;
618-
Edit : out LSP.Messages.TextEdit_Vector)
618+
Edit : in out LSP.Messages.TextEdit_Vector)
619619
is
620620
use LSP.Types;
621621
use LSP.Messages;
@@ -1121,68 +1121,50 @@ package body LSP.Ada_Documents is
11211121
end loop;
11221122
end Append_PP_Messages;
11231123

1124-
Output : Char_Vector;
1125-
1126-
PP_Messages : Pp.Scanner.Source_Message_Vector;
1127-
1128-
Input_Selection_Range : constant Source_Location_Range :=
1129-
(if Span = LSP.Messages.Empty_Span then
1130-
No_Source_Location_Range
1131-
else
1132-
Make_Range
1133-
(Self.Get_Source_Location (Span.first),
1134-
Self.Get_Source_Location (Span.last)));
1135-
1136-
Output_Selection_Range : Source_Location_Range;
1137-
1138-
Unit : constant Analysis_Unit :=
1139-
Self.Unit (Context);
1140-
Enclosing_Node : Ada_Node;
1141-
11421124
begin
11431125
Context.Trace.Trace ("On Range_Formatting");
1126+
11441127
Context.Trace.Trace ("Format_Selection");
1145-
begin
1146-
Format_Selection
1147-
(Main_Unit => Unit,
1148-
Input_Selection_Range => Input_Selection_Range,
1149-
Output => Output,
1150-
Output_Selection_Range => Output_Selection_Range,
1151-
PP_Messages => PP_Messages,
1152-
Formatted_Node => Enclosing_Node,
1153-
PP_Options => PP_Options,
1154-
Force_Source_Line_Breaks => False);
1128+
declare
1129+
Unit : constant Analysis_Unit :=
1130+
Self.Unit (Context);
1131+
Input_Selection_Range : constant Source_Location_Range :=
1132+
(if Span = LSP.Messages.Empty_Span then No_Source_Location_Range
1133+
else Make_Range
1134+
(Self.Get_Source_Location (Span.first),
1135+
Self.Get_Source_Location (Span.last)));
1136+
Partial_Formatting_Edit :
1137+
constant Laltools.Partial_GNATPP.Partial_Formatting_Edit :=
1138+
Format_Selection (Unit, Input_Selection_Range, PP_Options);
11551139

1156-
exception
1157-
when others =>
1158-
Append_PP_Messages (PP_Messages);
1140+
begin
1141+
if not Partial_Formatting_Edit.Diagnostics.Is_Empty then
1142+
Append_PP_Messages (Partial_Formatting_Edit.Diagnostics);
1143+
Context.Trace.Trace
1144+
("Non empty diagnostics from GNATPP - "
1145+
& "not continuing with Range_Formatting");
11591146
return False;
1160-
end;
1147+
end if;
11611148

1162-
if not PP_Messages.Is_Empty then
1163-
Context.Trace.Trace
1164-
("Non empty PP_Messages - appending them to Messages");
1165-
Append_PP_Messages (PP_Messages);
1166-
return False;
1167-
end if;
1149+
Context.Trace.Trace ("Computing Range_Formatting Text_Edits");
1150+
Edit.Clear;
1151+
declare
1152+
Edit_Span : constant LSP.Messages.Span :=
1153+
Self.To_LSP_Range (Partial_Formatting_Edit.Edit.Location);
1154+
Edit_Text : constant VSS.Strings.Virtual_String :=
1155+
VSS.Strings.Conversions.To_Virtual_String
1156+
(Partial_Formatting_Edit.Edit.Text);
11681157

1169-
Context.Trace.Trace ("Computing Range_Formatting Text_Edits");
1170-
declare
1171-
Edit_Span : constant LSP.Messages.Span :=
1172-
Self.To_LSP_Range (Output_Selection_Range);
1173-
Output_Str : constant String :=
1174-
Char_Vectors.Elems (Output) (1 .. Char_Vectors.Last_Index (Output));
1175-
Edit_Text : constant VSS.Strings.Virtual_String :=
1176-
VSS.Strings.Conversions.To_Virtual_String (Output_Str);
1158+
begin
1159+
Edit.Append (TextEdit'(Edit_Span, Edit_Text));
1160+
end;
11771161

1178-
begin
1179-
Self.Diff_Symbols (Edit_Span, Edit_Text, Edit);
1162+
return True;
11801163
end;
11811164

1182-
return True;
1183-
11841165
exception
1185-
when others =>
1166+
when E : others =>
1167+
Log (Self.Trace, E, "in Range_Formatting");
11861168
return False;
11871169
end Range_Formatting;
11881170

source/ada/lsp-ada_documents.ads

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

0 commit comments

Comments
 (0)