@@ -28,7 +28,6 @@ with GNAT.Strings;
2828with GNATCOLL.JSON ;
2929with GNATCOLL.Utils ; use GNATCOLL.Utils;
3030
31- with VSS.String_Vectors ;
3231with VSS.Strings ;
3332with VSS.Strings.Conversions ;
3433with VSS.Unicode ;
@@ -706,7 +705,7 @@ package body LSP.Ada_Handlers is
706705 workDoneProgress => LSP.Types.None));
707706 Response.result.capabilities.completionProvider :=
708707 (True,
709- (resolveProvider => LSP.Types.False ,
708+ (resolveProvider => LSP.Types.True ,
710709 triggerCharacters => (True, Empty_Vector & (+" ." ) & (+" (" )),
711710 allCommitCharacters => (Is_Set => False),
712711 workDoneProgress => LSP.Types.None));
@@ -776,6 +775,15 @@ package body LSP.Ada_Handlers is
776775 Self.Completion_Snippets_Enabled := True;
777776 end if ;
778777
778+ if Value.capabilities.textDocument.completion.completionItem.Is_Set
779+ and then Value.capabilities.textDocument.completion.
780+ completionItem.Value.resolveSupport.Is_Set
781+ then
782+ Self.Completion_Resolve_Properties :=
783+ Value.capabilities.textDocument.completion.
784+ completionItem.Value.resolveSupport.Value.properties;
785+ end if ;
786+
779787 if Value.capabilities.workspace.didChangeWatchedFiles
780788 .dynamicRegistration = True
781789 then
@@ -3875,8 +3883,23 @@ package body LSP.Ada_Handlers is
38753883
38763884 Response : LSP.Messages.Server_Responses.Completion_Response
38773885 (Is_Error => False);
3886+ Compute_Doc_And_Details : Boolean := True;
3887+
38783888 begin
38793889
3890+ -- If lazy computation for the 'detail' and 'documentation' fields is
3891+ -- supported by the client, set the Compute_Doc_And_Details flag to
3892+ -- False.
3893+
3894+ if Self.Completion_Resolve_Properties.Contains
3895+ (VSS.Strings.Conversions.To_Virtual_String (" detail" ))
3896+ and then
3897+ Self.Completion_Resolve_Properties.Contains
3898+ (VSS.Strings.Conversions.To_Virtual_String (" documentation" ))
3899+ then
3900+ Compute_Doc_And_Details := False;
3901+ end if ;
3902+
38803903 Document.Get_Completions_At
38813904 (Context => Context.all ,
38823905 Providers => Providers,
@@ -3888,13 +3911,75 @@ package body LSP.Ada_Handlers is
38883911 (Context => Context.all ,
38893912 Names => Names,
38903913 Named_Notation_Threshold => Self.Named_Notation_Threshold,
3914+ Compute_Doc_And_Details => Compute_Doc_And_Details,
38913915 Result => Response.result.items);
38923916
38933917 Response.result.isIncomplete := Names.Length >= Limit;
38943918
38953919 return Response;
38963920 end On_Completion_Request ;
38973921
3922+ -- ------------------------------------
3923+ -- On_CompletionItemResolve_Request --
3924+ -- ------------------------------------
3925+
3926+ overriding function On_CompletionItemResolve_Request
3927+ (Self : access Message_Handler;
3928+ Request : LSP.Messages.Server_Requests.CompletionItemResolve_Request)
3929+ return LSP.Messages.Server_Responses.CompletionItemResolve_Response
3930+ is
3931+ Item : LSP.Messages.CompletionItem :=
3932+ Request.params;
3933+ Response : LSP.Messages.Server_Responses.CompletionItemResolve_Response
3934+ (Is_Error => False);
3935+ C : constant Context_Access :=
3936+ Self.Contexts.Get_Best_Context (Item.data.Value.uri);
3937+ Node : Libadalang.Analysis.Ada_Node := Get_Node_At
3938+ (Self => C.all ,
3939+ Document => null ,
3940+ Position => LSP.Messages.TextDocumentPositionParams'
3941+ (textDocument => (uri => Item.data.Value.uri),
3942+ position => Item.data.Value.span.first));
3943+ begin
3944+ -- Retrieve the Basic_Decl from the completion item's SLOC
3945+ while not Node.Is_Null
3946+ and then Node.Kind not in Libadalang.Common.Ada_Basic_Decl
3947+ loop
3948+ Node := Node.Parent;
3949+ end loop ;
3950+
3951+ -- Compute the completion item's details
3952+ if not Node.Is_Null then
3953+ declare
3954+ BD : constant Libadalang.Analysis.Basic_Decl :=
3955+ Node.As_Basic_Decl;
3956+ begin
3957+ Item.detail :=
3958+ (True,
3959+ To_LSP_String (Compute_Completion_Detail (BD)));
3960+
3961+ -- Property_Errors can occur when calling
3962+ -- Get_Documentation on unsupported docstrings, so
3963+ -- add an exception handler to catch them and recover.
3964+
3965+ Item.documentation :=
3966+ (Is_Set => True,
3967+ Value => LSP.Messages.String_Or_MarkupContent'
3968+ (Is_String => True,
3969+ String => LSP.Lal_Utils.Compute_Completion_Doc (BD)));
3970+
3971+ exception
3972+ when E : Libadalang.Common.Property_Error =>
3973+ LSP.Common.Log (C.Trace, E);
3974+ Item.documentation := (others => <>);
3975+ end ;
3976+
3977+ Response.result := Item;
3978+ end if ;
3979+
3980+ return Response;
3981+ end On_CompletionItemResolve_Request ;
3982+
38983983 -- -------------------------
38993984 -- On_Formatting_Request --
39003985 -- -------------------------
0 commit comments