Skip to content

Commit dcfd1a3

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 985352d + c2f879b commit dcfd1a3

File tree

16 files changed

+420
-37
lines changed

16 files changed

+420
-37
lines changed

source/ada/lsp-ada_handlers-other_file_commands.adb

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,37 @@ package body LSP.Ada_Handlers.Other_File_Commands is
111111

112112
function Other_File_From_Unit
113113
(Unit : GPR2.Build.Compilation_Unit.Object)
114-
return GNATCOLL.VFS.Virtual_File;
114+
return GNATCOLL.VFS.Virtual_File;
115115
-- Return the other file, knowing that the original file was
116116
-- related to Unit.
117117
-- Return No_File if no other file has been found
118118
-- (e.g: when querying the other file of a package that has only a
119119
-- a specification file).
120120

121-
function Unit_For_File return GPR2.Build.Compilation_Unit.Object;
122-
-- Return the Unit object corresponding to File
121+
function Unit_For_File
122+
(Is_Multi_Unit : out Boolean)
123+
return GPR2.Build.Compilation_Unit.Object;
124+
-- Return the Unit object corresponding to File.
125+
-- Set Is_Multi_Unit to True if File is a multi-unit file.
123126

124127
--------------------------
125128
-- Other_File_From_Unit --
126129
--------------------------
127130

128131
function Other_File_From_Unit
129132
(Unit : GPR2.Build.Compilation_Unit.Object)
130-
return GNATCOLL.VFS.Virtual_File
133+
return GNATCOLL.VFS.Virtual_File
131134
is
132135
Spec_File : Virtual_File;
133136
Body_File : Virtual_File;
134137
begin
135-
Spec_File := (if Unit.Has_Part (S_Spec) then
136-
Unit.Spec.Source.Virtual_File else No_File);
137-
Body_File := (if Unit.Has_Part (S_Body) then
138-
Unit.Main_Body.Source.Virtual_File else No_File);
138+
Spec_File :=
139+
(if Unit.Has_Part (S_Spec) then Unit.Spec.Source.Virtual_File
140+
else No_File);
141+
Body_File :=
142+
(if Unit.Has_Part (S_Body)
143+
then Unit.Main_Body.Source.Virtual_File
144+
else No_File);
139145

140146
if File = Spec_File then
141147
return Body_File;
@@ -149,7 +155,8 @@ package body LSP.Ada_Handlers.Other_File_Commands is
149155
-------------------
150156

151157
function Unit_For_File
152-
return GPR2.Build.Compilation_Unit.Object is
158+
(Is_Multi_Unit : out Boolean)
159+
return GPR2.Build.Compilation_Unit.Object is
153160
begin
154161
-- Check in the root project's closure for a visible source
155162
-- corresponding to this file.
@@ -163,17 +170,27 @@ package body LSP.Ada_Handlers.Other_File_Commands is
163170
Unit : GPR2.Build.Compilation_Unit.Object :=
164171
GPR2.Build.Compilation_Unit.Undefined;
165172
begin
173+
Is_Multi_Unit := False;
174+
166175
-- The source is not visible from the root project (e.g:
167176
-- when querying the other file of an Ada file that
168177
-- does not belong to the loaded project).
169-
if not Visible_Source.Is_Defined then
178+
if not Visible_Source.Is_Defined
179+
or else not Visible_Source.Has_Units
180+
then
170181
return GPR2.Build.Compilation_Unit.Undefined;
171182
end if;
172183

