@@ -94,6 +94,7 @@ with LSP.Errors;
9494with LSP.Formatters.Texts ;
9595with LSP.Generic_Cancel_Check ;
9696with LSP.GNATCOLL_Tracers.Handle ;
97+ with LSP.Predefined_Completion ;
9798with LSP.Search ;
9899with LSP.Server_Notifications.DidChange ;
99100with 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
0 commit comments