Skip to content

Commit 01071eb

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents c2781f5 + 145eeaa commit 01071eb

11 files changed

+3609
-202
lines changed

Diff for: source/gpr/lsp-gpr_completions.adb

+380-108
Large diffs are not rendered by default.

Diff for: source/gpr/lsp-gpr_files-references.adb

+161-94
Large diffs are not rendered by default.

Diff for: source/gpr/lsp-gpr_files-references.ads

+128
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,139 @@
1717
--
1818
-- This package provides GPR references API.
1919

20+
with Gpr_Parser.Common;
21+
2022
package LSP.GPR_Files.References is
2123

24+
type Reference is private;
25+
26+
type Ref_Kind is
27+
(No_Ref, Project_Ref, Type_Ref, Variable_Ref, Attribute_Ref, Package_Ref);
28+
29+
function Kind (Ref : Reference) return Ref_Kind;
30+
2231
function Token_Reference
2332
(File : LSP.GPR_Files.File_Access;
2433
Position : LSP.Structures.Position)
2534
return Gpr_Parser.Common.Token_Reference;
2635

36+
function Identifier_Reference
37+
(File : LSP.GPR_Files.File_Access;
38+
Current_Package : GPR2.Package_Id;
39+
Token : Gpr_Parser.Common.Token_Reference)
40+
return Reference;
41+
-- return the Project, Type, Variable, Attribute, Package reference
42+
-- found at 'Location'. 'Current_Package' useful for package's variable.
43+
44+
function Referenced_File
45+
(File : LSP.GPR_Files.File_Access;
46+
Reference : LSP.GPR_Files.References.Reference)
47+
return LSP.GPR_Files.File_Access;
48+
49+
function Referenced_Package
50+
(Reference : LSP.GPR_Files.References.Reference)
51+
return GPR2.Package_Id;
52+
53+
function Has_Project
54+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
55+
56+
function Is_Project_Reference
57+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
58+
59+
function Has_Package
60+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
61+
62+
function Is_Package_Reference
63+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
64+
65+
function Is_Type_Reference
66+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
67+
68+
function Is_Variable_Reference
69+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
70+
71+
function Is_Attribute_Reference
72+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
73+
74+
function In_Type_Reference
75+
(Reference : LSP.GPR_Files.References.Reference) return Boolean;
76+
77+
No_Reference : constant Reference;
78+
-- No reference found
79+
80+
function Get_Referenced_File
81+
(File : LSP.GPR_Files.File_Access;
82+
Reference : LSP.GPR_Files.References.Reference)
83+
return LSP.GPR_Files.File_Access;
84+
85+
private
86+
87+
package GPC renames Gpr_Parser.Common;
88+
89+
type Reference (Kind : Ref_Kind := No_Ref) is record
90+
Token : Gpr_Parser.Common.Token_Reference := GPC.No_Token;
91+
case Kind is
92+
when No_Ref =>
93+
null;
94+
when others =>
95+
Project : Project_Id := No_Project;
96+
In_Type_Reference : Boolean := False;
97+
case Kind is
98+
when Project_Ref =>
99+
null;
100+
when Type_Ref =>
101+
Typ : Type_Id := No_Type;
102+
when others =>
103+
Pack : GPR2.Package_Id := GPR2.Project_Level_Scope;
104+
case Kind is
105+
when Variable_Ref =>
106+
Variable : Variable_Id := No_Variable;
107+
when Attribute_Ref =>
108+
Attribute : GPR2.Optional_Attribute_Id :=
109+
GPR2.No_Attribute;
110+
Index : Index_Type := No_Index;
111+
when others =>
112+
null;
113+
end case;
114+
end case;
115+
end case;
116+
end record;
117+
118+
No_Reference : constant Reference := (Kind => No_Ref, Token => GPC.No_Token);
119+
-- No reference found
120+
121+
function Has_Project
122+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
123+
(Reference.Kind /= No_Ref);
124+
125+
function Is_Project_Reference
126+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
127+
(Reference.Kind = Project_Ref);
128+
129+
function Has_Package
130+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
131+
(Reference.Kind not in No_Ref | Project_Ref | Type_Ref);
132+
133+
function Is_Package_Reference
134+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
135+
(Reference.Kind = Package_Ref);
136+
137+
function Is_Type_Reference
138+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
139+
(Reference.Kind = Type_Ref);
140+
141+
function Is_Variable_Reference
142+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
143+
(Reference.Kind = Variable_Ref);
144+
145+
function Is_Attribute_Reference
146+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
147+
(Reference.Kind = Attribute_Ref);
148+
149+
function In_Type_Reference
150+
(Reference : LSP.GPR_Files.References.Reference) return Boolean is
151+
(if Reference.Kind in Project_Ref | Type_Ref | Package_Ref
152+
then Reference.In_Type_Reference
153+
else False);
154+
27155
end LSP.GPR_Files.References;

