@@ -350,6 +350,140 @@ package body LSP.Lal_Utils is
350350 return LSP.Messages.A_Null;
351351 end Get_Decl_Kind ;
352352
353+ -- ----------------------
354+ -- Get_Call_Expr_Name --
355+ -- ----------------------
356+
357+ procedure Get_Call_Expr_Name
358+ (Node : Libadalang.Analysis.Ada_Node'Class;
359+ Active_Position : out LSP.Types.LSP_Number;
360+ Designator : out Libadalang.Analysis.Ada_Node;
361+ Name_Node : out Libadalang.Analysis.Name)
362+ is
363+ Cur_Node : Ada_Node := Node.As_Ada_Node;
364+ begin
365+ Active_Position := 0 ;
366+ Name_Node := Libadalang.Analysis.No_Name;
367+
368+ -- Find the first Call_Expr node in the parents
369+ while not Cur_Node.Is_Null loop
370+ exit when Cur_Node.Kind in Ada_Call_Expr_Range;
371+
372+ Cur_Node := Cur_Node.Parent;
373+ end loop ;
374+
375+ if Cur_Node.Is_Null then
376+ return ;
377+ end if ;
378+
379+ declare
380+ Call_Expr_Node : constant Libadalang.Analysis.Call_Expr :=
381+ Cur_Node.As_Call_Expr;
382+ Suffix_Node : constant Libadalang.Analysis.Ada_Node'Class :=
383+ Call_Expr_Node.F_Suffix;
384+ Node_Parents : constant Libadalang.Analysis.Ada_Node_Array :=
385+ Node.Parents;
386+ begin
387+ Name_Node := Call_Expr_Node.F_Name;
388+
389+ if Suffix_Node = Libadalang.Analysis.No_Ada_Node then
390+ return ;
391+ end if ;
392+
393+ -- Find the position in the Assoc_List
394+ if Suffix_Node.Kind in Ada_Assoc_List_Range then
395+ for Assoc of Suffix_Node.As_Assoc_List loop
396+ Designator := Assoc.As_Param_Assoc.F_Designator;
397+ for Parent of Node_Parents loop
398+ exit when Assoc = Parent;
399+ end loop ;
400+ Active_Position := Active_Position + 1 ;
401+ end loop ;
402+ end if ;
403+ -- The active position index starts at 0
404+ Active_Position := Active_Position - 1 ;
405+ end ;
406+ end Get_Call_Expr_Name ;
407+
408+ -- ------------------
409+ -- Get_Parameters --
410+ -- ------------------
411+
412+ procedure Get_Parameters
413+ (Node : Libadalang.Analysis.Basic_Decl;
414+ Parameters : in out LSP.Messages.ParameterInformation_Vector)
415+ is
416+ Spec : constant Libadalang.Analysis.Base_Subp_Spec :=
417+ Node.P_Subp_Spec_Or_Null;
418+ begin
419+ if Spec = Libadalang.Analysis.No_Base_Subp_Spec then
420+ return ;
421+ end if ;
422+
423+ for Param of Spec.P_Params loop
424+ for Id of Param.F_Ids loop
425+ declare
426+ P : constant LSP.Messages.ParameterInformation :=
427+ (label =>
428+ (Is_String => True,
429+ String => To_LSP_String (Id.Text)),
430+ documentation =>
431+ (Is_Set => False)
432+ );
433+ begin
434+ Parameters.Append (P);
435+ end ;
436+ end loop ;
437+ end loop ;
438+ end Get_Parameters ;
439+
440+ -- ------------------------
441+ -- Get_Active_Parameter --
442+ -- ------------------------
443+
444+ function Get_Active_Parameter
445+ (Node : Libadalang.Analysis.Basic_Decl;
446+ Designator : Libadalang.Analysis.Ada_Node;
447+ Position : LSP.Types.LSP_Number)
448+ return LSP.Types.LSP_Number
449+ is
450+ Spec : constant Libadalang.Analysis.Base_Subp_Spec :=
451+ Node.P_Subp_Spec_Or_Null;
452+ Index : LSP.Types.LSP_Number := 0 ;
453+ begin
454+ if Spec = Libadalang.Analysis.No_Base_Subp_Spec then
455+ return -1 ;
456+
457+ elsif Designator = Libadalang.Analysis.No_Ada_Node then
458+ -- Check if the given position is a valid index for Node
459+ for Param of Spec.P_Params loop
460+ for Id of Param.F_Ids loop
461+ Index := Index + 1 ;
462+ end loop ;
463+ end loop ;
464+ if Position > Index - 1 then
465+ return -1 ;
466+ else
467+ return Position;
468+ end if ;
469+
470+ else
471+ -- If we have a designator then try to find the position of a
472+ -- parameter with the same name
473+ for Param of Spec.P_Params loop
474+ for Id of Param.F_Ids loop
475+ if Id.Text = Designator.Text then
476+ return Index;
477+ end if ;
478+ Index := Index + 1 ;
479+ end loop ;
480+ end loop ;
481+
482+ -- No matching designator
483+ return -1 ;
484+ end if ;
485+ end Get_Active_Parameter ;
486+
353487 -- ---------------------
354488 -- Get_Node_Location --
355489 -- ---------------------
0 commit comments