Skip to content

Commit c22e484

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 6238f99 + a51dab0 commit c22e484

13 files changed

+1436
-481
lines changed

source/gpr/lsp-gpr_documentation.adb

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,36 @@
1616
------------------------------------------------------------------------------
1717

1818
with Ada.Characters.Conversions;
19+
with Ada.Characters.Latin_1;
20+
with GPR2.Project.Attribute;
21+
with GPR2.Project.Variable;
1922

2023
with Gpr_Parser.Common;
2124

2225
with GPR2.Project.Registry.Attribute.Description;
2326
with GPR2.Project.Registry.Pack.Description;
2427

28+
with LSP.GPR_Files.References;
2529
with LSP.Text_Documents.Langkit_Documents;
2630

2731
with VSS.Strings.Conversions;
2832

2933
package body LSP.GPR_Documentation is
3034

3135
procedure Get_Tooltip_Text
32-
(Self : LSP.GPR_Files.File;
33-
Position : LSP.Structures.Position;
34-
Tooltip_Text : out VSS.Strings.Virtual_String) is
36+
(Self : LSP.GPR_Files.File_Access;
37+
URI : LSP.Structures.DocumentUri;
38+
Document_Provider : LSP.GPR_Documents.Document_Provider_Access;
39+
Position : LSP.Structures.Position;
40+
Tooltip_Text : out VSS.Strings.Virtual_String) is
3541
use Gpr_Parser.Common;
3642

3743
package LKD renames LSP.Text_Documents.Langkit_Documents;
44+
package FR renames LSP.GPR_Files.References;
45+
46+
procedure Append_Value (Reference : FR.Reference);
47+
-- If gpr parsed without error append to 'Tooltip_Text'
48+
-- current variable/attribute value.
3849

3950
Location : constant Gpr_Parser.Slocs.Source_Location :=
4051
LSP.GPR_Files.To_Langkit_Location
@@ -49,12 +60,67 @@ package body LSP.GPR_Documentation is
4960
use GPR2.Project.Registry.Pack.Description;
5061
use GPR2;
5162
use Ada.Characters.Conversions;
63+
64+
------------------
65+
-- Append_Value --
66+
------------------
67+
68+
procedure Append_Value (Reference : FR.Reference) is
69+
begin
70+
if Reference.Is_Variable_Reference
71+
or else Reference.Is_Attribute_Reference
72+
then
73+
declare
74+
Document : constant LSP.GPR_Documents.Document_Access :=
75+
Document_Provider.Get_Open_Document (URI);
76+
use type LSP.GPR_Documents.Document_Access;
77+
begin
78+
if Document /= null and then not Document.Has_Errors
79+
then
80+
if Reference.Is_Variable_Reference then
81+
declare
82+
Variable : constant GPR2.Project.Variable.Object :=
83+
Document.Get_Variable
84+
(Root_File => Self,
85+
Reference => Reference);
86+
begin
87+
if Variable.Is_Defined then
88+
Tooltip_Text.Append
89+
(VSS.Strings.Conversions.To_Virtual_String
90+
(GPR2.Project.Variable.Image (Variable)));
91+
end if;
92+
end;
93+
elsif Reference.Is_Attribute_Reference then
94+
declare
95+
Attribute : constant GPR2.Project.Attribute.Object :=
96+
Document.Get_Attribute
97+
(Root_File => Self,
98+
Reference => Reference);
99+
begin
100+
if Attribute.Is_Defined then
101+
Tooltip_Text.Append
102+
(VSS.Strings.Conversions.To_Virtual_String
103+
(GPR2.Project.Attribute.Image (Attribute)
104+
& Ada.Characters.Latin_1.CR));
105+
end if;
106+
end;
107+
end if;
108+
end if;
109+
end;
110+
end if;
111+
end Append_Value;
112+
52113
begin
53114

54115
Tooltip_Text.Clear;
55116

56117
if Token /= No_Token and then Token.Data.Kind = Gpr_Identifier then
57118
declare
119+
Reference : constant FR.Reference :=
120+
FR.Identifier_Reference
121+
(File => Self,
122+
Current_Package => Self.Get_Package (Position),
123+
Token => Token);
58124
Previous : constant Token_Reference :=
59125
Token.Previous (Exclude_Trivia => True);
60126
begin
@@ -67,14 +133,35 @@ package body LSP.GPR_Documentation is
67133
(Self.Get_Package (Position))));
68134

69135
when Gpr_For =>
136+
Append_Value (Reference);
70137
Tooltip_Text.Append
71138
(VSS.Strings.Conversions.To_Virtual_String
72139
(Get_Attribute_Description ((
73140
Self.Get_Package (Position),
74141
+(Optional_Name_Type (To_String (Token.Text)))))));
75142

