Skip to content

Commit 97a5b47

Browse files
committed
Add some client side message codecs
1 parent 439b088 commit 97a5b47

7 files changed

+820
-1
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018, 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.Strings.UTF_Encoding;
19+
20+
with LSP.JSON_Streams;
21+
with LSP.Types;
22+
23+
package body LSP.Generic_Notifications is
24+
25+
function "+" (Text : Ada.Strings.UTF_Encoding.UTF_8_String)
26+
return LSP.Types.LSP_String renames
27+
LSP.Types.To_LSP_String;
28+
29+
----------
30+
-- Read --
31+
----------
32+
33+
not overriding procedure Read
34+
(S : access Ada.Streams.Root_Stream_Type'Class; V : out Notification)
35+
is
36+
JS : LSP.JSON_Streams.JSON_Stream'Class renames
37+
LSP.JSON_Streams.JSON_Stream'Class (S.all);
38+
begin
39+
JS.Start_Object;
40+
Read_Prefix (S, V);
41+
JS.Key (+"params");
42+
T'Read (S, V.params);
43+
JS.End_Object;
44+
end Read;
45+
46+
-----------
47+
-- Write --
48+
-----------
49+
50+
not overriding procedure Write
51+
(S : access Ada.Streams.Root_Stream_Type'Class; V : Notification)
52+
is
53+
JS : LSP.JSON_Streams.JSON_Stream'Class renames
54+
LSP.JSON_Streams.JSON_Stream'Class (S.all);
55+
begin
56+
JS.Start_Object;
57+
Write_Prefix (S, V);
58+
JS.Key (+"params");
59+
T'Write (S, V.params);
60+
JS.End_Object;
61+
end Write;
62+
63+
end LSP.Generic_Notifications;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018, 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.Streams;
19+
20+
generic
21+
type NotificationMessage is tagged private;
22+
type T is private;
23+
24+
with procedure Read_Prefix
25+
(S : access Ada.Streams.Root_Stream_Type'Class;
26+
V : out NotificationMessage'Class);
27+
28+
with procedure Write_Prefix
29+
(S : access Ada.Streams.Root_Stream_Type'Class;
30+
V : NotificationMessage'Class);
31+
32+
package LSP.Generic_Notifications is
33+
type Notification is new NotificationMessage with record
34+
params : T;
35+
end record;
36+
37+
not overriding procedure Read
38+
(S : access Ada.Streams.Root_Stream_Type'Class;
39+
V : out Notification);
40+
41+
not overriding procedure Write
42+
(S : access Ada.Streams.Root_Stream_Type'Class;
43+
V : Notification);
44+
45+
for Notification'Read use Read;
46+
for Notification'Write use Write;
47+
end LSP.Generic_Notifications;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018, 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.Strings.UTF_Encoding;
19+
20+
with LSP.JSON_Streams;
21+
with LSP.Types;
22+
23+
package body LSP.Generic_Requests is
24+
25+
function "+" (Text : Ada.Strings.UTF_Encoding.UTF_8_String)
26+
return LSP.Types.LSP_String renames
27+
LSP.Types.To_LSP_String;
28+
29+
-----------
30+
-- Write --
31+
-----------
32+
33+
not overriding procedure Write
34+
(S : access Ada.Streams.Root_Stream_Type'Class; V : Request)
35+
is
36+
JS : LSP.JSON_Streams.JSON_Stream'Class renames
37+
LSP.JSON_Streams.JSON_Stream'Class (S.all);
38+
begin
39+
JS.Start_Object;
40+
Write_Prefix (S, V);
41+
JS.Key (+"params");
42+
T'Write (S, V.params);
43+
JS.End_Object;
44+
end Write;
45+
46+
end LSP.Generic_Requests;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018, 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.Streams;
19+
20+
generic
21+
type RequestMessage is tagged private;
22+
type T is private;
23+
24+
with procedure Write_Prefix
25+
(S : access Ada.Streams.Root_Stream_Type'Class;
26+
V : RequestMessage'Class);
27+
28+
package LSP.Generic_Requests is
29+
type Request is new RequestMessage with record
30+
params : T;
31+
end record;
32+
33+
not overriding procedure Write
34+
(S : access Ada.Streams.Root_Stream_Type'Class;
35+
V : Request);
36+
37+
for Request'Write use Write;
38+
end LSP.Generic_Requests;

0 commit comments

Comments
 (0)