Diff for: source/gpr/lsp-gpr_files.adb

+99
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,10 @@ package body LSP.GPR_Files is
12901290
begin
12911291
File.Token_To_File_Map.Insert (Extended_Index, Extended_Path);
12921292
Extended := Parse (File.File_Provider, Extended_Path);
1293+
if not File.Name_To_File_Map.Contains (Extended.Name)
1294+
then
1295+
File.Name_To_File_Map.Insert (Extended.Name, Extended_Path);
1296+
end if;
12931297
File.Extended := Extended.Name;
12941298
File.Extended_All := Extends_All;
12951299
File.Extended_Path := Extended_Path;
@@ -1495,4 +1499,99 @@ package body LSP.GPR_Files is
14951499
return Path_Name.Undefined;
14961500
end Get_Referenced_GPR;
14971501

1502+
-----------
1503+
-- Types --
1504+
-----------
1505+
1506+
function Types
1507+
(Self : LSP.GPR_Files.File)
1508+
return VSS.String_Vectors.Virtual_String_Vector
1509+
is
1510+
Types : VSS.String_Vectors.Virtual_String_Vector;
1511+
1512+
procedure Handle_Element (Position : Type_Maps.Cursor);
1513+
1514+
--------------------
1515+
-- Handle_Element --
1516+
--------------------
1517+
1518+
procedure Handle_Element (Position : Type_Maps.Cursor) is
1519+
begin
1520+
Types.Append (Image (Type_Maps.Key (Position)));
1521+
end Handle_Element;
1522+
1523+
begin
1524+
Self.Types.Iterate (Handle_Element'Access);
1525+
return Types;
1526+
end Types;
1527+
1528+
---------------
1529+
-- Variables --
1530+
---------------
1531+
1532+
function Variables
1533+
(Self : LSP.GPR_Files.File;
1534+
Pack : GPR2.Package_Id)
1535+
return VSS.String_Vectors.Virtual_String_Vector is
1536+
Vars : VSS.String_Vectors.Virtual_String_Vector;
1537+
1538+
procedure Handle_Element (Position : Variable_Maps.Cursor);
1539+
1540+
--------------------
1541+
-- Handle_Element --
1542+
--------------------
1543+
1544+
procedure Handle_Element (Position : Variable_Maps.Cursor) is
1545+
begin
1546+
Vars.Append (Image (Variable_Maps.Key (Position)));
1547+
end Handle_Element;
1548+
1549+
begin
1550+
1551+
if Pack = GPR2.Project_Level_Scope then
1552+
Self.Project_Level_Scope_Defs.Variables.Iterate
1553+
(Handle_Element'Access);
1554+
else
1555+
declare
1556+
Cursor : constant LSP.GPR_Files.Package_Maps.Cursor :=
1557+
Self.Packages.Find (Pack);
1558+
begin
1559+
if LSP.GPR_Files.Package_Maps.Has_Element (Cursor) then
1560+
LSP.GPR_Files.Package_Maps.Element (Cursor).Variables.Iterate
1561+
(Handle_Element'Access);
1562+
end if;
1563+
end;
1564+
end if;
1565+
return Vars;
1566+
end Variables;
1567+
1568+
-------------
1569+
-- Projects--
1570+
-------------
1571+
1572+
function Projects
1573+
(Self : LSP.GPR_Files.File)
1574+
return VSS.String_Vectors.Virtual_String_Vector
1575+
is
1576+
Projects : VSS.String_Vectors.Virtual_String_Vector;
1577+
1578+
procedure Handle_Element (Position : Project_Id_List.Cursor);
1579+
1580+
--------------------
1581+
-- Handle_Element --
1582+
--------------------
1583+
1584+
procedure Handle_Element (Position : Project_Id_List.Cursor) is
1585+
begin
1586+
Projects.Append (Image (Project_Id_List.Element (Position)));
1587+
end Handle_Element;
1588+
1589+
begin
1590+
Self.Imported.Iterate (Handle_Element'Access);
1591+
if Self.Extended /= No_Project then
1592+
Projects.Append (Image (Self.Extended));
1593+
end if;
1594+
return Projects;
1595+
end Projects;
1596+
14981597
end LSP.GPR_Files;

Diff for: source/gpr/lsp-gpr_files.ads

+25
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ package LSP.GPR_Files is
225225
Token : Gpr_Parser.Common.Token_Reference) return Path_Name.Object;
226226
-- find file pointed by gpr token useful for imported & extended files
227227

228+
function Name
229+
(Self : LSP.GPR_Files.File)
230+
return VSS.Strings.Virtual_String;
231+
-- Self file' name
232+
233+
function Types
234+
(Self : LSP.GPR_Files.File)
235+
return VSS.String_Vectors.Virtual_String_Vector;
236+
-- Self file's types.
237+
238+
function Variables
239+
(Self : LSP.GPR_Files.File;
240+
Pack : GPR2.Package_Id)
241+
return VSS.String_Vectors.Virtual_String_Vector;
242+
-- Self file's package types.
243+
244+
function Projects
245+
(Self : LSP.GPR_Files.File)
246+
return VSS.String_Vectors.Virtual_String_Vector;
247+
-- Self file's non limited imported projects & extended projects.
248+
228249
private
229250

230251
type Source_Position is record
@@ -675,4 +696,8 @@ private
675696
return Gpr_Parser.Common.Token_Reference is
676697
(Self.Unit.Lookup_Token (Location));
677698

699+
function Name
700+
(Self : LSP.GPR_Files.File)
701+
return VSS.Strings.Virtual_String is (Image (Self.Name));
702+
678703
end LSP.GPR_Files;

Diff for: testsuite/gpr_lsp/completion_references/extended.gpr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project Extended is
2+
type Extended_Type is ("a");
3+
Extended_Variable := "";
4+
for Warning_Message use "warning message";
5+
package Emulator is
6+
Extended_Emulator_Variable := "";
7+
for Board use "";
8+
end Emulator;
9+
end Extended;

Diff for: testsuite/gpr_lsp/completion_references/imported.gpr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project Imported is
2+
type Imported_Type is ("a");
3+
Imported_Variable := "";
4+
for Warning_Message use "warning message";
5+
package Compiler is
6+
Imported_Compiler_Variable := "";
7+
for Local_Configuration_Pragmas use "";
8+
end Compiler;
9+
end Imported;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project Imported_Limited is
2+
type Imported_Limited_Type is ("a");
3+
Imported_Limited_Variable := "";
4+
for Warning_Message use "warning message";
5+
package Compiler is
6+
Imported_Limited_Compiler_Variable := "";
7+
for Local_Configuration_Pragmas use "";
8+
end Compiler;
9+
end Imported_Limited;

Diff for: testsuite/gpr_lsp/completion_references/prj.gpr

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
with "imported";
2+
limited with "imported_limited";
3+
project Prj extends "extended" is
4+
5+
type T1 is ("a");
6+
7+
package Compiler is
8+
V1 := "";
9+
for Local_Configuration_Pragmas use "";
10+
end Compiler;
11+
12+
V2 :=
13+
Imported.
14+
Compiler.
15+
Imported_Compiler_Variable;
16+
17+
V3 := project'
18+
Name;
19+
20+
V4 := Extended.Emulator'
21+
Board;
22+
23+
for Object_Dir use
24+
Prj.Compiler'
25+
Local_Configuration_Pragmas;
26+
27+
for Source_Dirs use (
28+
".");
29+
30+
for Source_Dirs use ("." &
31+
".");
32+
33+
for Source_Dirs use (".",
34+
"..");
35+
36+
V5 :
37+
Imported.
38+
Imported_Type := "a";
39+
40+
V5 :
41+
Extended.
42+
Extended_Type := "a";
43+
44+
V5 :
45+
E ;
46+
47+
V5 :=
48+
I;
49+
50+
for Object_Dir use
51+
P ;
52+
53+
V5 := (
54+
E );
55+
56+
V5 := V5 &
57+
I ;
58+
59+
V5 := ("",
60+
P );
61+
62+
V5 := project'
63+
N ;
64+
65+
V5 := Extended.
66+
E ;
67+
68+
end Prj;

0 commit comments

Comments
 (0)