Skip to content

Commit 7528dcc

Browse files
committed
Add a base type for server request jobs
to keep request cancelation logic. Use it in hover and references requests. Refs #1141
1 parent ce451f2 commit 7528dcc

File tree

4 files changed

+138
-43
lines changed

4 files changed

+138
-43
lines changed

source/ada/lsp-ada_hover.adb

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,27 @@ with LSP.Ada_Context_Sets;
2525
with LSP.Ada_Documentation;
2626
with LSP.Client_Message_Receivers;
2727
with LSP.Predefined_Completion;
28+
with LSP.Server_Request_Jobs;
2829
with LSP.Server_Requests.Hover;
2930
with LSP.Structures;
3031
with LSP.Utils;
3132

3233
package body LSP.Ada_Hover is
3334

3435
type Ada_Hover_Job
35-
(Parent : not null access constant Ada_Hover_Handler)
36-
is limited new LSP.Server_Jobs.Server_Job with record
37-
Message : LSP.Server_Messages.Server_Message_Access;
38-
end record;
36+
(Parent : not null access constant Ada_Hover_Handler) is limited
37+
new LSP.Server_Request_Jobs.Server_Request_Job
38+
(Priority => LSP.Server_Jobs.High)
39+
with null record;
3940

4041
type Ada_Hover_Job_Access is access all Ada_Hover_Job;
4142

42-
overriding function Priority
43-
(Self : Ada_Hover_Job) return LSP.Server_Jobs.Job_Priority is
44-
(LSP.Server_Jobs.High);
45-
46-
overriding procedure Execute
43+
overriding procedure Execute_Request
4744
(Self : in out Ada_Hover_Job;
4845
Client :
4946
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
5047
Status : out LSP.Server_Jobs.Execution_Status);
5148

52-
overriding function Message (Self : Ada_Hover_Job)
53-
return LSP.Server_Messages.Server_Message_Access is (Self.Message);
54-
5549
----------------
5650
-- Create_Job --
5751
----------------
@@ -64,16 +58,16 @@ package body LSP.Ada_Hover is
6458
Result : constant Ada_Hover_Job_Access :=
6559
new Ada_Hover_Job'
6660
(Parent => Self'Unchecked_Access,
67-
Message => Message);
61+
Request => LSP.Server_Request_Jobs.Request_Access (Message));
6862
begin
6963
return LSP.Server_Jobs.Server_Job_Access (Result);
7064
end Create_Job;
7165

72-
-------------
73-
-- Execute --
74-
-------------
66+
---------------------
67+
-- Execute_Request --
68+
---------------------
7569

