Skip to content

Commit 94bd93d

Browse files
committed
Merge branch 'topic/vadim/docs' into 'master'
Enhancements of documentation extraction See merge request eng/ide/ada_language_server!2113
2 parents 23872d5 + 0eb1c97 commit 94bd93d

File tree

29 files changed

+250
-175
lines changed

29 files changed

+250
-175
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ include:
7272
anod-args: run test_vscode_extension_$ACI_TRACK
7373
image: systemgtk
7474
windows: true
75+
# 8GB of memory leads to heap exhaustion during compilation. We need more.
76+
windows-mem: 16
7577

7678
# Integration testsuite
7779
- component: $CI_SERVER_FQDN/eng/gitlab-templates/test@~latest

source/ada/lsp-ada_completions-generic_assoc.adb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2022-2024, AdaCore --
4+
-- Copyright (C) 2022-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -188,7 +188,7 @@ package body LSP.Ada_Completions.Generic_Assoc is
188188
procedure Generate_Snippets
189189
(Spec_Designators : Laltools.Common.Node_Vectors.Vector;
190190
Param_Types : Param_To_Type_Maps.Map;
191-
Decl : Basic_Decl;
191+
Name : Defining_Name;
192192
Title : VSS.Strings.Virtual_String;
193193
Snippet_Prefix : VSS.Strings.Virtual_String;
194194
Completion_Prefix : VSS.Strings.Virtual_String);
@@ -222,7 +222,7 @@ package body LSP.Ada_Completions.Generic_Assoc is
222222
procedure Generate_Snippets
223223
(Spec_Designators : Laltools.Common.Node_Vectors.Vector;
224224
Param_Types : Param_To_Type_Maps.Map;
225-
Decl : Basic_Decl;
225+
Name : Defining_Name;
226226
Title : VSS.Strings.Virtual_String;
227227
Snippet_Prefix : VSS.Strings.Virtual_String;
228228
Completion_Prefix : VSS.Strings.Virtual_String)
@@ -381,7 +381,7 @@ package body LSP.Ada_Completions.Generic_Assoc is
381381
LSP.Ada_Documents.Set_Completion_Item_Documentation
382382
(Handler => Self.Handler.all,
383383
Context => Self.Context.all,
384-
BD => Decl,
384+
Name => Name,
385385
Item => Item,
386386
Compute_Doc_And_Details =>
387387
Self.Compute_Doc_And_Details);
@@ -439,7 +439,7 @@ package body LSP.Ada_Completions.Generic_Assoc is
439439
Generate_Snippets
440440
(Spec_Designators => Spec.Param_Vector,
441441
Param_Types => Spec.Param_Types,
442-
Decl => Spec.Decl,
442+
Name => Spec.Decl.P_Defining_Name,
443443
Title => Spec.Title,
444444
Snippet_Prefix => Spec.Prefix,
445445
Completion_Prefix => Completion_Prefix);
@@ -515,7 +515,8 @@ package body LSP.Ada_Completions.Generic_Assoc is
515515

