Skip to content

Commit ebc8db7

Browse files
committed
Reuse Hash function.
1 parent 936dac6 commit ebc8db7

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2024, 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+
private with VSS.Strings.Hash;
19+
20+
package LSP.Structures.Hashes is
21+
22+
function Hash
23+
(Item : LSP.Structures.Integer_Or_Virtual_String)
24+
return Ada.Containers.Hash_Type;
25+
26+
private
27+
28+
function Hash
29+
(Item : LSP.Structures.Integer_Or_Virtual_String)
30+
return Ada.Containers.Hash_Type is
31+
(case Item.Is_Integer is
32+
when True => Ada.Containers.Hash_Type'Mod (Item.Integer),
33+
when False => VSS.Strings.Hash (Item.Virtual_String));
34+
35+
end LSP.Structures.Hashes;

source/server/lsp-known_requests.adb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2022-2023, AdaCore --
4+
-- Copyright (C) 2022-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -17,6 +17,9 @@
1717

1818
with Ada.Unchecked_Conversion;
1919

20+
with LSP.Server_Notifications;
21+
with LSP.Server_Requests;
22+
2023
package body LSP.Known_Requests is
2124

2225
type Request_Constant_Access is

source/server/lsp-known_requests.ads

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2022-2023, AdaCore --
4+
-- Copyright (C) 2022-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -15,16 +15,14 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with Ada.Containers.Hashed_Maps;
18+
private with Ada.Containers.Hashed_Maps;
1919

20-
with VSS.Strings.Hash;
21-
22-
with LSP.Server_Message_Visitors;
20+
private with LSP.Server_Message_Visitors;
2321
with LSP.Server_Messages;
24-
with LSP.Server_Notification_Receivers;
25-
with LSP.Server_Notifications;
26-
with LSP.Server_Requests;
27-
with LSP.Structures;
22+
private with LSP.Server_Notification_Receivers;
23+
limited private with LSP.Server_Notifications;
24+
limited private with LSP.Server_Requests;
25+
private with LSP.Structures.Hashes;
2826

2927
package LSP.Known_Requests is
3028

@@ -61,22 +59,13 @@ private
6159
(Self : in out Visitor;
6260
Value : LSP.Structures.CancelParams);
6361

64-
function Hash
65-
(Value : LSP.Structures.Integer_Or_Virtual_String)
66-
return Ada.Containers.Hash_Type is
67-
(case Value.Is_Integer is
68-
when True =>
69-
Ada.Containers.Hash_Type'Mod (Value.Integer),
70-
when False =>
71-
VSS.Strings.Hash (Value.Virtual_String));
72-
7362
type Request_Access is
7463
access all LSP.Server_Requests.Server_Request'Class;
7564

7665
package Request_Maps is new Ada.Containers.Hashed_Maps
7766
(Key_Type => LSP.Structures.Integer_Or_Virtual_String, -- id
7867
Element_Type => Request_Access,
79-
Hash => Hash,
68+
Hash => LSP.Structures.Hashes.Hash,
8069
Equivalent_Keys => LSP.Structures."=",
8170
"=" => "=");
8271

0 commit comments

Comments
 (0)