Skip to content

Commit 39c8799

Browse files
committed
Introduce Output_Stream implemented over the GNATCOLL trace.
1 parent 706b9f1 commit 39c8799

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2022-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 VSS.Strings.Conversions;
19+
20+
package body LSP.GNATCOLL_Trace_Streams is
21+
22+
----------------
23+
-- Initialize --
24+
----------------
25+
26+
procedure Initialize
27+
(Self : in out Output_Text_Stream'Class;
28+
Trace : GNATCOLL.Traces.Trace_Handle) is
29+
begin
30+
Self.Trace := Trace;
31+
end Initialize;
32+
33+
--------------
34+
-- New_Line --
35+
--------------
36+
37+
overriding procedure New_Line
38+
(Self : in out Output_Text_Stream;
39+
Success : in out Boolean) is
40+
begin
41+
if Success then
42+
Self.Trace.Trace
43+
(VSS.Strings.Conversions.To_UTF_8_String (Self.Incomplete));
44+
Self.Incomplete.Clear;
45+
end if;
46+
end New_Line;
47+
48+
---------
49+
-- Put --
50+
---------
51+
52+
overriding procedure Put
53+
(Self : in out Output_Text_Stream;
54+
Item : VSS.Characters.Virtual_Character;
55+
Success : in out Boolean) is
56+
begin
57+
if Success then
58+
Self.Incomplete.Append (Item);
59+
end if;
60+
end Put;
61+
62+
---------
63+
-- Put --
64+
---------
65+
66+
overriding procedure Put
67+
(Self : in out Output_Text_Stream;
68+
Item : VSS.Strings.Virtual_String;
69+
Success : in out Boolean) is
70+
begin
71+
if Success then
72+
Self.Incomplete.Append (Item);
73+
end if;
74+
end Put;
75+
76+
--------------
77+
-- Put_Line --
78+
--------------
79+
80+
overriding procedure Put_Line
81+
(Self : in out Output_Text_Stream;
82+
Item : VSS.Strings.Virtual_String;
83+
Success : in out Boolean) is
84+
begin
85+
if Success then
86+
Self.Incomplete.Append (Item);
87+
Self.New_Line (Success);
88+
end if;
89+
end Put_Line;
90+
91+
end LSP.GNATCOLL_Trace_Streams;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2022-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 GNATCOLL.Traces;
19+
20+
with VSS.Characters;
21+
with VSS.Strings;
22+
with VSS.Text_Streams;
23+
24+
package LSP.GNATCOLL_Trace_Streams is
25+
26+
type Output_Text_Stream is limited
27+
new VSS.Text_Streams.Output_Text_Stream with private;
28+
-- Implementation of the text stream interface over GNATCOLL.Traces
29+
30+
procedure Initialize
31+
(Self : in out Output_Text_Stream'Class;
32+
Trace : GNATCOLL.Traces.Trace_Handle);
33+
-- Server_Trace - main trace for the LSP.
34+
35+
private
36+
37+
type Output_Text_Stream is limited
38+
new VSS.Text_Streams.Output_Text_Stream with
39+
record
40+
Incomplete : VSS.Strings.Virtual_String;
41+
Trace : GNATCOLL.Traces.Trace_Handle;
42+
end record;
43+
44+
overriding procedure Put
45+
(Self : in out Output_Text_Stream;
46+
Item : VSS.Characters.Virtual_Character;
47+
Success : in out Boolean);
48+
49+
overriding procedure Put
50+
(Self : in out Output_Text_Stream;
51+
Item : VSS.Strings.Virtual_String;
52+
Success : in out Boolean);
53+
54+
overriding procedure Put_Line
55+
(Self : in out Output_Text_Stream;
56+
Item : VSS.Strings.Virtual_String;
57+
Success : in out Boolean);
58+
59+
overriding procedure New_Line
60+
(Self : in out Output_Text_Stream;
61+
Success : in out Boolean);
62+
63+
overriding function Has_Error (Self : Output_Text_Stream) return Boolean is
64+
(False);
65+
66+
overriding function Error_Message
67+
(Self : Output_Text_Stream) return VSS.Strings.Virtual_String
68+
is (VSS.Strings.Empty_Virtual_String);
69+
70+
end LSP.GNATCOLL_Trace_Streams;

0 commit comments

Comments
 (0)