Skip to content

Commit 9afdb54

Browse files
U429-030: Fix signatureHelp active parameter + Prefix notation
Handle prefix notation: differentiate between a paremeter prefix and a package prefix. Properly select the active parameter + handle designators. Add a test.
1 parent 67a98c5 commit 9afdb54

File tree

9 files changed

+3614
-7
lines changed

9 files changed

+3614
-7
lines changed

source/ada/lsp-ada_handlers.adb

+10-1
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,7 @@ package body LSP.Ada_Handlers is
27942794
return LSP.Messages.Server_Responses.SignatureHelp_Response
27952795
is
27962796
use Libadalang.Analysis;
2797+
use Langkit_Support.Slocs;
27972798
use LSP.Messages;
27982799

27992800
Value : LSP.Messages.SignatureHelpParams renames
@@ -2858,7 +2859,15 @@ package body LSP.Ada_Handlers is
28582859
Response.result := (others => <>);
28592860

28602861
-- Check if we are inside a function call and get the caller name
2861-
Get_Call_Expr_Name (Node, Active_Position, Designator, Name_Node);
2862+
Get_Call_Expr_Name
2863+
(Node => Node,
2864+
Cursor_Line =>
2865+
Langkit_Support.Slocs.Line_Number (Value.position.line + 1),
2866+
Cursor_Column =>
2867+
Langkit_Support.Slocs.Column_Number (Value.position.character) + 1,
2868+
Active_Position => Active_Position,
2869+
Designator => Designator,
2870+
Name_Node => Name_Node);
28622871

28632872
if Name_Node = Libadalang.Analysis.No_Name then
28642873
return Response;

source/ada/lsp-lal_utils.adb

+37-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ with Langkit_Support.Token_Data_Handlers;
3535

3636
with Pp.Actions;
3737

38-
with LSP.Types; use LSP.Types;
38+
with LSP.Types; use LSP.Types;
3939

4040
package body LSP.Lal_Utils is
4141

@@ -356,13 +356,36 @@ package body LSP.Lal_Utils is
356356

357357
procedure Get_Call_Expr_Name
358358
(Node : Libadalang.Analysis.Ada_Node'Class;
359+
Cursor_Line : Langkit_Support.Slocs.Line_Number;
360+
Cursor_Column : Langkit_Support.Slocs.Column_Number;
359361
Active_Position : out LSP.Types.LSP_Number;
360362
Designator : out Libadalang.Analysis.Ada_Node;
361363
Name_Node : out Libadalang.Analysis.Name)
362364
is
365+
use Langkit_Support.Slocs;
363366
Cur_Node : Ada_Node := Node.As_Ada_Node;
367+
368+
function Is_Active (N : Ada_Node) return Boolean;
369+
-- Check if N contains the cursor
370+
371+
---------------
372+
-- Is_Active --
373+
---------------
374+
375+
function Is_Active (N : Ada_Node) return Boolean
376+
is
377+
S : constant Langkit_Support.Slocs.Source_Location_Range :=
378+
N.Sloc_Range;
379+
begin
380+
return S.Start_Line <= Cursor_Line
381+
and then Cursor_Line <= S.End_Line
382+
and then S.Start_Column <= Cursor_Column
383+
and then Cursor_Column <= S.End_Column;
384+
end Is_Active;
385+
364386
begin
365387
Active_Position := 0;
388+
Designator := Libadalang.Analysis.No_Ada_Node;
366389
Name_Node := Libadalang.Analysis.No_Name;
367390

368391
if not Cur_Node.Is_Null
@@ -404,11 +427,21 @@ package body LSP.Lal_Utils is
404427
Cur_Node.As_Call_Expr;
405428
Suffix_Node : constant Libadalang.Analysis.Ada_Node'Class :=
406429
Call_Expr_Node.F_Suffix;
407-
Node_Parents : constant Libadalang.Analysis.Ada_Node_Array :=
408-
Node.Parents;
409430
begin
410431
Name_Node := Call_Expr_Node.F_Name;
411432

433+
if Name_Node.Kind in Ada_Dotted_Name_Range then
434+
declare
435+
Dot_Name : constant Dotted_Name := Name_Node.As_Dotted_Name;
436+
begin
437+
-- If the prefix is a parameter then increase the
438+
-- Active_Position by 1
439+
if Dot_Name.P_Is_Dot_Call (Imprecise_Fallback => True) then
440+
Active_Position := Active_Position + 1;
441+
end if;
442+
end;
443+
end if;
444+
412445
if Suffix_Node = Libadalang.Analysis.No_Ada_Node then
413446
return;
414447
end if;
@@ -417,10 +450,8 @@ package body LSP.Lal_Utils is
417450
if Suffix_Node.Kind in Ada_Assoc_List_Range then
418451
for Assoc of Suffix_Node.As_Assoc_List loop
419452
Designator := Assoc.As_Param_Assoc.F_Designator;
420-
for Parent of Node_Parents loop
421-
exit when Assoc = Parent;
422-
end loop;
423453
Active_Position := Active_Position + 1;
454+
exit when Is_Active (Assoc.As_Ada_Node);
424455
end loop;
425456
end if;
426457
-- The active position index starts at 0

source/ada/lsp-lal_utils.ads

+4
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,17 @@ package LSP.Lal_Utils is
135135

136136
procedure Get_Call_Expr_Name
137137
(Node : Libadalang.Analysis.Ada_Node'Class;
138+
Cursor_Line : Langkit_Support.Slocs.Line_Number;
139+
Cursor_Column : Langkit_Support.Slocs.Column_Number;
138140
Active_Position : out LSP.Types.LSP_Number;
139141
Designator : out Libadalang.Analysis.Ada_Node;
140142
Name_Node : out Libadalang.Analysis.Name);
141143
-- If Node is inside a Call_Expr returns the following:
142144
-- Active_Position: the index of the parameter in the Call_Expr
143145
-- Designator: the designator of the Active_Position
144146
-- Name_Node: the name of the Call_Expr
147+
-- Cursor_Line and Cursor_Column the position of the cursor when the
148+
-- request was triggered.
145149

146150
procedure Get_Parameters
147151
(Node : Libadalang.Analysis.Basic_Decl;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package body Bar is
2+
3+
-----------
4+
-- Hello --
5+
-----------
6+
7+
procedure Hello (A : Integer; B : Float) is
8+
begin
9+
null;
10+
end Hello;
11+
12+
-----------
13+
-- Hello --
14+
-----------
15+
16+
procedure Hello (M : access My_Type; A : Integer; B : Float) is
17+
begin
18+
null;
19+
end Hello;
20+
21+
end Bar;
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package Bar is
2+
3+
procedure Hello (A : Integer; B : Float);
4+
5+
type My_Type is tagged
6+
record
7+
B : Boolean;
8+
end record;
9+
type My_Access is access all My_Type;
10+
11+
procedure Hello (M : access My_Type; A : Integer; B : Float);
12+
13+
end Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Default is
2+
for Main use ("foo.adb");
3+
end Default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
with Bar; use Bar;
2+
3+
procedure Foo is
4+
M : My_Access := null;
5+
begin
6+
-- Hello (null, 2, 3);
7+
8+
-- Bar.Hello (A => 1, M => null, 3);
9+
10+
-- M.Hello (B => 3, A => 2);
11+
12+
end Foo;

0 commit comments

Comments
 (0)