Skip to content

Commit d34f141

Browse files
U805-023: Filter the signatures using the previous designators
Previously it was only using the current designator and the active position.
1 parent 2fc9fa8 commit d34f141

File tree

7 files changed

+945
-47
lines changed

7 files changed

+945
-47
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,7 @@ package body LSP.Ada_Handlers is
25082508
Document.Get_Source_Location (Value.position);
25092509

25102510
Name_Node : Libadalang.Analysis.Name;
2511+
Prev_Designators : Laltools.Common.Node_Vectors.Vector;
25112512
Designator : Libadalang.Analysis.Ada_Node;
25122513
Active_Position : LSP.Types.LSP_Number;
25132514
Active_Signature : LSP.Types.LSP_Number := 0;
@@ -2542,7 +2543,11 @@ package body LSP.Ada_Handlers is
25422543
procedure Add_Signature (Decl_Node : Libadalang.Analysis.Basic_Decl)
25432544
is
25442545
Param_Index : constant LSP.Types.LSP_Number :=
2545-
Get_Active_Parameter (Decl_Node, Designator, Active_Position);
2546+
Get_Active_Parameter
2547+
(Node => Decl_Node,
2548+
Designator => Designator,
2549+
Prev_Designators => Prev_Designators,
2550+
Position => Active_Position);
25462551
begin
25472552
if Param_Index = -1 then
25482553
return;
@@ -2659,11 +2664,12 @@ package body LSP.Ada_Handlers is
26592664

26602665
-- Check if we are inside a function call and get the caller name
26612666
Get_Call_Expr_Name
2662-
(Node => Node,
2663-
Cursor => Sloc,
2664-
Active_Position => Active_Position,
2665-
Designator => Designator,
2666-
Name_Node => Name_Node);
2667+
(Node => Node,
2668+
Cursor => Sloc,
2669+
Active_Position => Active_Position,
2670+
Designator => Designator,
2671+
Prev_Designators => Prev_Designators,
2672+
Name_Node => Name_Node);
26672673

26682674
if Name_Node = Libadalang.Analysis.No_Name then
26692675
return Response;
@@ -2675,10 +2681,9 @@ package body LSP.Ada_Handlers is
26752681
and then
26762682
(Value.context.Value.triggerKind /= TriggerCharacter
26772683
or else
2678-
-- Check if the trigger character is a backspace
2679-
((not Value.context.Value.triggerCharacter.Is_Set)
2680-
or else Value.context.Value.triggerCharacter.Value /=
2681-
(+(1 => Backspace))))
2684+
-- Adding a ',' will not add new results only filter the previous
2685+
(Value.context.Value.triggerCharacter.Is_Set
2686+
and then Value.context.Value.triggerCharacter.Value = (+",")))
26822687
then
26832688
-- At this point, we are filtering the previous signatures:
26842689
-- * Don't recompute the list of signature

source/ada/lsp-lal_utils.adb

Lines changed: 88 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,12 @@ package body LSP.Lal_Utils is
386386
------------------------
387387

388388
procedure Get_Call_Expr_Name
389-
(Node : Libadalang.Analysis.Ada_Node'Class;
390-
Cursor : Langkit_Support.Slocs.Source_Location;
391-
Active_Position : out LSP.Types.LSP_Number;
392-
Designator : out Libadalang.Analysis.Ada_Node;
393-
Name_Node : out Libadalang.Analysis.Name)
389+
(Node : Libadalang.Analysis.Ada_Node'Class;
390+
Cursor : Langkit_Support.Slocs.Source_Location;
391+
Active_Position : out LSP.Types.LSP_Number;
392+
Designator : out Libadalang.Analysis.Ada_Node;
393+
Prev_Designators : out Laltools.Common.Node_Vectors.Vector;
394+
Name_Node : out Libadalang.Analysis.Name)
394395
is
395396
use Langkit_Support.Slocs;
396397
Cur_Node : Ada_Node := Node.As_Ada_Node;
@@ -453,6 +454,7 @@ package body LSP.Lal_Utils is
453454
begin
454455
Active_Position := 0;
455456
Designator := Libadalang.Analysis.No_Ada_Node;
457+
Prev_Designators := Laltools.Common.Node_Vectors.Empty_Vector;
456458
Name_Node := Libadalang.Analysis.No_Name;
457459