76143
when others =>
77-
null;
144+
Append_Value (Reference);
145+
if Reference.Is_Package_Reference then
146+
Tooltip_Text.Append
147+
(VSS.Strings.Conversions.To_Virtual_String
148+
(Get_Package_Description
149+
(Reference.Referenced_Package)));
150+
else
151+
declare
152+
Attribute : constant FR.Attribute_Definition :=
153+
Reference.Referenced_Attribute;
154+
155+
use type FR.Attribute_Definition;
156+
begin
157+
if Attribute /= FR.No_Attribute_Definition then
158+
Tooltip_Text.Append
159+
(VSS.Strings.Conversions.To_Virtual_String
160+
(Get_Attribute_Description
161+
(Attribute.Name)));
162+
end if;
163+
end;
164+
end if;
78165
end case;
79166
end if;
80167
end;

source/gpr/lsp-gpr_documentation.ads

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
-- Subprogram to obtain documentation for packages & attributes.
1919

20+
with LSP.GPR_Documents;
2021
with LSP.GPR_Files;
2122
with LSP.Structures;
2223

@@ -25,9 +26,11 @@ with VSS.Strings;
2526
package LSP.GPR_Documentation is
2627

2728
procedure Get_Tooltip_Text
28-
(Self : LSP.GPR_Files.File;
29-
Position : LSP.Structures.Position;
30-
Tooltip_Text : out VSS.Strings.Virtual_String);
29+
(Self : LSP.GPR_Files.File_Access;
30+
URI : LSP.Structures.DocumentUri;
31+
Document_Provider : LSP.GPR_Documents.Document_Provider_Access;
32+
Position : LSP.Structures.Position;
33+
Tooltip_Text : out VSS.Strings.Virtual_String);
3134
-- Get all the information needed to produce tooltips (hover and completion
3235
-- requests)
3336

source/gpr/lsp-gpr_documents.adb

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
with Ada.Exceptions;
1919

2020
with GPR2.Message;
21+
with GPR2.Project.View;
2122
with GPR2.Source_Reference;
2223

24+
with VSS.Strings.Conversions;
25+
2326
package body LSP.GPR_Documents is
2427

2528
-------------
@@ -113,6 +116,17 @@ package body LSP.GPR_Documents is
113116
return Self.Has_Messages;
114117
end Has_Diagnostics;
115118

119+
----------------
120+
-- Has_Errors --
121+
----------------
122+
123+
function Has_Errors
124+
(Self : Document)
125+
return Boolean is
126+
begin
127+
return Self.Tree.Log_Messages.Has_Error;
128+
end Has_Errors;
129+
116130
----------------
117131
-- Initialize --
118132
----------------
@@ -206,4 +220,152 @@ package body LSP.GPR_Documents is
206220
Self.Published_Files_With_Diags := Files;
207221
end Update_Files_With_Diags;
208222

