Skip to content

Commit d71afd8

Browse files
committed
Use Defining_Name to reference of entity to extract documentation
1 parent 2810584 commit d71afd8

10 files changed

+60
-44
lines changed

source/ada/lsp-ada_completions-generic_assoc.adb

Lines changed: 6 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,7 @@ 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,
519519
Style => Context.Get_Documentation_Style,
520520
Declaration_Text => Declaration_Text,
521521
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: 9 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,16 @@ 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;
228228
Style : GNATdoc.Comments.Options.Documentation_Style;
229229
Declaration_Text : out VSS.Strings.Virtual_String;
230230
Qualifier_Text : out VSS.Strings.Virtual_String;
231231
Location_Text : out VSS.Strings.Virtual_String;
232232
Documentation_Text : out VSS.Strings.Virtual_String;
233233
Aspects_Text : out VSS.Strings.Virtual_String)
234234
is
235+
Decl : constant Libadalang.Analysis.Basic_Decl :=
236+
Name.P_Basic_Decl;
235237
Options : constant
236238
GNATdoc.Comments.Options.Extractor_Options :=
237239
(Style => Style,
@@ -247,7 +249,7 @@ package body LSP.Ada_Documentation is
247249
-- Extract documentation with GNATdoc when supported.
248250

249251
GNATdoc.Comments.Helpers.Get_Plain_Text_Documentation
250-
(Name => BD.P_Defining_Name,
252+
(Name => Name,
251253
Options => Options,
252254
Code_Snippet => Decl_Lines,
253255
Documentation => Doc_Lines);
@@ -260,15 +262,15 @@ package body LSP.Ada_Documentation is
260262

261263
if Declaration_Text.Is_Empty then
262264
Declaration_Text :=
263-
Get_Hover_Text_For_Node (BD).Join_Lines
265+
Get_Hover_Text_For_Node (Decl).Join_Lines
264266
(Document_LSP_New_Line_Function, False);
265267
end if;
266268

267-
Location_Text := LSP.Utils.Node_Location_Image (BD);
269+
Location_Text := LSP.Utils.Node_Location_Image (Decl);
268270

269271
-- For subprograms, do additional analysis and construct qualifier.
270272

271-
case BD.Kind is
273+
case Decl.Kind is
272274
when Ada_Abstract_Subp_Decl =>
273275
Qualifier_Text.Append ("abstract");
274276

@@ -283,7 +285,7 @@ package body LSP.Ada_Documentation is
283285

284286
declare
285287
Aspects : constant Libadalang.Analysis.Aspect_Spec :=
286-
BD.F_Aspects;
288+
Decl.F_Aspects;
287289

288290
begin
289291
if not Aspects.Is_Null then

source/ada/lsp-ada_documentation.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) 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,7 @@ 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;
3030
Style : GNATdoc.Comments.Options.Documentation_Style;
3131
Declaration_Text : out VSS.Strings.Virtual_String;
3232
Qualifier_Text : out VSS.Strings.Virtual_String;
@@ -36,7 +36,7 @@ package LSP.Ada_Documentation is
3636
-- Get all the information needed to produce tooltips (hover and completion
3737
-- requests) for the given declaration.
3838
--
39-
-- @param BD Declaration's node.
39+
-- @param Name Defining name's node.
4040
-- @param Style
4141
-- Is used by GNATdoc for extracting the associated comments.
4242
-- @param Qualifier_Text

source/ada/lsp-ada_documents.adb

Lines changed: 14 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,7 @@ package body LSP.Ada_Documents is
13801384

13811385
begin
13821386
LSP.Ada_Documentation.Get_Tooltip_Text
1383-
(BD => BD,
1387+
(Name => Name,
13841388
Style => Context.Get_Documentation_Style,
13851389
Declaration_Text => Decl_Text,
13861390
Qualifier_Text => Qual_Text,
@@ -1406,7 +1410,7 @@ package body LSP.Ada_Documents is
14061410
-- Set node's location to the 'data' field of the completion item, so
14071411
-- that we can retrieve it in the completionItem/resolve handler.
14081412
LSP.Structures.LSPAny_Vectors.To_Any
1409-
(LSP.Ada_Handlers.Locations.To_LSP_Location (Handler, BD),
1413+
(LSP.Ada_Handlers.Locations.To_LSP_Location (Handler, Name),
14101414
Item.data);
14111415
end if;
14121416
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: 16 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,25 @@ 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;
1967+
1968+
-- Retrieve the Basic_Decl from the completion item's SLOC
1969+
-- while not Node.Is_Null
1970+
-- and then Node.Kind not in Libadalang.Common.Ada_Basic_Decl
1971+
-- loop
1972+
-- Node := Node.Parent;
1973+
-- end loop;
19651974

19661975
-- Compute the completion item's details
19671976
if not Node.Is_Null then
19681977
declare
19691978
use type VSS.Strings.Virtual_String;
19701979

1971-
BD : constant Libadalang.Analysis.Basic_Decl :=
1972-
Node.As_Basic_Decl;
19731980
Qual_Text : VSS.Strings.Virtual_String;
19741981
Loc_Text : VSS.Strings.Virtual_String;
19751982
Doc_Text : VSS.Strings.Virtual_String;
@@ -1978,7 +1985,7 @@ package body LSP.Ada_Handlers is
19781985

19791986
begin
19801987
LSP.Ada_Documentation.Get_Tooltip_Text
1981-
(BD => BD,
1988+
(Name => Node.As_Defining_Name,
19821989
Style => Self.Configuration.Documentation_Style,
19831990
Qualifier_Text => Qual_Text,
19841991
Location_Text => Loc_Text,

0 commit comments

Comments
 (0)