Skip to content

Commit ac3604b

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 5a376d5 + 1d400cd commit ac3604b

20 files changed

+472
-324
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ with GNATCOLL.Utils;
4040
with LSP.Ada_Commands;
4141
with LSP.Ada_Did_Change_Configurations;
4242
with LSP.Ada_Did_Change_Document;
43+
with LSP.Ada_Hover;
4344
with LSP.Ada_References;
4445
with LSP.Ada_Handlers;
4546
with LSP.Ada_Handlers.Executables_Commands;
@@ -75,6 +76,7 @@ with LSP.Predefined_Completion;
7576
with LSP.Secure_Message_Loggers;
7677
with LSP.Server_Notifications.DidChange;
7778
with LSP.Server_Notifications.DidChangeConfiguration;
79+
with LSP.Server_Requests.Hover;
7880
with LSP.Server_Requests.References;
7981
with LSP.Servers;
8082
with LSP.Stdio_Streams;
@@ -183,7 +185,10 @@ procedure LSP.Ada_Driver is
183185
(Ada_Handler'Unchecked_Access);
184186

185187
Ada_References_Handler : aliased LSP.Ada_References.Ada_References_Handler
186-
(Ada_Handler'Unchecked_Access);
188+
(Ada_Handler'Unchecked_Access);
189+
190+
Ada_Hover_Handler : aliased LSP.Ada_Hover.Ada_Hover_Handler
191+
(Ada_Handler'Unchecked_Access);
187192

188193
GPR_Did_Change_Doc_Handler : aliased
189194
LSP.GPR_Did_Change_Document.GPR_Did_Change_Handler
@@ -393,6 +398,10 @@ begin
393398
(LSP.Server_Notifications.DidChange.Notification'Tag,
394399
Ada_Did_Change_Doc_Handler'Unchecked_Access);
395400

401+
Server.Register_Handler
402+
(LSP.Server_Requests.Hover.Request'Tag,
403+
Ada_Hover_Handler'Unchecked_Access);
404+
396405
Server.Register_Handler
397406
(LSP.Server_Requests.References.Request'Tag,
398407
Ada_References_Handler'Unchecked_Access);

source/ada/lsp-ada_handlers.adb

Lines changed: 4 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ with LSP.Errors;
9090
with LSP.Formatters.Texts;
9191
with LSP.Generic_Cancel_Check;
9292
with LSP.GNATCOLL_Tracers.Handle;
93-
with LSP.Predefined_Completion;
9493
with LSP.Search;
9594
with LSP.Servers;
9695
with LSP.Servers.FS_Watch;
@@ -142,12 +141,12 @@ package body LSP.Ada_Handlers is
142141
return LSP.Structures.Location
143142
renames LSP.Ada_Handlers.Locations.To_LSP_Location;
144143

145-
function Get_Node_At
146-
(Self : in out Message_Handler'Class;
144+
overriding function Get_Node_At
145+
(Self : in out Message_Handler;
147146
Context : LSP.Ada_Contexts.Context;
148147
Value : LSP.Structures.TextDocumentPositionParams'Class)
149-
return Libadalang.Analysis.Ada_Node
150-
renames LSP.Ada_Handlers.Locations.Get_Node_At;
148+
return Libadalang.Analysis.Ada_Node is
149+
(LSP.Ada_Handlers.Locations.Get_Node_At (Self, Context, Value));
151150

152151
overriding procedure Append_Location
153152
(Self : in out Message_Handler;
@@ -2840,153 +2839,6 @@ package body LSP.Ada_Handlers is
28402839
end if;
28412840
end On_Formatting_Request;
28422841

2843-
----------------------
2844-
-- On_Hover_Request --
2845-
----------------------
2846-
2847-
overriding procedure On_Hover_Request
2848-
(Self : in out Message_Handler;
2849-
Id : LSP.Structures.Integer_Or_Virtual_String;
2850-
Value : LSP.Structures.HoverParams)
2851-
is
2852-
2853-
Response : LSP.Structures.Hover_Or_Null;
2854-
2855-
procedure Compute_Response;
2856-
2857-
----------------------
2858-
-- Compute_Response --
2859-
----------------------
2860-
2861-
procedure Compute_Response is
2862-
Context : constant LSP.Ada_Context_Sets.Context_Access :=
2863-
Self.Contexts.Get_Best_Context (Value.textDocument.uri);
2864-
-- For the Hover request, we're only interested in the "best"
2865-
-- response value, not in the list of values for all contexts
2866-
2867-
Defining_Name_Node : constant Libadalang.Analysis.Defining_Name :=
2868-
Self.Imprecise_Resolve_Name (Context.all, Value);
2869-
Decl : constant Libadalang.Analysis.Basic_Decl :=
2870-
(if Defining_Name_Node.Is_Null
2871-
then Libadalang.Analysis.No_Basic_Decl
2872-
else Defining_Name_Node.P_Basic_Decl);
2873-
-- Associated basic declaration, if any
2874-
2875-
Decl_Text : VSS.Strings.Virtual_String;
2876-
Qualifier_Text : VSS.Strings.Virtual_String;
2877-
Documentation_Text : VSS.Strings.Virtual_String;
2878-
Location_Text : VSS.Strings.Virtual_String;
2879-
Aspects_Text : VSS.Strings.Virtual_String;
2880-
2881-
begin
2882-
-- Return immediately if the request has been canceled
2883-
if Self.Is_Canceled.all then
2884-
return;
2885-
end if;
2886-
2887-
if Decl.Is_Null then
2888-
2889-
-- There is no declaration for the hovered node: ask the predefined
2890-
-- entities' completion provider (attributes, pragmas, aspects) for
2891-
-- a tooltip text if it can.
2892-
declare
2893-
Node : constant Libadalang.Analysis.Ada_Node := Self.Get_Node_At
2894-
(Context.all, Value);
2895-
begin
2896-
if not Node.Is_Null
2897-
and then Node.Kind in Libadalang.Common.Ada_Identifier_Range
2898-
then
2899-
LSP.Predefined_Completion.Get_Tooltip_Text
2900-
(Node => Node.As_Identifier,
2901-
Declaration_Text => Decl_Text,
2902-
Documentation_Text => Documentation_Text);
2903-
end if;
2904-
end;
2905-
else
2906-
-- We have resolved the hovered node to its declaration: use
2907-
-- the default tooltip provider, based on GNATdoc.
2908-
LSP.Ada_Documentation.Get_Tooltip_Text
2909-
(BD => Decl,
2910-
Style => Context.Get_Documentation_Style,
2911-
Declaration_Text => Decl_Text,
2912-
Qualifier_Text => Qualifier_Text,
2913-
Location_Text => Location_Text,
2914-
Documentation_Text => Documentation_Text,
2915-
Aspects_Text => Aspects_Text);
2916-
end if;
2917-
2918-
-- Return if no provider has been able to compute text for a tooltip.
2919-
if Decl_Text.Is_Empty then
2920-
return;
2921-
end if;
2922-
2923-
Response := (Is_Null => False, others => <>);
2924-
Response.Value.contents := (Is_MarkupContent => False, others => <>);
2925-
2926-
-- Append the whole declaration text to the response
2927-
2928-
Response.Value.contents.MarkedString_Vector.Append
2929-
(LSP.Structures.MarkedString'
2930-
(Is_Virtual_String => False,
2931-
value => Decl_Text,
2932-
language => "ada"));
2933-
2934-
-- Append qualifier text if any
2935-
2936-
if not Qualifier_Text.Is_Empty then
2937-
Response.Value.contents.MarkedString_Vector.Append
2938-
(LSP.Structures.MarkedString'
2939-
(Is_Virtual_String => True,
2940-
Virtual_String => Qualifier_Text));
2941-
end if;
2942-
2943-
-- Append the declaration's location.
2944-
--
2945-
-- In addition, append the project's name if we are dealing with an
2946-
-- aggregate project.
2947-
2948-
if not Decl.Is_Null then
2949-
Location_Text := LSP.Utils.Node_Location_Image (Decl);
2950-
2951-
if Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind then
2952-
Location_Text.Append (VSS.Characters.Latin.Line_Feed);
2953-
Location_Text.Append ("As defined in project ");
2954-
Location_Text.Append (Context.Id);
2955-
Location_Text.Append (" (other projects skipped).");
2956-
end if;
2957-
2958-
Response.Value.contents.MarkedString_Vector.Append
2959-
(LSP.Structures.MarkedString'
2960-
(Is_Virtual_String => True,
2961-
Virtual_String => Location_Text));
2962-
end if;
2963-
2964-
-- Append the comments associated with the basic declaration if any.
2965-
2966-
if not Documentation_Text.Is_Empty then
2967-
Response.Value.contents.MarkedString_Vector.Append
2968-
(LSP.Structures.MarkedString'
2969-
(Is_Virtual_String => False,
2970-
language => "plaintext",
2971-
value => Documentation_Text));
2972-
end if;
2973-
2974-
-- Append text of aspects
2975-
2976-
if not Aspects_Text.Is_Empty then
2977-
Response.Value.contents.MarkedString_Vector.Append
2978-
(LSP.Structures.MarkedString'
2979-
(Is_Virtual_String => False,
2980-
value => Aspects_Text,
2981-
language => "ada"));
2982-
end if;
2983-
end Compute_Response;
2984-
2985-
begin
2986-
Compute_Response;
2987-
Self.Sender.On_Hover_Response (Id, Response);
2988-
end On_Hover_Request;
2989-
29902842
-------------------------------
29912843
-- On_Implementation_Request --
29922844
-------------------------------

source/ada/lsp-ada_handlers.ads

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ limited with LSP.Servers;
5151
with LSP.Structures;
5252
with LSP.Tracers;
5353
with LSP.Unimplemented_Handlers;
54-
5554
with URIs;
5655

5756
private with LAL_Refactor;
@@ -295,11 +294,6 @@ private
295294

296295
overriding procedure On_Exits_Notification (Self : in out Message_Handler);
297296

298-
overriding procedure On_Hover_Request
299-
(Self : in out Message_Handler;
300-
Id : LSP.Structures.Integer_Or_Virtual_String;
301-
Value : LSP.Structures.HoverParams);
302-
303297
overriding procedure On_Shutdown_Request
304298
(Self : in out Message_Handler;
305299
Id : LSP.Structures.Integer_Or_Virtual_String);
@@ -501,8 +495,24 @@ private
501495
overriding function Project_Tree_Is_Defined (Self : Message_Handler)
502496
return Boolean is (Self.Project_Tree.Is_Defined);
503497

498+
overriding function Project_Tree_Is_Aggregate (Self : Message_Handler)
499+
return Boolean is
500+
(Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind);
501+
504502
overriding procedure Reload_Project (Self : in out Message_Handler);
505503

504+
overriding function Get_Best_Context
505+
(Self : Message_Handler;
506+
URI : LSP.Structures.DocumentUri)
507+
return LSP.Ada_Context_Sets.Context_Access is
508+
(Self.Contexts.Get_Best_Context (URI));
509+
510+
overriding function Get_Node_At
511+
(Self : in out Message_Handler;
512+
Context : LSP.Ada_Contexts.Context;
513+
Value : LSP.Structures.TextDocumentPositionParams'Class)
514+
return Libadalang.Analysis.Ada_Node;
515+
506516
overriding function Imprecise_Resolve_Name
507517
(Self : in out Message_Handler;
508518
Context : LSP.Ada_Contexts.Context;

0 commit comments

Comments
 (0)