223+
------------------
224+
-- Get_Variable --
225+
------------------
226+
227+
function Get_Variable
228+
(Self : Document'Class;
229+
Root_File : LSP.GPR_Files.File_Access;
230+
Reference : LSP.GPR_Files.References.Reference)
231+
return GPR2.Project.Variable.Object is
232+
233+
function Variable
234+
(View : GPR2.Project.View.Object) return GPR2.Project.Variable.Object;
235+
236+
function Variable
237+
(View : GPR2.Project.View.Object) return GPR2.Project.Variable.Object
238+
is
239+
Pack : constant GPR2.Package_Id :=
240+
LSP.GPR_Files.References.Referenced_Package (Reference);
241+
Name : constant GPR2.Name_Type :=
242+
GPR2.Name_Type
243+
(VSS.Strings.Conversions.To_UTF_8_String
244+
(LSP.GPR_Files.Image
245+
(LSP.GPR_Files.References.Referenced_Variable
246+
(Reference))));
247+
248+
use type GPR2.Package_Id;
249+
begin
250+
if Pack = GPR2.Project_Level_Scope then
251+
if View.Has_Variables (Name) then
252+
return View.Variable (Name);
253+
end if;
254+
else
255+
if View.Has_Variables (Pack, Name) then
256+
return View.Variable (Pack, Name);
257+
end if;
258+
end if;
259+
return GPR2.Project.Variable.Undefined;
260+
end Variable;
261+
262+
begin
263+
if LSP.GPR_Files.References.Is_Variable_Reference (Reference)
264+
and then not Self.Tree.Log_Messages.Has_Error
265+
then
266+
declare
267+
File : constant LSP.GPR_Files.File_Access :=
268+
LSP.GPR_Files.References.Referenced_File
269+
(File => Root_File,
270+
Reference => Reference);
271+
Path : constant GPR2.Path_Name.Object :=
272+
LSP.GPR_Files.Path (File.all);
273+
Root : constant GPR2.Project.View.Object := Self.Tree.Root_Project;
274+
begin
275+
if Root.Path_Name = Path then
276+
return Variable (Root);
277+
end if;
278+
if Root.Is_Extended then
279+
declare
280+
Extending : constant GPR2.Project.View.Object :=
281+
Root.Extending;
282+
begin
283+
if Extending.Path_Name = Path then
284+
return Variable (Extending);
285+
end if;
286+
end;
287+
end if;
288+
for Import of Root.Imports loop
289+
if Import.Path_Name = Path then
290+
return Variable (Import);
291+
end if;
292+
end loop;
293+
end;
294+
end if;
295+
return GPR2.Project.Variable.Undefined;
296+
end Get_Variable;
297+
298+
-------------------
299+
-- Get_Attribute --
300+
-------------------
301+
302+
function Get_Attribute
303+
(Self : Document'Class;
304+
Root_File : LSP.GPR_Files.File_Access;
305+
Reference : LSP.GPR_Files.References.Reference)
306+
return GPR2.Project.Attribute.Object is
307+
308+
function Attribute
309+
(View : GPR2.Project.View.Object) return GPR2.Project.Attribute.Object;
310+
311+
Attr_Def : constant LSP.GPR_Files.References.Attribute_Definition :=
312+
LSP.GPR_Files.References.Referenced_Attribute (Reference);
313+
314+
---------------
315+
-- Attribute --
316+
---------------
317+
318+
function Attribute
319+
(View : GPR2.Project.View.Object) return GPR2.Project.Attribute.Object
320+
is
321+
Result : GPR2.Project.Attribute.Object;
322+
begin
323+
if View.Check_Attribute
324+
(Name => Attr_Def.Name,
325+
Index => Attr_Def.Index,
326+
At_Pos => Attr_Def.At_Pos,
327+
Result => Result)
328+
then
329+
return Result;
330+
else
331+
return GPR2.Project.Attribute.Undefined;
332+
end if;
333+
end Attribute;
334+
335+
begin
336+
if LSP.GPR_Files.References.Is_Attribute_Reference (Reference)
337+
and then not Self.Tree.Log_Messages.Has_Error
338+
then
339+
declare
340+
File : constant LSP.GPR_Files.File_Access :=
341+
LSP.GPR_Files.References.Referenced_File
342+
(File => Root_File,
343+
Reference => Reference);
344+
Path : constant GPR2.Path_Name.Object :=
345+
LSP.GPR_Files.Path (File.all);
346+
Root : constant GPR2.Project.View.Object := Self.Tree.Root_Project;
347+
begin
348+
if Root.Path_Name = Path then
349+
return Attribute (Root);
350+
end if;
351+
if Root.Is_Extended then
352+
declare
353+
Extending : constant GPR2.Project.View.Object :=
354+
Root.Extending;
355+
begin
356+
if Extending.Path_Name = Path then
357+
return Attribute (Extending);
358+
end if;
359+
end;
360+
end if;
361+
for Import of Root.Imports loop
362+
if Import.Path_Name = Path then
363+
return Attribute (Import);
364+
end if;
365+
end loop;
366+
end;
367+
end if;
368+
return GPR2.Project.Attribute.Undefined;
369+
end Get_Attribute;
370+
209371
end LSP.GPR_Documents;

source/gpr/lsp-gpr_documents.ads

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ with GPR2.Log;
3131
with GPR2.Path_Name;
3232
with GPR2.Path_Name.Set;
3333
with GPR2.Project.Tree;
34+
with GPR2.Project.Attribute;
35+
with GPR2.Project.Variable;
3436

3537
with LSP.Text_Documents;
3638
with LSP.GPR_Files;
39+
with LSP.GPR_Files.References;
3740
with LSP.Structures;
3841
with LSP.Tracers;
3942

@@ -91,6 +94,11 @@ package LSP.GPR_Documents is
9194
function Has_Diagnostics
9295
(Self : Document)
9396
return Boolean;
97+
-- Returns True when messages found during document parsing.
98+
99+
function Has_Errors
100+
(Self : Document)
101+
return Boolean;
94102
-- Returns True when errors found during document parsing.
95103

96104
-----------------------
@@ -125,6 +133,22 @@ package LSP.GPR_Documents is
125133
procedure Update_Files_With_Diags
126134
(Self : in out Document'Class; Files : GPR2.Path_Name.Set.Object);
127135

136+
function Get_Variable
137+
(Self : Document'Class;
138+
Root_File : LSP.GPR_Files.File_Access;
139+
Reference : LSP.GPR_Files.References.Reference)
140+
return GPR2.Project.Variable.Object;
141+
-- if Document contains a valid Tree & Reference is a variable reference
142+
-- returns corresponding value otherwise returns 'Undefined'
143+
144+
function Get_Attribute
145+
(Self : Document'Class;
146+
Root_File : LSP.GPR_Files.File_Access;
147+
Reference : LSP.GPR_Files.References.Reference)
148+
return GPR2.Project.Attribute.Object;
149+
-- if Document contains a valid Tree & Reference is an attribute reference
150+
-- returns corresponding value otherwise returns 'Undefined'
151+
128152
private
129153

130154
type Name_Information is record

0 commit comments

Comments
 (0)