458460
if not Cur_Node.Is_Null
@@ -519,6 +521,9 @@ package body LSP.Lal_Utils is
519521
Designator := Assoc.As_Param_Assoc.F_Designator;
520522
Active_Position := Active_Position + 1;
521523
exit when Cursor_In_Node (Assoc.As_Ada_Node);
524+
if Designator /= No_Ada_Node then
525+
Prev_Designators.Append (Designator);
526+
end if;
522527
end loop;
523528
end if;
524529

@@ -570,46 +575,101 @@ package body LSP.Lal_Utils is
570575
--------------------------
571576

572577
function Get_Active_Parameter
573-
(Node : Libadalang.Analysis.Basic_Decl;
574-
Designator : Libadalang.Analysis.Ada_Node;
575-
Position : LSP.Types.LSP_Number)
578+
(Node : Libadalang.Analysis.Basic_Decl;
579+
Designator : Libadalang.Analysis.Ada_Node;
580+
Prev_Designators : Laltools.Common.Node_Vectors.Vector;
581+
Position : LSP.Types.LSP_Number)
576582
return LSP.Types.LSP_Number
577583
is
578584
Spec : constant Libadalang.Analysis.Base_Subp_Spec :=
579585
Node.P_Subp_Spec_Or_Null;
580-
Index : LSP.Types.LSP_Number := 0;
581-
begin
582-
if Spec = Libadalang.Analysis.No_Base_Subp_Spec then
583-
return -1;
586+
Res : LSP.Types.LSP_Number := -1;
587+
588+
function Find_Designator
589+
(D : Libadalang.Analysis.Ada_Node;
590+
Params : Libadalang.Analysis.Param_Spec_Array)
591+
return LSP.Types.LSP_Number;
592+
593+
function Count_Parameters
594+
(Params : Libadalang.Analysis.Param_Spec_Array)
595+
return LSP.Types.LSP_Number;
584596

585-
elsif Designator = Libadalang.Analysis.No_Ada_Node then
586-
-- Check if the given position is a valid index for Node
587-
for Param of Spec.P_Params loop
597+
---------------------
598+
-- Find_Designator --
599+
---------------------
600+
601+
function Find_Designator
602+
(D : Libadalang.Analysis.Ada_Node;
603+
Params : Libadalang.Analysis.Param_Spec_Array)
604+
return LSP.Types.LSP_Number
605+
is
606+
Index : LSP.Types.LSP_Number := 0;
607+
begin
608+
for Param of Params loop
588609
for Id of Param.F_Ids loop
610+
if Id.Text = D.Text then
611+
return Index;
612+
end if;
589613
Index := Index + 1;
590614
end loop;
591615
end loop;
592-
if Position > Index - 1 then
593-
return -1;
594-
else
595-
return Position;
596-
end if;
597616

598-
else
599-
-- If we have a designator then try to find the position of a
600-
-- parameter with the same name
601-
for Param of Spec.P_Params loop
617+
return -1;
618+
end Find_Designator;
619+
620+
----------------------
621+
-- Count_Parameters --
622+
----------------------
623+
624+
function Count_Parameters
625+
(Params : Libadalang.Analysis.Param_Spec_Array)
626+
return LSP.Types.LSP_Number
627+
is
628+
Index : LSP.Types.LSP_Number := 0;
629+
begin
630+
for Param of Params loop
602631
for Id of Param.F_Ids loop
603-
if Id.Text = Designator.Text then
604-
return Index;
605-
end if;
606632
Index := Index + 1;
607633
end loop;
608634
end loop;
609635

