Skip to content

Commit 9ecf015

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents ba5805c + 6f4fd55 commit 9ecf015

27 files changed

+2303
-97
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ build_and_test:
8383
- cp -r $ANOD_DEFAULT_SANDBOX_DIR/log $CI_PROJECT_DIR/anod-logs
8484
- echo -e "\e[0Ksection_end:`date +%s`:prepare_artifacts\r\e[0K"
8585

86+
- if [ ! -z ${FAILED+x} ]; then cat $CI_PROJECT_DIR/als_xunit_output.xml; fi
87+
- if [ ! -z ${FAILED+x} ]; then cat $CI_PROJECT_DIR/vscode_xunit_output.xml; fi
88+
8689
- if [ ! -z ${FAILED+x} ]; then echo "There was at least one testcase failure" && exit 1; fi
8790

8891
artifacts:

source/ada/lsp-ada_handlers.adb

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ with LSP.Errors;
9494
with LSP.Formatters.Texts;
9595
with LSP.Generic_Cancel_Check;
9696
with LSP.GNATCOLL_Tracers.Handle;
97+
with LSP.Predefined_Completion;
9798
with LSP.Search;
9899
with LSP.Server_Notifications.DidChange;
99100
with LSP.Servers;
@@ -3028,24 +3029,48 @@ package body LSP.Ada_Handlers is
30283029

30293030
Decl_Text : VSS.Strings.Virtual_String;
30303031
Qualifier_Text : VSS.Strings.Virtual_String;
3031-
Comments_Text : VSS.Strings.Virtual_String;
3032+
Documentation_Text : VSS.Strings.Virtual_String;
30323033
Location_Text : VSS.Strings.Virtual_String;
30333034
Aspects_Text : VSS.Strings.Virtual_String;
30343035

30353036
begin
3036-
if Decl.Is_Null or else Self.Is_Canceled.all then
3037+
-- Return immediately if the request has been canceled
3038+
if Self.Is_Canceled.all then
30373039
return;
30383040
end if;
30393041

3040-
LSP.Ada_Documentation.Get_Tooltip_Text
3041-
(BD => Decl,
3042-
Style => Context.Get_Documentation_Style,
3043-
Declaration_Text => Decl_Text,
3044-
Qualifier_Text => Qualifier_Text,
3045-
Location_Text => Location_Text,
3046-
Documentation_Text => Comments_Text,
3047-
Aspects_Text => Aspects_Text);
3042+
if Decl.Is_Null then
3043+
3044+
-- There is no declaration for the hovered node: ask the predefined
3045+
-- entities' completion provider (attributes, pragmas, aspects) for
3046+
-- a tooltip text if it can.
3047+
declare
3048+
Node : constant Libadalang.Analysis.Ada_Node := Self.Get_Node_At
3049+
(Context.all, Value);
3050+
begin
3051+
if not Node.Is_Null
3052+
and then Node.Kind in Libadalang.Common.Ada_Identifier_Range
3053+
then
3054+
LSP.Predefined_Completion.Get_Tooltip_Text
3055+
(Node => Node.As_Identifier,
3056+
Declaration_Text => Decl_Text,
3057+
Documentation_Text => Documentation_Text);
3058+
end if;
3059+
end;
3060+
else
3061+
-- We have resolved the hovered node to its declaration: use
3062+
-- the default tooltip provider, based on GNATdoc.
3063+
LSP.Ada_Documentation.Get_Tooltip_Text
3064+
(BD => Decl,
3065+
Style => Context.Get_Documentation_Style,
3066+
Declaration_Text => Decl_Text,
3067+
Qualifier_Text => Qualifier_Text,
3068+
Location_Text => Location_Text,
3069+
Documentation_Text => Documentation_Text,
3070+
Aspects_Text => Aspects_Text);
3071+
end if;
30483072

3073+
-- Return if no provider has been able to compute text for a tooltip.
30493074
if Decl_Text.Is_Empty then
30503075
return;
30513076
end if;
@@ -3075,28 +3100,30 @@ package body LSP.Ada_Handlers is
30753100
-- In addition, append the project's name if we are dealing with an
30763101
-- aggregate project.
30773102

3078-
Location_Text := LSP.Utils.Node_Location_Image (Decl);
3103+
if not Decl.Is_Null then
3104+
Location_Text := LSP.Utils.Node_Location_Image (Decl);
30793105

3080-
if Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind then
3081-
Location_Text.Append (VSS.Characters.Latin.Line_Feed);
3082-
Location_Text.Append ("As defined in project ");
3083-
Location_Text.Append (Context.Id);
3084-
Location_Text.Append (" (other projects skipped).");
3085-
end if;
3106+
if Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind then
3107+
Location_Text.Append (VSS.Characters.Latin.Line_Feed);
3108+
Location_Text.Append ("As defined in project ");
3109+
Location_Text.Append (Context.Id);
3110+
Location_Text.Append (" (other projects skipped).");
3111+
end if;
30863112

3087-
Response.Value.contents.MarkedString_Vector.Append
3088-
(LSP.Structures.MarkedString'
3089-
(Is_Virtual_String => True,
3090-
Virtual_String => Location_Text));
3113+
Response.Value.contents.MarkedString_Vector.Append
3114+
(LSP.Structures.MarkedString'
3115+
(Is_Virtual_String => True,
3116+
Virtual_String => Location_Text));
3117+
end if;
30913118

30923119
-- Append the comments associated with the basic declaration if any.
30933120

3094-
if not Comments_Text.Is_Empty then
3121+
if not Documentation_Text.Is_Empty then
30953122
Response.Value.contents.MarkedString_Vector.Append
30963123
(LSP.Structures.MarkedString'
30973124
(Is_Virtual_String => False,
30983125
language => "plaintext",
3099-
value => Comments_Text));
3126+
value => Documentation_Text));
31003127
end if;
31013128