173184
declare
185+
Index : constant GPR2.Unit_Index :=
186+
(if Visible_Source.Has_Unit_At (GPR2.No_Index)
187+
then GPR2.No_Index
188+
else GPR2.Multi_Unit_Index'First);
174189
Unit_Info : constant GPR2.Build.Unit_Info.Object :=
175-
Visible_Source.Unit;
190+
Visible_Source.Unit (Index => Index);
176191
begin
192+
Is_Multi_Unit := Index /= GPR2.No_Index;
193+
177194
if Unit_Info.Is_Defined then
178195
Unit :=
179196
View.Namespace_Roots.First_Element.Unit
@@ -188,8 +205,10 @@ package body LSP.Ada_Handlers.Other_File_Commands is
188205
end if;
189206
end Unit_For_File;
190207

191-
Unit : constant GPR2.Build.Compilation_Unit.Object := Unit_For_File;
192-
Other_File : Virtual_File;
208+
Is_Multi_Unit : Boolean;
209+
Unit : constant GPR2.Build.Compilation_Unit.Object :=
210+
Unit_For_File (Is_Multi_Unit => Is_Multi_Unit);
211+
Other_File : Virtual_File;
193212
begin
194213
Success := True;
195214

@@ -229,23 +248,26 @@ package body LSP.Ada_Handlers.Other_File_Commands is
229248
Use_Extended => True)
230249
else ".adb");
231250
begin
232-
if GNATCOLL.Utils.Ends_With
233-
(File.Display_Full_Name, Impl_Ext)
251+
if GNATCOLL.Utils.Ends_With (File.Display_Full_Name, Impl_Ext)
234252
then
235-
return GNATCOLL.VFS.Create
236-
(Full_Filename => +GNATCOLL.Utils.Replace
237-
(S => File.Display_Full_Name,
238-
Pattern => Impl_Ext,
239-
Replacement => Spec_Ext));
253+
return
254+
GNATCOLL.VFS.Create
255+
(Full_Filename =>
256+
+GNATCOLL.Utils.Replace
257+
(S => File.Display_Full_Name,
258+
Pattern => Impl_Ext,
259+
Replacement => Spec_Ext));
240260
else
241-
return GNATCOLL.VFS.Create
242-
(Full_Filename => +GNATCOLL.Utils.Replace
243-
(S => File.Display_Full_Name,
244-
Pattern => Spec_Ext,
245-
Replacement => Impl_Ext));
261+
return
262+
GNATCOLL.VFS.Create
263+
(Full_Filename =>
264+
+GNATCOLL.Utils.Replace
265+
(S => File.Display_Full_Name,
266+
Pattern => Spec_Ext,
267+
Replacement => Impl_Ext));
246268
end if;
247269
end;
248-
else
270+
elsif not Is_Multi_Unit then
249271
Other_File := Other_File_From_Unit (Unit => Unit);
250272

251273
if Other_File = No_File then
@@ -258,6 +280,16 @@ package body LSP.Ada_Handlers.Other_File_Commands is
258280
end if;
259281

260282
return Other_File;
283+
else
284+
Success := False;
285+
Error_Msg :=
286+
VSS.Strings.Conversions.To_Virtual_String
287+
("Could not find other file for '"
288+
& File.Display_Base_Name
289+
& "': this is a multi-unit file, containing both "
290+
& "the package's specification and its body.");
291+
292+
return GNATCOLL.VFS.No_File;
261293
end if;
262294
end Get_Other_File;
263295

source/ada/lsp-ada_handlers.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ private
428428
overriding function Project_Tree_Is_Aggregate (Self : Message_Handler)
429429
return Boolean is
430430
(Self.Project_Tree_Is_Defined
431+
and then Self.Project_Tree.Root_Project.Is_Defined
431432
and then Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind);
432433

433434
overriding procedure Reload_Project (Self : in out Message_Handler);