516516
begin
517517
LSP.Ada_Documentation.Get_Tooltip_Text
518-
(BD => Spec.Decl,
518+
(Name => Spec.Decl.P_Defining_Name,
519+
Origin => Libadalang.Analysis.No_Ada_Node,
519520
Style => Context.Get_Documentation_Style,
520521
Declaration_Text => Declaration_Text,
521522
Qualifier_Text => Qualifier_Text,

source/ada/lsp-ada_completions-generic_assoc_utils.ads

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2022, AdaCore --
4+
-- Copyright (C) 2022-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -64,6 +64,8 @@ package LSP.Ada_Completions.Generic_Assoc_Utils is
6464
Decl : Libadalang.Analysis.Basic_Decl :=
6565
Libadalang.Analysis.No_Basic_Decl;
6666
-- Basic_Decl to retrieve the documentation
67+
--
68+
-- XXX Defining_Name nodes should be used for documentation extraction
6769

6870
Title : VSS.Strings.Virtual_String;
6971
-- Title of the CompletionItem

source/ada/lsp-ada_completions-names.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2024, AdaCore --
4+
-- Copyright (C) 2018-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -206,6 +206,7 @@ package body LSP.Ada_Completions.Names is
206206

207207
Names.Include
208208
(DN.P_Canonical_Part,
209+
-- XXX Should most visible part be used here ???
209210
(Error_Dotted_Recovery or else Is_Dot_Call (Item),
210211
Is_Visible (Item),
211212
Use_Snippets,

source/ada/lsp-ada_completions.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2023, AdaCore --
4+
-- Copyright (C) 2018-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -173,7 +173,7 @@ package body LSP.Ada_Completions is
173173
Sloc => Sloc,
174174
From => From,
175175
Node => Node,
176-
BD => Name.P_Basic_Decl,
176+
Name => Name,
177177
Label => Label,
178178
Use_Snippets => Info.Use_Snippets,
179179
Compute_Doc_And_Details => Compute_Doc_And_Details,

source/ada/lsp-ada_documentation.adb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2023, AdaCore --
4+
-- Copyright (C) 2023-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -224,14 +224,17 @@ package body LSP.Ada_Documentation is
224224
----------------------
225225

226226
procedure Get_Tooltip_Text
227-
(BD : Libadalang.Analysis.Basic_Decl;
227+
(Name : Libadalang.Analysis.Defining_Name;
228+
Origin : Libadalang.Analysis.Ada_Node'Class;
228229
Style : GNATdoc.Comments.Options.Documentation_Style;
229230
Declaration_Text : out VSS.Strings.Virtual_String;
230231
Qualifier_Text : out VSS.Strings.Virtual_String;
231232
Location_Text : out VSS.Strings.Virtual_String;
232233
Documentation_Text : out VSS.Strings.Virtual_String;
233234
Aspects_Text : out VSS.Strings.Virtual_String)
234235
is
236+
Decl : constant Libadalang.Analysis.Basic_Decl :=
237+
Name.P_Basic_Decl;
235238
Options : constant
236239
GNATdoc.Comments.Options.Extractor_Options :=
237240
(Style => Style,
@@ -247,7 +250,8 @@ package body LSP.Ada_Documentation is
247250
-- Extract documentation with GNATdoc when supported.
248251

249252
GNATdoc.Comments.Helpers.Get_Plain_Text_Documentation
250-
(Name => BD.P_Defining_Name,
253+
(Name => Name,
254+
Origin => Origin,
251255
Options => Options,
252256
Code_Snippet => Decl_Lines,
253257
Documentation => Doc_Lines);
@@ -260,15 +264,15 @@ package body LSP.Ada_Documentation is
260264

261265
if Declaration_Text.Is_Empty then
262266
Declaration_Text :=
263-
Get_Hover_Text_For_Node (BD).Join_Lines
267+
Get_Hover_Text_For_Node (Decl).Join_Lines
264268
(Document_LSP_New_Line_Function, False);
265269
end if;
266270

267-
Location_Text := LSP.Utils.Node_Location_Image (BD);
271+
Location_Text := LSP.Utils.Node_Location_Image (Decl);
268272

269273
-- For subprograms, do additional analysis and construct qualifier.
270274

271-
case BD.Kind is
275+
case Decl.Kind is
272276
when Ada_Abstract_Subp_Decl =>
273277
Qualifier_Text.Append ("abstract");
274278

@@ -283,7 +287,7 @@ package body LSP.Ada_Documentation is
283287

284288
declare
285289
Aspects : constant Libadalang.Analysis.Aspect_Spec :=
286-
BD.F_Aspects;
290+
Decl.F_Aspects;
287291

288292
begin
289293
if not Aspects.Is_Null then

source/ada/lsp-ada_documentation.ads

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2023, AdaCore --
4+
-- Copyright (C) 2023-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -26,7 +26,8 @@ with GNATdoc.Comments.Options;
2626
package LSP.Ada_Documentation is
2727

2828
procedure Get_Tooltip_Text
29-
(BD : Libadalang.Analysis.Basic_Decl;
29+
(Name : Libadalang.Analysis.Defining_Name;
30+
Origin : Libadalang.Analysis.Ada_Node'Class;
3031
Style : GNATdoc.Comments.Options.Documentation_Style;
3132
Declaration_Text : out VSS.Strings.Virtual_String;
3233
Qualifier_Text : out VSS.Strings.Virtual_String;
@@ -36,7 +37,11 @@ package LSP.Ada_Documentation is
3637
-- Get all the information needed to produce tooltips (hover and completion
3738
-- requests) for the given declaration.
3839
--
39-
-- @param BD Declaration's node.
40+
-- @param Name Defining name's node.
41+
-- @param Origin
42+
-- AST node at the origin of the request (location in the source code).
43+
-- It is used to determine most visible part of the declaration and
44+
-- to construct corresponding documentation.
4045
-- @param Style
4146
-- Is used by GNATdoc for extracting the associated comments.
4247
-- @param Qualifier_Text

source/ada/lsp-ada_documents.adb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ package body LSP.Ada_Documents is
112112
Sloc : Langkit_Support.Slocs.Source_Location;
113113
From : Langkit_Support.Slocs.Source_Location;
114114
Node : Libadalang.Analysis.Ada_Node;
115-
BD : Libadalang.Analysis.Basic_Decl;
115+
Name : Libadalang.Analysis.Defining_Name;
116116
Label : VSS.Strings.Virtual_String;
117117
Use_Snippets : Boolean;
118118
Compute_Doc_And_Details : Boolean;
@@ -189,7 +189,7 @@ package body LSP.Ada_Documents is
189189
-- string if we are not completing a dotted name.
190190

191191
Missing_Unit_Root_Decl : constant Libadalang.Analysis.Basic_Decl :=
192-
BD.P_Enclosing_Compilation_Unit.P_Decl;
192+
Name.P_Enclosing_Compilation_Unit.P_Decl;
193193
-- The missing unit root declaration for this invisible symbol (e.g:
194194
-- the "Ada.Text_IO" package declaration for the
195195
-- "Ada.Text_IO.Put_Line" subprogram).
@@ -231,7 +231,9 @@ package body LSP.Ada_Documents is
231231
-- the user selects "Ada.Text_IO" in the completion window, we do not
232232
-- need to add any qualifier) or if he's completing a dotted name.
233233
Missing_Qualifier :=
234-
(if Is_Dotted_Name or else BD = Missing_Unit_Root_Decl then
234+
(if Is_Dotted_Name
235+
or else Name.P_Basic_Decl = Missing_Unit_Root_Decl
236+
then
235237
VSS.Strings.Empty_Virtual_String
236238
else
237239
Missing_Unit_Name);
@@ -295,7 +297,9 @@ package body LSP.Ada_Documents is
295297

296298
begin
297299
Item.label := Label;
298-
Item.kind := (True, To_Completion_Kind (LSP.Utils.Get_Decl_Kind (BD)));
300+
Item.kind :=
301+
(True,
302+
To_Completion_Kind (LSP.Utils.Get_Decl_Kind (Name.P_Basic_Decl)));
299303

300304
if not Is_Visible then
301305
Item.insertText := Label;
@@ -318,7 +322,7 @@ package body LSP.Ada_Documents is
318322
Set_Completion_Item_Documentation
319323
(Handler => Handler,
320324
Context => Context,
321-
BD => BD,
325+
Name => Name,
322326
Item => Item,
323327
Compute_Doc_And_Details => Compute_Doc_And_Details);
324328

@@ -331,7 +335,7 @@ package body LSP.Ada_Documents is
331335
-- Check if we are dealing with a subprogram and return a completion
332336
-- snippet that lists all the formal parameters if it's the case.
333337

334-
Subp_Spec_Node := BD.P_Subp_Spec_Or_Null;
338+
Subp_Spec_Node := Name.P_Basic_Decl.P_Subp_Spec_Or_Null;
335339

336340
if Subp_Spec_Node.Is_Null then
337341
return Item;
@@ -1360,7 +1364,7 @@ package body LSP.Ada_Documents is
13601364
procedure Set_Completion_Item_Documentation
13611365
(Handler : in out LSP.Ada_Handlers.Message_Handler;
13621366
Context : LSP.Ada_Contexts.Context;
1363-
BD : Libadalang.Analysis.Basic_Decl;
1367+
Name : Libadalang.Analysis.Defining_Name;
13641368
Item : in out LSP.Structures.CompletionItem;
13651369
Compute_Doc_And_Details : Boolean)
13661370
is
@@ -1370,7 +1374,7 @@ package body LSP.Ada_Documents is
13701374
-- Compute the 'documentation' and 'detail' fields immediately if
13711375
-- requested (i.e: when the client does not support lazy computation
13721376
-- for these fields or if we are dealing with predefined types).
1373-
if Compute_Doc_And_Details or else LSP.Utils.Is_Synthetic (BD) then
1377+
if Compute_Doc_And_Details or else LSP.Utils.Is_Synthetic (Name) then
13741378
declare
13751379
Qual_Text : VSS.Strings.Virtual_String;
13761380
Decl_Text : VSS.Strings.Virtual_String;
@@ -1380,7 +1384,8 @@ package body LSP.Ada_Documents is
13801384

13811385
begin
13821386
LSP.Ada_Documentation.Get_Tooltip_Text
1383-
(BD => BD,
1387+
(Name => Name,
1388+
Origin => Libadalang.Analysis.No_Ada_Node,
13841389
Style => Context.Get_Documentation_Style,
13851390
Declaration_Text => Decl_Text,
13861391
Qualifier_Text => Qual_Text,
@@ -1406,7 +1411,7 @@ package body LSP.Ada_Documents is
14061411
-- Set node's location to the 'data' field of the completion item, so
14071412
-- that we can retrieve it in the completionItem/resolve handler.
14081413
LSP.Structures.LSPAny_Vectors.To_Any
1409-
(LSP.Ada_Handlers.Locations.To_LSP_Location (Handler, BD),
1414+
(LSP.Ada_Handlers.Locations.To_LSP_Location (Handler, Name),
14101415
Item.data);
14111416
end if;
14121417
end Set_Completion_Item_Documentation;

source/ada/lsp-ada_documents.ads

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2023, AdaCore --
4+
-- Copyright (C) 2018-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -250,7 +250,7 @@ package LSP.Ada_Documents is
250250
Sloc : Langkit_Support.Slocs.Source_Location;
251251
From : Langkit_Support.Slocs.Source_Location;
252252
Node : Libadalang.Analysis.Ada_Node;
253-
BD : Libadalang.Analysis.Basic_Decl;
253+
Name : Libadalang.Analysis.Defining_Name;
254254
Label : VSS.Strings.Virtual_String;
255255
Use_Snippets : Boolean;
256256
Compute_Doc_And_Details : Boolean;
@@ -278,7 +278,7 @@ package LSP.Ada_Documents is
278278
procedure Set_Completion_Item_Documentation
279279
(Handler : in out LSP.Ada_Handlers.Message_Handler;
280280
Context : LSP.Ada_Contexts.Context;
281-
BD : Libadalang.Analysis.Basic_Decl;
281+
Name : Libadalang.Analysis.Defining_Name;
282282
Item : in out LSP.Structures.CompletionItem;
283283
Compute_Doc_And_Details : Boolean);
284284
-- Either set the item documentation and details or setup it to produce

source/ada/lsp-ada_handlers.adb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2023, AdaCore --
4+
-- Copyright (C) 2018-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -1929,6 +1929,8 @@ package body LSP.Ada_Handlers is
19291929
Id : LSP.Structures.Integer_Or_Virtual_String;
19301930
Value : LSP.Structures.CompletionItem)
19311931
is
1932+
use all type Libadalang.Common.Ada_Node_Kind_Type;
1933+
19321934
Context : LSP.Ada_Context_Sets.Context_Access;
19331935
Node : Libadalang.Analysis.Ada_Node;
19341936
C : LSP.Structures.JSON_Event_Vectors.Cursor;
@@ -1956,20 +1958,18 @@ package body LSP.Ada_Handlers is
19561958
(textDocument => (uri => Location.uri),
19571959
position => Location.a_range.start));
19581960

1959-
-- Retrieve the Basic_Decl from the completion item's SLOC
1960-
while not Node.Is_Null
1961-
and then Node.Kind not in Libadalang.Common.Ada_Basic_Decl
1962-
loop
1961+
if Node.Kind = Libadalang.Common.Ada_Identifier then
1962+
-- When node is an identifier, take parent node to resolve to
1963+
-- defining name. It is a case of names of package identifiers.
1964+
19631965
Node := Node.Parent;
1964-
end loop;
1966+
end if;
19651967

19661968
-- Compute the completion item's details
19671969
if not Node.Is_Null then
19681970
declare
19691971
use type VSS.Strings.Virtual_String;
19701972

1971-
BD : constant Libadalang.Analysis.Basic_Decl :=
1972-
Node.As_Basic_Decl;
19731973
Qual_Text : VSS.Strings.Virtual_String;
19741974
Loc_Text : VSS.Strings.Virtual_String;
19751975
Doc_Text : VSS.Strings.Virtual_String;
@@ -1978,7 +1978,8 @@ package body LSP.Ada_Handlers is
19781978

19791979
begin
19801980
LSP.Ada_Documentation.Get_Tooltip_Text
1981-
(BD => BD,
1981+
(Name => Node.As_Defining_Name,
1982+
Origin => Libadalang.Analysis.No_Ada_Node,
19821983
Style => Self.Configuration.Documentation_Style,
19831984
Qualifier_Text => Qual_Text,
19841985
Location_Text => Loc_Text,

0 commit comments

Comments
 (0)