@@ -94,6 +94,7 @@ with LSP.Errors;
94
94
with LSP.Formatters.Texts ;
95
95
with LSP.Generic_Cancel_Check ;
96
96
with LSP.GNATCOLL_Tracers.Handle ;
97
+ with LSP.Predefined_Completion ;
97
98
with LSP.Search ;
98
99
with LSP.Server_Notifications.DidChange ;
99
100
with LSP.Servers ;
@@ -3028,24 +3029,48 @@ package body LSP.Ada_Handlers is
3028
3029
3029
3030
Decl_Text : VSS.Strings.Virtual_String;
3030
3031
Qualifier_Text : VSS.Strings.Virtual_String;
3031
- Comments_Text : VSS.Strings.Virtual_String;
3032
+ Documentation_Text : VSS.Strings.Virtual_String;
3032
3033
Location_Text : VSS.Strings.Virtual_String;
3033
3034
Aspects_Text : VSS.Strings.Virtual_String;
3034
3035
3035
3036
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
3037
3039
return ;
3038
3040
end if ;
3039
3041
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 ;
3048
3072
3073
+ -- Return if no provider has been able to compute text for a tooltip.
3049
3074
if Decl_Text.Is_Empty then
3050
3075
return ;
3051
3076
end if ;
@@ -3075,28 +3100,30 @@ package body LSP.Ada_Handlers is
3075
3100
-- In addition, append the project's name if we are dealing with an
3076
3101
-- aggregate project.
3077
3102
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);
3079
3105
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 ;
3086
3112
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 ;
3091
3118
3092
3119
-- Append the comments associated with the basic declaration if any.
3093
3120
3094
- if not Comments_Text .Is_Empty then
3121
+ if not Documentation_Text .Is_Empty then
3095
3122
Response.Value.contents.MarkedString_Vector.Append
3096
3123
(LSP.Structures.MarkedString'
3097
3124
(Is_Virtual_String => False,
3098
3125
language => " plaintext" ,
3099
- value => Comments_Text ));
3126
+ value => Documentation_Text ));
3100
3127
end if ;
3101
3128
3102
3129
-- Append text of aspects
0 commit comments