Skip to content

Commit 6ef4148

Browse files
committed
Move File_Span_Sets to a dedicated file
Refs #1141
1 parent a5e57f0 commit 6ef4148

9 files changed

+66
-62
lines changed

source/ada/lsp-ada_handlers-call_hierarchy.adb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with Laltools.Common;
2323
with Laltools.Call_Hierarchy;
2424

2525
with LSP.GNATCOLL_Tracers.Handle;
26+
with LSP.Ada_Handlers.Locations;
2627
with LSP.Utils;
2728

2829
package body LSP.Ada_Handlers.Call_Hierarchy is
@@ -69,7 +70,7 @@ package body LSP.Ada_Handlers.Call_Hierarchy is
6970
procedure Find_Incoming_Calls
7071
(Self : in out Message_Handler;
7172
Response : in out LSP.Structures.CallHierarchyIncomingCall_Vector;
72-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
73+
Filter : in out LSP.Locations.File_Span_Sets.Set;
7374
Context : LSP.Ada_Contexts.Context;
7475
Definition : Libadalang.Analysis.Defining_Name)
7576
is
@@ -206,7 +207,7 @@ package body LSP.Ada_Handlers.Call_Hierarchy is
206207
procedure Find_Outgoing_Calls
207208
(Self : in out Message_Handler;
208209
Response : in out LSP.Structures.CallHierarchyOutgoingCall_Vector;
209-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
210+
Filter : in out LSP.Locations.File_Span_Sets.Set;
210211
Definition : Libadalang.Analysis.Defining_Name)
211212
is
212213
use Laltools.Common.References_By_Subprogram;

source/ada/lsp-ada_handlers-call_hierarchy.ads

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
with Libadalang.Analysis;
1919

2020
with LSP.Ada_Contexts;
21-
with LSP.Ada_Handlers.Locations;
21+
with LSP.Locations;
2222

2323
package LSP.Ada_Handlers.Call_Hierarchy is
2424

2525
procedure Find_Incoming_Calls
2626
(Self : in out Message_Handler;
2727
Response : in out LSP.Structures.CallHierarchyIncomingCall_Vector;
28-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
28+
Filter : in out LSP.Locations.File_Span_Sets.Set;
2929
Context : LSP.Ada_Contexts.Context;
3030
Definition : Libadalang.Analysis.Defining_Name)
3131
with Pre => Definition.P_Basic_Decl.P_Is_Subprogram;
@@ -36,7 +36,7 @@ package LSP.Ada_Handlers.Call_Hierarchy is
3636
procedure Find_Outgoing_Calls
3737
(Self : in out Message_Handler;
3838
Response : in out LSP.Structures.CallHierarchyOutgoingCall_Vector;
39-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
39+
Filter : in out LSP.Locations.File_Span_Sets.Set;
4040
Definition : Libadalang.Analysis.Defining_Name)
4141
with Pre => Definition.P_Basic_Decl.P_Is_Subprogram;
4242
-- Return the list of all the calls made in the subprogram pointed at by

source/ada/lsp-ada_handlers-locations.adb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ package body LSP.Ada_Handlers.Locations is
3838
procedure Append_Location
3939
(Self : in out Message_Handler;
4040
Result : in out LSP.Structures.Location_Vector;
41-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
41+
Filter : in out LSP.Locations.File_Span_Sets.Set;
4242
Node : Libadalang.Analysis.Ada_Node'Class;
4343
Kinds : LSP.Structures.AlsReferenceKind_Set := LSP.Constants.Empty) is
4444
begin
@@ -132,17 +132,6 @@ package body LSP.Ada_Handlers.Locations is
132132
end;
133133
end Get_Node_At;
134134

135-
----------
136-
-- Hash --
137-
----------
138-
139-
function Hash
140-
(Value : LSP.Structures.Location) return Ada.Containers.Hash_Type is
141-
use type Ada.Containers.Hash_Type;
142-
begin
143-
return Value.uri.Get_Hash + LSP.Utils.Hash (Value.a_range);
144-
end Hash;
145-
146135
----------
147136
-- Sort --
148137
----------

source/ada/lsp-ada_handlers-locations.ads

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,10 @@ with Libadalang.Common;
2626

2727
with LSP.Ada_Contexts;
2828
with LSP.Constants;
29+
with LSP.Locations;
2930

3031
package LSP.Ada_Handlers.Locations is
3132