76-
overriding procedure Execute
70+
overriding procedure Execute_Request
7771
(Self : in out Ada_Hover_Job;
7872
Client :
7973
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
@@ -209,6 +203,6 @@ package body LSP.Ada_Hover is
209203
end if;
210204

211205
Client.On_Hover_Response (Message.Id, Response);
212-
end Execute;
206+
end Execute_Request;
213207

214208
end LSP.Ada_Hover;

source/ada/lsp-ada_references.adb

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ with LSP.Ada_Id_Iterators;
3131
with LSP.Client_Message_Receivers;
3232
with LSP.Enumerations;
3333
with LSP.Locations;
34+
with LSP.Server_Request_Jobs;
3435
with LSP.Server_Requests.References;
3536
with LSP.Structures;
3637

@@ -47,34 +48,28 @@ package body LSP.Ada_References is
4748
(Reversible_Iterator, Iterator_Access);
4849

4950
type Ada_References_Job
50-
(Parent : not null access constant Ada_References_Handler)
51-
is limited new LSP.Server_Jobs.Server_Job with record
52-
Message : LSP.Server_Messages.Server_Message_Access;
53-
Is_Enum : Boolean := False;
54-
Response : LSP.Structures.Location_Vector_Or_Null;
55-
Filter : LSP.Locations.File_Span_Sets.Set;
56-
Contexts : LSP.Ada_Context_Sets.Context_Lists.List;
57-
Context : LSP.Ada_Context_Sets.Context_Access;
58-
Iterator : Iterator_Access;
59-
Cursor : LSP.Ada_File_Sets.File_Sets.Cursor;
60-
Definition : Libadalang.Analysis.Defining_Name;
51+
(Parent : not null access constant Ada_References_Handler) is limited
52+
new LSP.Server_Request_Jobs.Server_Request_Job
53+
(Priority => LSP.Server_Jobs.Low) with
54+
record
55+
Is_Enum : Boolean := False;
56+
Response : LSP.Structures.Location_Vector_Or_Null;
57+
Filter : LSP.Locations.File_Span_Sets.Set;
58+
Contexts : LSP.Ada_Context_Sets.Context_Lists.List;
59+
Context : LSP.Ada_Context_Sets.Context_Access;
60+
Iterator : Iterator_Access;
61+
Cursor : LSP.Ada_File_Sets.File_Sets.Cursor;
62+
Definition : Libadalang.Analysis.Defining_Name;
6163
end record;
6264

6365
type Ada_References_Job_Access is access all Ada_References_Job;
6466

65-
overriding function Priority
66-
(Self : Ada_References_Job) return LSP.Server_Jobs.Job_Priority is
67-
(LSP.Server_Jobs.Low);
68-
69-
overriding procedure Execute
67+
overriding procedure Execute_Request
7068
(Self : in out Ada_References_Job;
7169
Client :
7270
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
7371
Status : out LSP.Server_Jobs.Execution_Status);
7472

75-
overriding function Message (Self : Ada_References_Job)
76-
return LSP.Server_Messages.Server_Message_Access is (Self.Message);
77-
7873
function Get_Reference_Kind
7974
(Self : Ada_References_Job'Class;
8075
Node : Libadalang.Analysis.Ada_Node'Class;
@@ -101,19 +96,19 @@ package body LSP.Ada_References is
10196
Result : constant Ada_References_Job_Access :=
10297
new Ada_References_Job'
10398
(Parent => Self'Unchecked_Access,
104-
Message => Message,
99+
Request => LSP.Server_Request_Jobs.Request_Access (Message),
105100
others => <>);
106101
begin
107102
Result.Contexts := Self.Context.Contexts_For_File (File);
108103

109104
return LSP.Server_Jobs.Server_Job_Access (Result);
110105
end Create_Job;
111106

112-
-------------
113-
-- Execute --
114-
-------------
107+
---------------------
108+
-- Execute_Request --
109+
---------------------
115110

116-
overriding procedure Execute
111+
overriding procedure Execute_Request
117112
(Self : in out Ada_References_Job;
118113
Client :
119114
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
@@ -232,7 +227,7 @@ package body LSP.Ada_References is
232227
Client.On_References_Response (Message.Id, Self.Response);
233228
Status := LSP.Server_Jobs.Done;
234229
end if;
235-
end Execute;
230+
end Execute_Request;
236231

237232
------------------------
238233
-- Get_Reference_Kind --
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) 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+
with LSP.Constants;
19+
20+
package body LSP.Server_Request_Jobs is
21+
22+
-------------
23+
-- Execute --
24+
-------------
25+
26+
overriding procedure Execute
27+
(Self : in out Server_Request_Job;
28+
Client : in out LSP.Client_Message_Receivers.Client_Message_Receiver'
29+
Class;
30+
Status : out LSP.Server_Jobs.Execution_Status)
31+
is
32+
begin
33+
if Self.Request.Canceled then
34+
Client.On_Error_Response
35+
(Self.Request.Id,
36+
(code => LSP.Constants.RequestCancelled,
37+
message => "Request was canceled"));
38+
39+
Status := LSP.Server_Jobs.Done;
40+
else
41+
Execute_Request (Server_Request_Job'Class (Self), Client, Status);
42+
end if;
43+
end Execute;
44+
45+
end LSP.Server_Request_Jobs;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 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+
-- This package provides a base type for server requests jobs. It implements
19+
-- request cancelation logic: if the request has been canceled then the job
20+
-- has Immediate priority and its execution just sends the corresponding
21+
-- error code.
22+
23+
with LSP.Client_Message_Receivers;
24+
with LSP.Server_Jobs;
25+
with LSP.Server_Messages;
26+
with LSP.Server_Requests;
27+
28+
package LSP.Server_Request_Jobs is
29+
pragma Preelaborate;
30+
31+
type Request_Access is
32+
access all LSP.Server_Requests.Server_Request'Class;
33+
34+
type Server_Request_Job (Priority : LSP.Server_Jobs.Job_Priority)
35+
is abstract limited new LSP.Server_Jobs.Server_Job with
36+
record
37+
Request : Request_Access;
38+
end record;
39+
40+
procedure Execute_Request
41+
(Self : in out Server_Request_Job;
42+
Client :
43+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
44+
Status : out LSP.Server_Jobs.Execution_Status) is abstract;
45+
46+
overriding function Priority
47+
(Self : Server_Request_Job) return LSP.Server_Jobs.Job_Priority is
48+
(if Self.Request.Canceled then LSP.Server_Jobs.Immediate
49+
else Self.Priority);
50+
51+
overriding procedure Execute
52+
(Self : in out Server_Request_Job;
53+
Client :
54+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
55+
Status : out LSP.Server_Jobs.Execution_Status);
56+
57+
overriding function Message (Self : Server_Request_Job)
58+
return LSP.Server_Messages.Server_Message_Access is
59+
(LSP.Server_Messages.Server_Message_Access (Self.Request));
60+
61+
end LSP.Server_Request_Jobs;

0 commit comments

Comments
 (0)