Skip to content

Commit cffa25f

Browse files
author
mergerepo
committed
Merge remote branch 'origin/master' into edge
(no-precommit-check no-tn-check)
2 parents 4c8c6b5 + bb7d6ec commit cffa25f

File tree

12 files changed

+530
-16
lines changed

12 files changed

+530
-16
lines changed

integration/vscode/Code Samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Here is some code samples for the Ada Language Server and the VS Code extension.
66
* [Docker](docker/) - example using Ada with Remote/Container VS Code feature
77
* [Gnatprove](gnatprove/) - SPARK/gnatprove integration example
88
* [Refactoring demos](refactoring_demos/) - sample code to check refactoring capabilities
9+
* [Custom worspace-specific environment](custom_env/) - example showing how to set workspace-specific environment variables

source/ada/lsp-ada_completions-generic_assoc.adb

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ package body LSP.Ada_Completions.Generic_Assoc is
4848
-- Empty if we already have a whitespace before a ","
4949

5050
Designators : Laltools.Common.Node_Vectors.Vector;
51+
-- Current list of designators
52+
53+
Unnamed_Params : Natural;
54+
-- The number of parameters without designators already present
5155

5256
Prefix : VSS.Strings.Virtual_String;
5357
-- The whole string before the snippet (including whitespaces)
@@ -133,6 +137,13 @@ package body LSP.Ada_Completions.Generic_Assoc is
133137
or else (Limit > 0
134138
and then (Snippet_Index = 1
135139
or else Snippet_Index >= Limit));
140+
141+
Nb_Params : Natural := Unnamed_Params;
142+
-- We already have Skip params
143+
144+
Total_Params : constant Natural :=
145+
Natural (Spec_Designators.Length);
146+
-- The maximum number of params
136147
begin
137148
if Match_Designators (Designators, Spec_Designators) then
138149

@@ -233,6 +244,9 @@ package body LSP.Ada_Completions.Generic_Assoc is
233244
end if;
234245
Snippet_Index := Snippet_Index - 1;
235246
end;
247+
248+
Nb_Params := Nb_Params + 1;
249+
exit when Nb_Params = Total_Params;
236250
end loop;
237251

238252
-- If the string is empty => nothing to do
@@ -303,7 +317,7 @@ package body LSP.Ada_Completions.Generic_Assoc is
303317
Prefix := Self.Document.Get_Text_At
304318
(Prefix_Span.first, Prefix_Span.last);
305319

306-
Designators := Get_Designators (Elem_Node);
320+
Designators := Get_Designators (Elem_Node, Sloc, Unnamed_Params);
307321

308322
if Token_Kind = Ada_Whitespace then
309323
Token_Kind := Kind (Data (Previous (Token, Exclude_Trivia => True)));
@@ -320,13 +334,18 @@ package body LSP.Ada_Completions.Generic_Assoc is
320334
(E => Elem_Node,
321335
Context => Self.Context)
322336
loop
323-
Generate_Snippets
324-
(Spec_Designators => Spec.Param_Vector,
325-
Param_Types => Spec.Param_Types,
326-
Decl => Spec.Decl,
327-
Title => Spec.Title,
328-
Snippet_Prefix => Spec.Prefix,
329-
Completion_Prefix => Completion_Prefix);
337+
-- Too many params to match Spec
338+
if Natural (Spec.Param_Vector.Length)
339+
> Natural (Designators.Length) + Unnamed_Params
340+
then
341+
Generate_Snippets
342+
(Spec_Designators => Spec.Param_Vector,
343+
Param_Types => Spec.Param_Types,
344+
Decl => Spec.Decl,
345+
Title => Spec.Title,
346+
Snippet_Prefix => Spec.Prefix,
347+
Completion_Prefix => Completion_Prefix);
348+
end if;
330349
end loop;
331350
end;
332351
end Propose_Completion;

source/ada/lsp-ada_completions-generic_assoc.ads

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ generic
3737
-- Return Null_Element if there is no such Element.
3838

3939
with function Get_Designators
40-
(E : Element) return Laltools.Common.Node_Vectors.Vector;
41-
-- Return the current list of Designators for E
40+
(E : Element;
41+
Sloc : Langkit_Support.Slocs.Source_Location;
42+
Unnamed_Params : out Natural)
43+
return Laltools.Common.Node_Vectors.Vector;
44+
-- Return the current list of Designators for E.
45+
-- Unnamed_Params correspond to the number of parameters without
46+
-- designators before Sloc.
4247

