Skip to content

Commit 84a1069

Browse files
authored
Merge pull request AdaCore#34 from AdaCore/topic/client
Topic/client
2 parents 7e39925 + eb8db13 commit 84a1069

16 files changed

+1430
-307
lines changed

gnat/spawn_glib.gpr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ with "gtkada";
1919

2020
project Spawn_Glib is
2121

22-
type OS_API_Kind is ("Windows_NT", "Posix");
23-
OS_API : OS_API_Kind := external ("OS", "Posix");
22+
type OS_API_Kind is ("unix", "osx", "Windows_NT");
23+
OS_API : OS_API_Kind := external ("OS", "unix");
2424

2525
for Source_Dirs use ("../source/spawn");
2626
for Object_Dir use "../.obj/spawn";
@@ -31,7 +31,7 @@ project Spawn_Glib is
3131
"spawn-processes-monitor_loop.adb");
3232

3333
case OS_API is
34-
when "Posix" =>
34+
when "unix" | "osx" =>
3535
for Excluded_Source_Files use Common_Excluded &
3636
("spawn-windows_api.ads",
3737
"spawn-processes-windows.ads",
@@ -47,7 +47,7 @@ project Spawn_Glib is
4747

4848
package Naming is
4949
case OS_API is
50-
when "Posix" =>
50+
when "unix" | "osx" =>
5151
for Spec ("Spawn.Internal")
5252
use "spawn-internal__glib.ads";
5353
for Body ("Spawn.Internal")

source/ada/lsp-ada_handlers.ads

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
------------------------------------------------------------------------------
1717

1818
with LSP.Message_Handlers;
19+
with LSP.Notification_Handlers;
1920
with LSP.Messages;
2021
with LSP.Servers;
2122

@@ -27,15 +28,15 @@ package LSP.Ada_Handlers is
2728
(Server : access LSP.Servers.Server;
2829
Context : access LSP.Ada_Contexts.Context) is
2930
limited new LSP.Message_Handlers.Request_Handler
30-
and LSP.Message_Handlers.Notification_Handler with private;
31+
and LSP.Notification_Handlers.Notification_Handler with private;
3132

3233
private
3334

3435
type Message_Handler
3536
(Server : access LSP.Servers.Server;
3637
Context : access LSP.Ada_Contexts.Context)
3738
is limited new LSP.Message_Handlers.Request_Handler
38-
and LSP.Message_Handlers.Notification_Handler with record
39+
and LSP.Notification_Handlers.Notification_Handler with record
3940
null;
4041
end record;
4142

source/client/lsp-clients.adb

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,18 @@ package body LSP.Clients is
144144
Params => Params);
145145
end;
146146
else
147-
raise Constraint_Error with "Unknown request";
147+
declare
148+
Error : LSP.Messages.ResponseMessage :=
149+
(error =>
150+
(True,
151+
(code => LSP.Messages.MethodNotFound,
152+
message =>
153+
+("Unknown method:" & Value.Get ("method")),
154+
data => <>)),
155+
others => <>);
156+
begin
157+
Self.Send_Response (Id, Error);
158+
end;
148159
end if;
149160
else
150161
-- Response from server
@@ -175,7 +186,7 @@ package body LSP.Clients is
175186
Value.method := +Method;
176187
LSP.Messages.NotificationMessage'Class'Write (JS'Access, Value);
177188
JSON := GNATCOLL.JSON.Get (JS.Get_JSON_Document, 1);
178-
Self.Send_Request (JSON.Write);
189+
Self.Send_Message (JSON.Write);
179190
end Send_Notification;
180191

181192
------------------
@@ -201,7 +212,7 @@ package body LSP.Clients is
201212
Value.id := (True, Request);
202213
LSP.Messages.RequestMessage'Class'Write (JS'Access, Value);
203214
JSON := GNATCOLL.JSON.Get (JS.Get_JSON_Document, 1);
204-
Self.Send_Request (JSON.Write);
215+
Self.Send_Message (JSON.Write);
205216
end Send_Request;
206217

207218
-------------------------
@@ -239,6 +250,25 @@ package body LSP.Clients is
239250
Self.Send_Request (Request, "shutdown", null, Message);
240251
end Shutdown_Request;
241252

253+
-------------------
254+
-- Send_Response --
255+
-------------------
256+
257+
procedure Send_Response
258+
(Self : in out Client'Class;
259+
Request : LSP.Types.LSP_Number_Or_String;
260+
Value : in out LSP.Messages.ResponseMessage'Class)
261+
is
262+
JS : aliased LSP.JSON_Streams.JSON_Stream;
263+
JSON : GNATCOLL.JSON.JSON_Value;
264+
begin
265+
Value.jsonrpc := +"2.0";
266+
Value.id := Request;
267+
LSP.Messages.ResponseMessage'Class'Write (JS'Access, Value);
268+
JSON := GNATCOLL.JSON.Get (JS.Get_JSON_Document, 1);
269+
Self.Send_Message (JSON.Write);
270+
end Send_Response;
271+
242272
---------------------------------------
243273
-- Text_Document_Code_Action_Request --
244274
---------------------------------------
@@ -426,18 +456,11 @@ package body LSP.Clients is
426456
Request : LSP.Types.LSP_Number_Or_String;
427457
Applied : Boolean)
428458
is
429-
Message : constant LSP.Messages.ApplyWorkspaceEdit_Response :=
430-
(result => (applied => Applied),
431-
jsonrpc => +"2.0",
432-
id => Request,
433-
error => (Is_Set => False));
434-
435-
JS : aliased LSP.JSON_Streams.JSON_Stream;
436-
JSON : GNATCOLL.JSON.JSON_Value;
459+
Message : LSP.Messages.ApplyWorkspaceEdit_Response :=
460+
(result => (applied => Applied),
461+
others => <>);
437462
begin
438-
LSP.Messages.ApplyWorkspaceEdit_Response'Write (JS'Access, Message);
439-
JSON := GNATCOLL.JSON.Get (JS.Get_JSON_Document, 1);
440-
Self.Send_Request (JSON.Write);
463+
Self.Send_Response (Request, Message);
441464
end Workspace_Apply_Edit;
442465

443466
----------------------------------------

source/client/lsp-clients.ads

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ package LSP.Clients is
110110
Request : out LSP.Types.LSP_Number;
111111
Value : LSP.Messages.WorkspaceSymbolParams);
112112

113-
-- Notification sennding procedures:
113+
-- Notification sending procedures:
114114

115115
overriding procedure Workspace_Did_Change_Configuration
116116
(Self : access Client;
@@ -185,4 +185,9 @@ private
185185
Decoder : Response_Decoder;
186186
Value : in out LSP.Messages.RequestMessage'Class);
187187

188+
procedure Send_Response
189+
(Self : in out Client'Class;
190+
Request : LSP.Types.LSP_Number_Or_String;
191+
Value : in out LSP.Messages.ResponseMessage'Class);
192+
188193
end LSP.Clients;

source/client/lsp-raw_clients.adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ package body LSP.Raw_Clients is
5656
end Is_Server_Running;
5757

5858
------------------
59-
-- Send_Request --
59+
-- Send_Message --
6060
------------------
6161

62-
procedure Send_Request
62+
procedure Send_Message
6363
(Self : in out Raw_Client'Class;
6464
Text : Ada.Strings.Unbounded.Unbounded_String)
6565
is
@@ -75,7 +75,7 @@ package body LSP.Raw_Clients is
7575
if Self.Can_Write then
7676
Self.Listener.Standard_Input_Available;
7777
end if;
78-
end Send_Request;
78+
end Send_Message;
7979

8080
-------------------
8181
-- Set_Arguments --

source/client/lsp-raw_clients.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ package LSP.Raw_Clients is
6767
function Exit_Code (Self : Raw_Client'Class) return Integer;
6868
-- Check is LSP server is running
6969

70-
procedure Send_Request
70+
procedure Send_Message
7171
(Self : in out Raw_Client'Class;
7272
Text : Ada.Strings.Unbounded.Unbounded_String);
7373
-- Send a request to LSP server. Text should contain valid JSON in

0 commit comments

Comments
 (0)