31023129
-- Append text of aspects

source/ada/lsp-predefined_completion.adb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with VSS.Strings.Conversions;
2828

2929
with LSP.Enumerations;
3030
with LSP.Predefined_Completion.Ada2012;
31+
with Libadalang.Common;
3132

3233
package body LSP.Predefined_Completion is
3334

@@ -277,4 +278,52 @@ package body LSP.Predefined_Completion is
277278
end;
278279
end Get_Output;
279280

281+
----------------------
282+
-- Get_Tooltip_Text --
283+
----------------------
284+
285+
procedure Get_Tooltip_Text
286+
(Node : Libadalang.Analysis.Identifier;
287+
Declaration_Text : out VSS.Strings.Virtual_String;
288+
Documentation_Text : out VSS.Strings.Virtual_String)
289+
is
290+
use Libadalang.Common;
291+
292+
Filtered_Items : CompletionItem_Vector;
293+
Prefix : VSS.Strings.Virtual_String;
294+
Parent : constant Libadalang.Analysis.Ada_Node :=
295+
(if Node.Is_Null then Libadalang.Analysis.No_Ada_Node
296+
else Node.Parent);
297+
Item : CompletionItem;
298+
begin
299+
-- Return immediately if the node is null of if its parent is null
300+
if Node.Is_Null or else Parent.Is_Null then
301+
return;
302+
end if;
303+
304+
-- Get the attribute/aspect/pragma completion item corresponding to the
305+
-- given node
306+
307+
Prefix := VSS.Strings.To_Virtual_String (Node.Text);
308+
309+
case Parent.Kind is
310+
when Ada_Attribute_Ref_Range =>
311+
Get_Attributes (Prefix => Prefix, Result => Filtered_Items);
312+
313+
when Ada_Aspect_Assoc_Range =>
314+
Get_Aspects (Prefix => Prefix, Result => Filtered_Items);
315+
316+
when Ada_Pragma_Node_Range =>
317+
Get_Pragmas (Prefix => Prefix, Result => Filtered_Items);
318+
319+
when others =>
320+
return;
321+
end case;
322+
323+
Item := Filtered_Items.First_Element;
324+
325+
Declaration_Text := Item.detail;
326+
Documentation_Text := Item.documentation.Value.Virtual_String;
327+
end Get_Tooltip_Text;
328+
280329
end LSP.Predefined_Completion;

source/ada/lsp-predefined_completion.ads

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ with GNATCOLL.Traces; use GNATCOLL.Traces;
2020
with VSS.Strings;
2121

2222
with LSP.Structures; use LSP.Structures;
23+
with Libadalang.Analysis;
2324

2425
package LSP.Predefined_Completion is
2526

@@ -43,4 +44,19 @@ package LSP.Predefined_Completion is
4344
Result : in out CompletionItem_Vector);
4445
-- Return completion for pragmas, filtering the results using Prefix.
4546

47+
procedure Get_Tooltip_Text
48+
(Node : Libadalang.Analysis.Identifier;
49+
Declaration_Text : out VSS.Strings.Virtual_String;
50+
Documentation_Text : out VSS.Strings.Virtual_String);
51+
-- Get all the information needed to produce tooltips (hover and completion
52+
-- requests) for the given node, if it's a predefined entity (e.g: aspect,
53+
-- pragma or attribute).
54+
--
55+
-- @param Node
56+
-- The predefined entity's node.
57+
-- @param Declaration_Text
58+
-- Contains the code corresponding to the predefined entity's declaration.
59+
-- @param Documentation_Text
60+
-- Contains the documentation associated to the predefined entity.
61+
4662
end LSP.Predefined_Completion;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2023, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
pragma Ada_2022;
19+
20+
with VSS.String_Vectors;
21+
22+
with LSP.Structures.Unwrap;
23+
24+
package body LSP.GPR_Client_Capabilities is
25+
26+
----------------
27+
-- Initialize --
28+
----------------
29+
30+
procedure Initialize
31+
(Self : in out Client_Capability'Class;
32+
Value : LSP.Structures.InitializeParams) is
33+
begin
34+
Self.Value := Value;
35+
end Initialize;
36+
37+
--------------------
38+
-- Resolve_Lazily --
39+
--------------------
40+
41+
function Resolve_Lazily (Self : Client_Capability'Class) return Boolean is
42+
use LSP.Structures.Unwrap;
43+
44+
List : constant VSS.String_Vectors.Virtual_String_Vector :=
45+
properties
46+
(resolveSupport
47+
(completionItem
48+
(completion
49+
(Self.Value.capabilities.textDocument))));
50+
51+
begin
52+
return List.Contains ("detail") and then List.Contains ("documentation");
53+
end Resolve_Lazily;
54+
55+
end LSP.GPR_Client_Capabilities;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2023, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
with LSP.Structures;
19+
20+
package LSP.GPR_Client_Capabilities is
21+
22+
type Client_Capability is tagged limited private;
23+
-- This type holds client initialization response and provides handy
24+
-- queries on the client capabilities
25+
26+
procedure Initialize
27+
(Self : in out Client_Capability'Class;
28+
Value : LSP.Structures.InitializeParams);
29+
-- Save initialize parameters
30+
31+
function Resolve_Lazily (Self : Client_Capability'Class) return Boolean;
32+
-- Returns True when resolve contains `documentation` and `details`
33+
34+
private
35+
36+
type Client_Capability is tagged limited record
37+
Value : LSP.Structures.InitializeParams;
38+
end record;
39+
40+
end LSP.GPR_Client_Capabilities;

0 commit comments

Comments
 (0)