@@ -1246,8 +1246,7 @@ package body LSP.Ada_Handlers is
1246
1246
(Context : Context_Access;
1247
1247
Node : Libadalang.Analysis.Ada_Node;
1248
1248
Result : out LSP.Messages.CodeAction_Vector;
1249
- Found : in out Boolean;
1250
- Done : in out Boolean);
1249
+ Found : in out Boolean);
1251
1250
-- Look for a possible refactoring in given Node.
1252
1251
-- Return Found = True if some refactoring is possible. Populate
1253
1252
-- Result with Code_Actions in this case. Return Done = True if futher
@@ -1257,14 +1256,6 @@ package body LSP.Ada_Handlers is
1257
1256
(Result : in out LSP.Messages.CodeAction_Vector);
1258
1257
-- Append project status code action if needed
1259
1258
1260
- Found_Named_Parameters : Boolean := False;
1261
- -- We propose only one choice of Named_Parameters refactoring per
1262
- -- request. So, if a user clicks on `1` in `A (B (1))` we propose the
1263
- -- refactoring for B (1), but not for A (...) call. We consider this
1264
- -- as better user experience.
1265
- --
1266
- -- This boolean filter to detect such refactoring duplication.
1267
-
1268
1259
-- --------------------------------
1269
1260
-- Has_Assoc_Without_Designator --
1270
1261
-- --------------------------------
@@ -1401,12 +1392,8 @@ package body LSP.Ada_Handlers is
1401
1392
(Context : Context_Access;
1402
1393
Node : Libadalang.Analysis.Ada_Node;
1403
1394
Result : out LSP.Messages.CodeAction_Vector;
1404
- Found : in out Boolean;
1405
- Done : in out Boolean)
1395
+ Found : in out Boolean)
1406
1396
is
1407
- procedure Append_Command (Node : Libadalang.Analysis.Ada_Node);
1408
- -- Contruct a command and append it to Result
1409
-
1410
1397
procedure Change_Parameters_Type_Code_Action ;
1411
1398
-- Checks if the Change Parameters Type refactoring tool is avaiable,
1412
1399
-- and if so, appends a Code Action with its Command.
@@ -1423,50 +1410,14 @@ package body LSP.Ada_Handlers is
1423
1410
-- Checks if the Introduce Parameter refactoring tool is available,
1424
1411
-- and if so, appends a Code Action with its Command.
1425
1412
1413
+ procedure Named_Parameters_Code_Action ;
1414
+ -- Checks if the Named Parameters refactoring is available, and if
1415
+ -- so, appends a Code Action with its Command.
1416
+
1426
1417
procedure Pull_Up_Declaration_Code_Action ;
1427
1418
-- Checks if the Pull Up Declaration refactoring tool is available,
1428
1419
-- and if so, appends a Code Action with its Command.
1429
1420
1430
- -- ------------------
1431
- -- Append_Command --
1432
- -- ------------------
1433
-
1434
- procedure Append_Command (Node : Libadalang.Analysis.Ada_Node) is
1435
- Command : LSP.Ada_Handlers.Named_Parameters_Commands.Command;
1436
- Pointer : LSP.Commands.Command_Pointer;
1437
- Item : LSP.Messages.CodeAction;
1438
- Where : constant LSP.Messages.Location :=
1439
- LSP.Lal_Utils.Get_Node_Location (Node);
1440
- begin
1441
- if Found_Named_Parameters then
1442
- return ;
1443
- end if ;
1444
-
1445
- Command.Initialize
1446
- (Context => Context.all ,
1447
- Where => ((uri => Where.uri), Where.span.first));
1448
-
1449
- Pointer.Set (Command);
1450
-
1451
- Item :=
1452
- (title => " Name parameters in the call" ,
1453
- kind => (Is_Set => True,
1454
- Value => LSP.Messages.RefactorRewrite),
1455
- diagnostics => (Is_Set => False),
1456
- disabled => (Is_Set => False),
1457
- edit => (Is_Set => False),
1458
- isPreferred => (Is_Set => False),
1459
- command => (Is_Set => True,
1460
- Value =>
1461
- (Is_Unknown => False,
1462
- title => <>,
1463
- Custom => Pointer)));
1464
-
1465
- Result.Append (Item);
1466
- Found := True;
1467
- Found_Named_Parameters := True;
1468
- end Append_Command ;
1469
-
1470
1421
-- --------------------------------------
1471
1422
-- Change_Parameters_Type_Code_Action --
1472
1423
-- --------------------------------------
@@ -1500,6 +1451,8 @@ package body LSP.Ada_Handlers is
1500
1451
span => Params.span,
1501
1452
alsKind => LSP.Messages.Empty_Set),
1502
1453
Syntax_Rules => Syntax_Rules);
1454
+
1455
+ Found := True;
1503
1456
end if ;
1504
1457
end Change_Parameters_Type_Code_Action ;
1505
1458
@@ -1533,6 +1486,8 @@ package body LSP.Ada_Handlers is
1533
1486
(uri => Params.textDocument.uri,
1534
1487
span => Params.span,
1535
1488
alsKind => LSP.Messages.Empty_Set));
1489
+
1490
+ Found := True;
1536
1491
end if ;
1537
1492
end Change_Parameters_Default_Value_Code_Action ;
1538
1493
@@ -1591,7 +1546,6 @@ package body LSP.Ada_Handlers is
1591
1546
end if ;
1592
1547
1593
1548
Found := True;
1594
- Done := True;
1595
1549
end if ;
1596
1550
end if ;
1597
1551
end Extract_Subprogram_Code_Action ;
@@ -1625,9 +1579,104 @@ package body LSP.Ada_Handlers is
1625
1579
(uri => Params.textDocument.uri,
1626
1580
span => Params.span,
1627
1581
alsKind => LSP.Messages.Empty_Set));
1582
+
1583
+ Found := True;
1628
1584
end if ;
1629
1585
end Introduce_Parameter_Code_Action ;
1630
1586
1587
+ -- --------------------------------
1588
+ -- Named_Parameters_Code_Action --
1589
+ -- --------------------------------
1590
+
1591
+ procedure Named_Parameters_Code_Action is
1592
+ Aux_Node : Libadalang.Analysis.Ada_Node := Node;
1593
+ Done : Boolean := False;
1594
+ -- We propose only one choice of Named_Parameters refactoring per
1595
+ -- request. So, if a user clicks on `1` in `A (B (1))` we propose
1596
+ -- the refactoring for B (1), but not for A (...) call. We
1597
+ -- consider this as better user experience.
1598
+ --
1599
+ -- This boolean filter to detect such refactoring duplication.
1600
+
1601
+ procedure Append_Command (Node : Libadalang.Analysis.Ada_Node);
1602
+ -- Contruct a command and append it to Result
1603
+
1604
+ -- ------------------
1605
+ -- Append_Command --
1606
+ -- ------------------
1607
+
1608
+ procedure Append_Command (Node : Libadalang.Analysis.Ada_Node) is
1609
+ Command : LSP.Ada_Handlers.Named_Parameters_Commands.Command;
1610
+ Pointer : LSP.Commands.Command_Pointer;
1611
+ Item : LSP.Messages.CodeAction;
1612
+ Where : constant LSP.Messages.Location :=
1613
+ LSP.Lal_Utils.Get_Node_Location (Node);
1614
+
1615
+ begin
1616
+ Command.Initialize
1617
+ (Context => Context.all ,
1618
+ Where => ((uri => Where.uri), Where.span.first));
1619
+
1620
+ Pointer.Set (Command);
1621
+
1622
+ Item :=
1623
+ (title => " Name parameters in the call" ,
1624
+ kind => (Is_Set => True,
1625
+ Value => LSP.Messages.RefactorRewrite),
1626
+ diagnostics => (Is_Set => False),
1627
+ disabled => (Is_Set => False),
1628
+ edit => (Is_Set => False),
1629
+ isPreferred => (Is_Set => False),
1630
+ command => (Is_Set => True,
1631
+ Value =>
1632
+ (Is_Unknown => False,
1633
+ title => <>,
1634
+ Custom => Pointer)));
1635
+
1636
+ Result.Append (Item);
1637
+
1638
+ Done := True;
1639
+ Found := True;
1640
+ end Append_Command ;
1641
+
1642
+ begin
1643
+ while not Done and then not Aux_Node.Is_Null loop
1644
+ case Aux_Node.Kind is
1645
+ when Libadalang.Common.Ada_Stmt
1646
+ | Libadalang.Common.Ada_Basic_Decl =>
1647
+
1648
+ Done := True;
1649
+
1650
+ when Libadalang.Common.Ada_Basic_Assoc_List =>
1651
+ if Has_Assoc_Without_Designator
1652
+ (Aux_Node.As_Basic_Assoc_List)
1653
+ then
1654
+ Append_Command (Aux_Node);
1655
+ end if ;
1656
+
1657
+ when Libadalang.Common.Ada_Call_Expr =>
1658
+ declare
1659
+ List : constant Libadalang.Analysis.Ada_Node :=
1660
+ Aux_Node.As_Call_Expr.F_Suffix;
1661
+
1662
+ begin
1663
+ if not List.Is_Null
1664
+ and then List.Kind in
1665
+ Libadalang.Common.Ada_Basic_Assoc_List
1666
+ and then Has_Assoc_Without_Designator
1667
+ (List.As_Basic_Assoc_List)
1668
+ then
1669
+ Append_Command (List);
1670
+ end if ;
1671
+ end ;
1672
+ when others =>
1673
+ null ;
1674
+ end case ;
1675
+
1676
+ Aux_Node := Aux_Node.Parent;
1677
+ end loop ;
1678
+ end Named_Parameters_Code_Action ;
1679
+
1631
1680
-- -----------------------------------
1632
1681
-- Pull_Up_Declaration_Code_Action --
1633
1682
-- -----------------------------------
@@ -1664,39 +1713,15 @@ package body LSP.Ada_Handlers is
1664
1713
alsKind => Empty_Set));
1665
1714
1666
1715
Found := True;
1667
- Done := True;
1668
1716
end if ;
1669
1717
end Pull_Up_Declaration_Code_Action ;
1670
1718
1671
1719
Kind : constant Libadalang.Common.Ada_Node_Kind_Type := Node.Kind;
1672
1720
1673
1721
begin
1674
- case Kind is
1675
- when Libadalang.Common.Ada_Stmt
1676
- | Libadalang.Common.Ada_Basic_Decl =>
1677
-
1678
- Done := True;
1679
-
1680
- when Libadalang.Common.Ada_Basic_Assoc_List =>
1681
- if Has_Assoc_Without_Designator (Node.As_Basic_Assoc_List) then
1682
- Append_Command (Node);
1683
- end if ;
1684
-
1685
- when Libadalang.Common.Ada_Call_Expr =>
1686
- declare
1687
- List : constant Libadalang.Analysis.Ada_Node :=
1688
- Node.As_Call_Expr.F_Suffix;
1689
- begin
1690
- if not List.Is_Null
1691
- and then List.Kind in
1692
- Libadalang.Common.Ada_Basic_Assoc_List
1693
- and then Has_Assoc_Without_Designator
1694
- (List.As_Basic_Assoc_List)
1695
- then
1696
- Append_Command (List);
1697
- end if ;
1698
- end ;
1722
+ Named_Parameters_Code_Action;
1699
1723
1724
+ case Kind is
1700
1725
when Libadalang.Common.Ada_Identifier =>
1701
1726
declare
1702
1727
Name : constant Libadalang.Analysis.Name
@@ -1837,7 +1862,6 @@ package body LSP.Ada_Handlers is
1837
1862
Requires_Full_Specification);
1838
1863
1839
1864
Found := True;
1840
- Done := True;
1841
1865
end if ;
1842
1866
end ;
1843
1867
end if ;
@@ -1878,7 +1902,6 @@ package body LSP.Ada_Handlers is
1878
1902
Parameters_Indices => Parameter_Indices_Range);
1879
1903
1880
1904
Found := True;
1881
- Done := True;
1882
1905
end if ;
1883
1906
end ;
1884
1907
@@ -1909,7 +1932,6 @@ package body LSP.Ada_Handlers is
1909
1932
end loop ;
1910
1933
1911
1934
Found := True;
1912
- Done := True;
1913
1935
end if ;
1914
1936
end ;
1915
1937
@@ -1938,7 +1960,6 @@ package body LSP.Ada_Handlers is
1938
1960
end loop ;
1939
1961
1940
1962
Found := True;
1941
- Done := True;
1942
1963
end if ;
1943
1964
end ;
1944
1965
@@ -1961,7 +1982,6 @@ package body LSP.Ada_Handlers is
1961
1982
Target_Separate => Target_Separate);
1962
1983
1963
1984
Found := True;
1964
- Done := True;
1965
1985
end if ;
1966
1986
end ;
1967
1987
end Analyse_Node ;
@@ -1976,14 +1996,10 @@ package body LSP.Ada_Handlers is
1976
1996
Result : out LSP.Messages.CodeAction_Vector;
1977
1997
Found : in out Boolean)
1978
1998
is
1979
- Done : Boolean := False; -- True when futher analysis has no sense
1980
- Node : Libadalang.Analysis.Ada_Node :=
1999
+ Node : constant Libadalang.Analysis.Ada_Node :=
1981
2000
Document.Get_Node_At (Context.all , Params.span.first);
1982
2001
begin
1983
- while not Done and then not Node.Is_Null loop
1984
- Analyse_Node (Context, Node, Result, Found, Done);
1985
- Node := Node.Parent;
1986
- end loop ;
2002
+ Analyse_Node (Context, Node, Result, Found);
1987
2003
end Analyse_In_Context ;
1988
2004
1989
2005
-- -------------------------
0 commit comments