32-
function Hash
33-
(Value : LSP.Structures.Location) return Ada.Containers.Hash_Type;
34-
35-
package File_Span_Sets is new Ada.Containers.Hashed_Sets
36-
(Element_Type => LSP.Structures.Location,
37-
Hash => Hash,
38-
Equivalent_Elements => LSP.Structures."=",
39-
"=" => LSP.Structures."=");
40-
4133
function To_LSP_Location
4234
(Self : in out Message_Handler'Class;
4335
Node : Libadalang.Analysis.Ada_Node'Class;
@@ -66,7 +58,7 @@ package LSP.Ada_Handlers.Locations is
6658
procedure Append_Location
6759
(Self : in out Message_Handler;
6860
Result : in out LSP.Structures.Location_Vector;
69-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
61+
Filter : in out LSP.Locations.File_Span_Sets.Set;
7062
Node : Libadalang.Analysis.Ada_Node'Class;
7163
Kinds : LSP.Structures.AlsReferenceKind_Set := LSP.Constants.Empty);
7264
-- Append given Node location to the Result.

source/ada/lsp-ada_handlers-renaming.adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ with LAL_Refactor.Safe_Rename;
2828

2929
with LSP.Ada_Contexts;
3030
with LSP.Ada_Handlers.Locations;
31-
with LSP.Utils;
31+
with LSP.Locations;
3232

3333
package body LSP.Ada_Handlers.Renaming is
3434

@@ -53,14 +53,14 @@ package body LSP.Ada_Handlers.Renaming is
5353
Result := @ + Ada.Containers.Hash_Type'Mod
5454
(Item.TextEdit.newText.Hash);
5555

56-
Result := @ + LSP.Utils.Hash (Item.TextEdit.a_range);
56+
Result := @ + LSP.Locations.Hash (Item.TextEdit.a_range);
5757

5858
when False =>
5959
Result := @ + Ada.Containers.Hash_Type'Mod
6060
(Item.AnnotatedTextEdit.newText.Hash);
6161

6262
Result := @ +
63-
LSP.Utils.Hash (Item.AnnotatedTextEdit.a_range);
63+
LSP.Locations.Hash (Item.AnnotatedTextEdit.a_range);
6464
end case;
6565
end loop;
6666

source/ada/lsp-ada_handlers.adb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ with LSP.Errors;
9494
with LSP.Formatters.Texts;
9595
with LSP.Generic_Cancel_Check;
9696
with LSP.GNATCOLL_Tracers.Handle;
97+
with LSP.Locations;
9798
with LSP.Predefined_Completion;
9899
with LSP.Search;
99100
with LSP.Servers;
@@ -156,7 +157,7 @@ package body LSP.Ada_Handlers is
156157
procedure Append_Location
157158
(Self : in out Message_Handler;
158159
Result : in out LSP.Structures.Location_Vector;
159-
Filter : in out LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
160+
Filter : in out LSP.Locations.File_Span_Sets.Set;
160161
Node : Libadalang.Analysis.Ada_Node'Class;
161162
Kinds : AlsReferenceKind_Array := LSP.Constants.Empty)
162163
renames LSP.Ada_Handlers.Locations.Append_Location;
@@ -1711,7 +1712,7 @@ package body LSP.Ada_Handlers is
17111712

17121713
Response : LSP.Structures.Declaration_Result (LSP.Structures.Variant_1);
17131714
Vector : LSP.Structures.Location_Vector renames Response.Variant_1;
1714-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
1715+
Filter : LSP.Locations.File_Span_Sets.Set;
17151716

17161717
Display_Method_Policy : constant
17171718
LSP.Enumerations.AlsDisplayMethodAncestryOnNavigationPolicy :=
@@ -1865,7 +1866,7 @@ package body LSP.Ada_Handlers is
18651866

18661867
Response : LSP.Structures.Definition_Result (LSP.Structures.Variant_1);
18671868
Vector : LSP.Structures.Location_Vector renames Response.Variant_1;
1868-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
1869+
Filter : LSP.Locations.File_Span_Sets.Set;
18691870

18701871
Imprecise : Boolean := False;
18711872

@@ -3013,7 +3014,7 @@ package body LSP.Ada_Handlers is
30133014
Response : LSP.Structures.Definition_Result (LSP.Structures.Variant_1);
30143015

30153016
Vector : LSP.Structures.Location_Vector renames Response.Variant_1;
3016-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
3017+
Filter : LSP.Locations.File_Span_Sets.Set;
30173018

30183019
Display_Method_Policy : constant
30193020
LSP.Enumerations.AlsDisplayMethodAncestryOnNavigationPolicy :=
@@ -3151,7 +3152,7 @@ package body LSP.Ada_Handlers is
31513152
(textDocument => (uri => Item.uri),
31523153
position => Item.selectionRange.start);
31533154

3154-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
3155+
Filter : LSP.Locations.File_Span_Sets.Set;
31553156

31563157
---------------------
31573158
-- Process_Context --
@@ -3500,7 +3501,7 @@ package body LSP.Ada_Handlers is
35003501
(textDocument => (uri => Item.uri),
35013502
position => Item.selectionRange.start);
35023503

3503-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
3504+
Filter : LSP.Locations.File_Span_Sets.Set;
35043505

35053506
---------------------
35063507
-- Process_Context --
@@ -3718,7 +3719,7 @@ package body LSP.Ada_Handlers is
37183719

37193720
Response : LSP.Structures.Location_Vector_Or_Null;
37203721
Imprecise : Boolean := False;
3721-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
3722+
Filter : LSP.Locations.File_Span_Sets.Set;
37223723

37233724
Additional_Kinds : AlsReferenceKind_Array :=
37243725
[others => False];
@@ -4419,7 +4420,7 @@ package body LSP.Ada_Handlers is
44194420

44204421
Response : LSP.Structures.Definition_Result (LSP.Structures.Variant_1);
44214422
Vector : LSP.Structures.Location_Vector renames Response.Variant_1;
4422-
Filter : LSP.Ada_Handlers.Locations.File_Span_Sets.Set;
4423+
Filter : LSP.Locations.File_Span_Sets.Set;
44234424
Imprecise : Boolean := False;
44244425

44254426
procedure Resolve_In_Context (C : LSP.Ada_Context_Sets.Context_Access);

source/ada/lsp-locations.ads

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2023, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
with Ada.Containers.Hashed_Sets;
19+
20+
with LSP.Structures;
21+
22+
package LSP.Locations is
23+
24+
use type Ada.Containers.Hash_Type;
25+
26+
Prime : constant := 271;
27+
28+
function Hash
29+
(Value : LSP.Structures.A_Range) return Ada.Containers.Hash_Type is
30+
(Prime * Ada.Containers.Hash_Type'Mod (Value.start.line)
31+
+ Ada.Containers.Hash_Type'Mod (Value.start.character)
32+
+ Prime * Ada.Containers.Hash_Type'Mod (Value.an_end.line)
33+
+ Ada.Containers.Hash_Type'Mod (Value.an_end.character));
34+
35+
function Hash
36+
(Value : LSP.Structures.Location) return Ada.Containers.Hash_Type is
37+
(Value.uri.Get_Hash + Hash (Value.a_range));
38+
39+
package File_Span_Sets is new Ada.Containers.Hashed_Sets
40+
(Element_Type => LSP.Structures.Location,
41+
Hash => Hash,
42+
Equivalent_Elements => LSP.Structures."=",
43+
"=" => LSP.Structures."=");
44+
45+
end LSP.Locations;

source/ada/lsp-utils.adb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -454,25 +454,6 @@ package body LSP.Utils is
454454
return Std = Unit;
455455
end Is_Synthetic;
456456

457-
----------
458-
-- Hash --
459-
----------
460-
461-
function Hash
462-
(Value : LSP.Structures.A_Range) return Ada.Containers.Hash_Type
463-
is
464-
use type Ada.Containers.Hash_Type;
465-
Prime : constant := 271;
466-
From : constant Ada.Containers.Hash_Type :=
467-
Prime * Ada.Containers.Hash_Type'Mod (Value.start.line)
468-
+ Ada.Containers.Hash_Type'Mod (Value.start.character);
469-
To : constant Ada.Containers.Hash_Type :=
470-
Prime * Ada.Containers.Hash_Type'Mod (Value.an_end.line)
471-
+ Ada.Containers.Hash_Type'Mod (Value.an_end.character);
472-
begin
473-
return From + To;
474-
end Hash;
475-
476457
-------------------------
477458
-- Node_Location_Image --
478459
-------------------------

source/ada/lsp-utils.ads

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
-- This package provides some utility subprograms.
1919

20-
with Ada.Containers;
21-
2220
with VSS.Strings;
2321

2422
with Libadalang.Analysis;
@@ -75,9 +73,6 @@ package LSP.Utils is
7573
-- to convert LAL's Source_Location_Range to LSP's Range. Consider to
7674
-- use Document.To_LSP_Range instead, or add necessary wrapper.
7775

78-
function Hash
79-
(Value : LSP.Structures.A_Range) return Ada.Containers.Hash_Type;
80-
8176
function Is_Synthetic
8277
(Node : Libadalang.Analysis.Ada_Node'Class) return Boolean;
8378
-- Check if Node is in a synthetic file (like "__standard").

0 commit comments

Comments
 (0)