4348
with function Get_Spec_Designators
4449
(E : Element;

source/ada/lsp-ada_completions-parameters.adb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ package body LSP.Ada_Completions.Parameters is
5555
(N : Libadalang.Analysis.Ada_Node'Class)
5656
return Libadalang.Analysis.Aggregate;
5757
function Get_Designators
58-
(A : Libadalang.Analysis.Aggregate)
58+
(A : Libadalang.Analysis.Aggregate;
59+
Sloc : Langkit_Support.Slocs.Source_Location;
60+
Unnamed_Params : out Natural)
5961
return Laltools.Common.Node_Vectors.Vector;
6062
function Get_Spec_Aggregate_Designators
6163
(A : Libadalang.Analysis.Aggregate;
@@ -80,7 +82,9 @@ package body LSP.Ada_Completions.Parameters is
8082
(N : Libadalang.Analysis.Ada_Node'Class)
8183
return Libadalang.Analysis.Generic_Package_Instantiation;
8284
function Get_Designators
83-
(G : Libadalang.Analysis.Generic_Package_Instantiation)
85+
(G : Libadalang.Analysis.Generic_Package_Instantiation;
86+
Sloc : Langkit_Support.Slocs.Source_Location;
87+
Unnamed_Params : out Natural)
8488
return Laltools.Common.Node_Vectors.Vector;
8589
function Get_Decl_Designators
8690
(G : Libadalang.Analysis.Generic_Package_Instantiation;
@@ -185,11 +189,16 @@ package body LSP.Ada_Completions.Parameters is
185189
---------------------
186190

187191
function Get_Designators
188-
(A : Libadalang.Analysis.Aggregate)
192+
(A : Libadalang.Analysis.Aggregate;
193+
Sloc : Langkit_Support.Slocs.Source_Location;
194+
Unnamed_Params : out Natural)
189195
return Laltools.Common.Node_Vectors.Vector
190196
is
197+
pragma Unreferenced (Sloc);
191198
Res : Laltools.Common.Node_Vectors.Vector;
192199
begin
200+
Unnamed_Params := 0;
201+
193202
for Assoc of A.F_Assocs loop
194203
if Assoc.Kind in Ada_Aggregate_Assoc_Range then
195204
for Alt of Assoc.As_Aggregate_Assoc.F_Designators loop
@@ -501,16 +510,29 @@ package body LSP.Ada_Completions.Parameters is
501510
---------------------
502511

503512
function Get_Designators
504-
(G : Libadalang.Analysis.Generic_Package_Instantiation)
513+
(G : Libadalang.Analysis.Generic_Package_Instantiation;
514+
Sloc : Langkit_Support.Slocs.Source_Location;
515+
Unnamed_Params : out Natural)
505516
return Laltools.Common.Node_Vectors.Vector
506517
is
518+
use Langkit_Support.Slocs;
507519
Designator : Libadalang.Analysis.Ada_Node;
508520
Res : Laltools.Common.Node_Vectors.Vector;
509521
begin
522+
Unnamed_Params := 0;
523+
510524
for Assoc of G.F_Params loop
511525
Designator := Assoc.As_Param_Assoc.F_Designator;
512526
if Designator /= No_Ada_Node then
513527
Res.Append (Designator);
528+
else
529+
if Res.Is_Empty
530+
-- Count only the unnamed params at the start
531+
and then Start_Sloc (Assoc.Sloc_Range) < Sloc
532+
-- Prevent adding false parameter because of LAL recovery
533+
then
534+
Unnamed_Params := Unnamed_Params + 1;
535+
end if;
514536
end if;
515537
end loop;
516538

source/ada/lsp-lal_utils.adb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,18 @@ package body LSP.Lal_Utils is
420420
--------------------------
421421

422422
function Get_Call_Designators
423-
(Node : Libadalang.Analysis.Call_Expr)
423+
(Node : Libadalang.Analysis.Call_Expr;
424+
Sloc : Langkit_Support.Slocs.Source_Location;
425+
Unnamed_Params : out Natural)
424426
return Laltools.Common.Node_Vectors.Vector
425427
is
428+
use Langkit_Support.Slocs;
426429
Designator : Libadalang.Analysis.Ada_Node;
427430
Res : Laltools.Common.Node_Vectors.Vector :=
428431
Laltools.Common.Node_Vectors.Empty_Vector;
429432
begin
433+
Unnamed_Params := 0;
434+
430435
if Node = No_Call_Expr then
431436
return Res;
432437
end if;
@@ -442,6 +447,14 @@ package body LSP.Lal_Utils is
442447
Designator := Assoc.As_Param_Assoc.F_Designator;
443448
if Designator /= No_Ada_Node then
444449
Res.Append (Designator);
450+
else
451+
if Res.Is_Empty
452+
-- Count only the unnamed params at the start
453+
and then Start_Sloc (Assoc.Sloc_Range) < Sloc
454+
-- Prevent adding false parameter because of LAL recovery
455+
then
456+
Unnamed_Params := Unnamed_Params + 1;
457+
end if;
445458
end if;
446459
end loop;
447460
end if;

source/ada/lsp-lal_utils.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,13 @@ package LSP.Lal_Utils is
211211
-- recovery.
212212

213213
function Get_Call_Designators
214-
(Node : Libadalang.Analysis.Call_Expr)
214+
(Node : Libadalang.Analysis.Call_Expr;
215+
Sloc : Langkit_Support.Slocs.Source_Location;
216+
Unnamed_Params : out Natural)
215217
return Laltools.Common.Node_Vectors.Vector;
216218
-- Return the list of designator in the current call_expr
219+
-- Unnamed_Params correspond to the number of parameters without
220+
-- designators before Sloc.
217221

218222
procedure Get_Call_Expr_Name
219223
(Node : Libadalang.Analysis.Ada_Node'Class;
Lines changed: 22 additions & 0 deletions
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+
Lines changed: 13 additions & 0 deletions
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;
Lines changed: 3 additions & 0 deletions
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;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
with Bar; use Bar;
2+
3+
procedure Foo is
4+
M : My_Access := null;
5+
begin
6+
Hello (1);
7+
8+
Bar.Hello (1, B => 1);
9+
10+
M.Hello (1);
11+
end Foo;

0 commit comments

Comments
 (0)