610-
-- No matching designator
636+
return Index;
637+
end Count_Parameters;
638+
639+
begin
640+
if Spec = Libadalang.Analysis.No_Base_Subp_Spec then
611641
return -1;
612642
end if;
643+
644+
declare
645+
Params : constant Libadalang.Analysis.Param_Spec_Array :=
646+
Spec.P_Params;
647+
begin
648+
if Designator = Libadalang.Analysis.No_Ada_Node then
649+
-- Check if the given position is a valid index for Node
650+
651+
if Position >= Count_Parameters (Params) then
652+
return -1;
653+
else
654+
Res := Position;
655+
end if;
656+
657+
else
658+
-- If we have a designator then try to find the position of a
659+
-- parameter with the same name
660+
Res := Find_Designator (Designator, Params);
661+
662+
end if;
663+
664+
-- Invalidate the result if it doesn't match the previous designators
665+
for Prev_Designator of Prev_Designators loop
666+
if Find_Designator (Prev_Designator, Params) = -1 then
667+
return -1;
668+
end if;
669+
end loop;
670+
end;
671+
672+
return Res;
613673
end Get_Active_Parameter;
614674

615675
------------------

source/ada/lsp-lal_utils.ads

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,29 +197,33 @@ package LSP.Lal_Utils is
197197
-- variables.
198198

199199
procedure Get_Call_Expr_Name
200-
(Node : Libadalang.Analysis.Ada_Node'Class;
201-
Cursor : Langkit_Support.Slocs.Source_Location;
202-
Active_Position : out LSP.Types.LSP_Number;
203-
Designator : out Libadalang.Analysis.Ada_Node;
204-
Name_Node : out Libadalang.Analysis.Name);
200+
(Node : Libadalang.Analysis.Ada_Node'Class;
201+
Cursor : Langkit_Support.Slocs.Source_Location;
202+
Active_Position : out LSP.Types.LSP_Number;
203+
Designator : out Libadalang.Analysis.Ada_Node;
204+
Prev_Designators : out Laltools.Common.Node_Vectors.Vector;
205+
Name_Node : out Libadalang.Analysis.Name);
205206
-- If Node is inside a Call_Expr returns the following:
206207
-- Active_Position: the index of the parameter in the Call_Expr
207208
-- Designator: the designator of the Active_Position
209+
-- Prev_Designators: the designators found before the Active_Position
208210
-- Name_Node: the name of the Call_Expr
209-
-- Cursor: the position of the cursor when the request was triggered.
211+
-- Cursor: the position of the cursor when the request was triggered
210212

211213
procedure Get_Parameters
212214
(Node : Libadalang.Analysis.Basic_Decl;
213215
Parameters : in out LSP.Messages.ParameterInformation_Vector);
214216
-- Append all the parameters of Node inside Parameters
215217

216218
function Get_Active_Parameter
217-
(Node : Libadalang.Analysis.Basic_Decl;
218-
Designator : Libadalang.Analysis.Ada_Node;
219-
Position : LSP.Types.LSP_Number)
219+
(Node : Libadalang.Analysis.Basic_Decl;
220+
Designator : Libadalang.Analysis.Ada_Node;
221+
Prev_Designators : Laltools.Common.Node_Vectors.Vector;
222+
Position : LSP.Types.LSP_Number)
220223
return LSP.Types.LSP_Number;
221224
-- Return the position of Designator in the parameters of Node else -1
222225
-- If Designator is null try check if Position is a valid parameter index
226+
-- Verify that Node parameters matches all the previous designators.
223227

224228
function To_Call_Hierarchy_Item
225229
(Name : Libadalang.Analysis.Defining_Name)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
procedure Foo is
2+
3+
procedure Bar (I, J, K : Integer);
4+
procedure Bar (I, J : Integer; F : Float);
5+
procedure Bar (F, H : Float; I : Integer);
6+
procedure Bar (J : Integer; F : Float);
7+
8+
begin
9+
Bar (I => 1, J => 2
10+
end Foo;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Test is
2+
for Main use ("foo.adb");
3+
end Test;

0 commit comments

Comments
 (0)