source/tester/tester-tests.adb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ package body Tester.Tests is
9898
function Find_Matching_Request
9999
(Request : GNATCOLL.JSON.JSON_Value;
100100
Search_Array : GNATCOLL.JSON.JSON_Array;
101-
Request_ID : out Integer)
101+
Request_ID : out Unbounded_String)
102102
return GNATCOLL.JSON.JSON_Value;
103103
-- Search for the matching Request in Search_Array. Return JSON_Null if
104104
-- Request was not matched.
@@ -930,9 +930,9 @@ package body Tester.Tests is
930930
for J in 1 .. GNATCOLL.JSON.Length (R) loop
931931
-- For each request, try to find the request with the same ID
932932
declare
933-
Expected : constant GNATCOLL.JSON.JSON_Value :=
933+
Expected : constant GNATCOLL.JSON.JSON_Value :=
934934
GNATCOLL.JSON.Get (R, J);
935-
Expected_ID : Integer;
935+
Expected_ID : Unbounded_String;
936936
Matching_Request : constant GNATCOLL.JSON.JSON_Value :=
937937
Find_Matching_Request
938938
(Request => Expected,
@@ -947,11 +947,11 @@ package body Tester.Tests is
947947
Minimal => Minimal,
948948
Result => Result);
949949
else
950-
if Expected_ID /= -1 then
950+
if Expected_ID = Null_Unbounded_String then
951951
-- Alert the user we failed to find the request
952952
Result.Append
953953
("Failed to find result for request:"
954-
& Expected_ID'Image);
954+
& Expected_ID);
955955
Result.Append (Ada.Characters.Latin_1.LF);
956956
Result.Append
957957
("Either the result was never received or the id "
@@ -982,26 +982,44 @@ package body Tester.Tests is
982982
function Find_Matching_Request
983983
(Request : GNATCOLL.JSON.JSON_Value;
984984
Search_Array : GNATCOLL.JSON.JSON_Array;
985-
Request_ID : out Integer)
985+
Request_ID : out Unbounded_String)
986986
return GNATCOLL.JSON.JSON_Value
987987
is
988-
function Get_ID (Value : GNATCOLL.JSON.JSON_Value) return Integer;
988+
function Get_ID
989+
(Value : GNATCOLL.JSON.JSON_Value) return Unbounded_String;
989990

990991
------------
991992
-- Get_ID --
992993
------------
993994

994-
function Get_ID (Value : GNATCOLL.JSON.JSON_Value) return Integer is
995+
function Get_ID
996+
(Value : GNATCOLL.JSON.JSON_Value) return Unbounded_String is
995997
begin
996998
if Value.Kind = JSON_Object_Type and then Value.Has_Field ("id") then
997-
return Value.Get ("id");
999+
declare
1000+
ID : constant GNATCOLL.JSON.JSON_Value := Value.Get ("id");
1001+
begin
1002+
if ID.Kind = JSON_Int_Type then
1003+
declare
1004+
ID_Value : constant Integer := Value.Get ("id");
1005+
begin
1006+
return To_Unbounded_String (ID_Value'Image);
1007+
end;
1008+
elsif ID.Kind = JSON_String_Type then
1009+
declare
1010+
ID_Value : constant String := Value.Get ("id");
1011+
begin
1012+
return To_Unbounded_String (ID_Value);
1013+
end;
1014+
end if;
1015+
end;
9981016
end if;
999-
return -1;
1017+
return Null_Unbounded_String;
10001018
end Get_ID;
10011019

10021020
begin
10031021
Request_ID := Get_ID (Request);
1004-
if Request_ID = -1 then
1022+
if Request_ID = Null_Unbounded_String then
10051023
-- No ID, so left was not a request object
10061024
return GNATCOLL.JSON.JSON_Null;
10071025
end if;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
project Multi is
2+
for Object_Dir use "obj";
3+
for Source_Dirs use ("src");
4+
for Exec_Dir use ".";
5+
for Main use ("main.adb");
6+
7+
package Naming is
8+
for Specification ("U") use "u.adb" at 1;
9+
for Body ("U") use "u.adb" at 2;
10+
for Body ("U.V") use "sep.adb" at 1;
11+
for Body ("U.W") use "sep.adb" at 2;
12+
end Naming;
13+
end Multi;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
with U;
2+
with Ada;
3+
with Pkg;
4+
5+
procedure Main is
6+
begin
7+
U.V;
8+
Pkg.Foo;
9+
end Main;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package body Pkg is
2+
procedure Foo is null;
3+
end Pkg;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package Pkg is
2+
procedure Foo;
3+
end Pkg;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
with Ada.Text_IO;
2+
separate (U) procedure V is
3+
begin
4+
Ada.Text_IO.Put_Line ("U.V.");
5+
end V;
6+
7+
with GNAT.Regexp;
8+
separate (U) procedure W is
9+
begin
10+
null;
11+
end W;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package U is
2+
procedure V;
3+
end U;
4+
5+
with GNAT.OS_Lib; use GNAT.OS_Lib;
6+
package body U is
7+
procedure V is separate;
8+
procedure W is separate;
9+
begin
10+
W;
11+
end U;

0 commit comments

Comments
 (0)