Skip to content

Commit ff4ce7b

Browse files
committed
Rewrite Ada_Indexing as a new server job
Refs #1141
1 parent 3705224 commit ff4ce7b

File tree

7 files changed

+59
-76
lines changed

7 files changed

+59
-76
lines changed

source/ada/lsp-ada_indexing.adb

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2023, AdaCore --
4+
-- Copyright (C) 2023-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- --
@@ -22,12 +22,15 @@ with VSS.Strings.Templates;
2222

2323
package body LSP.Ada_Indexing is
2424

25-
-----------------
26-
-- Index_Files --
27-
-----------------
28-
29-
procedure Index_Files (Self : in out Indexing_Job'Class) is
25+
-------------
26+
-- Execute --
27+
-------------
3028

29+
overriding procedure Execute
30+
(Self : in out Indexing_Job;
31+
Client :
32+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class)
33+
is
3134
use type LSP.Ada_Handlers.Project_Stamp;
3235

3336
procedure Emit_Progress_Report (Files_Indexed, Total_Files : Natural);
@@ -51,7 +54,7 @@ package body LSP.Ada_Indexing is
5154

5255
Self.Progress_Report_Sent := Current;
5356

54-
Self.Server.On_ProgressReport_Work_Done
57+
Client.On_ProgressReport_Work_Done
5558
(Self.Indexing_Token,
5659
(percentage => (True, (Files_Indexed * 100) / Total_Files),
5760
message =>
@@ -63,7 +66,7 @@ package body LSP.Ada_Indexing is
6366

6467
begin
6568
if Self.Total_Files_Indexed = 0 then
66-
Self.Server.On_ProgressBegin_Work_Done
69+
Client.On_ProgressBegin_Work_Done
6770
(Self.Indexing_Token,
6871
(title => "Indexing", percentage => (True, 0), others => <>));
6972
end if;
@@ -109,28 +112,10 @@ package body LSP.Ada_Indexing is
109112
if Self.Files_To_Index.Is_Empty then
110113
-- Indexing done.
111114

112-
Self.Server.On_ProgressEnd_Work_Done
115+
Client.On_ProgressEnd_Work_Done
113116
(Self.Indexing_Token, (message => <>));
114-
115-
return;
116117
end if;
117-
118-
declare
119-
Job : LSP.Server_Jobs.Server_Jobs_Access :=
120-
new Indexing_Job'
121-
(Server => Self.Server.all'Unchecked_Access,
122-
Handler => Self.Handler.all'Unchecked_Access,
123-
Files_To_Index => Self.Files_To_Index,
124-
Indexing_Token => Self.Indexing_Token,
125-
Total_Files_Indexed => Self.Total_Files_Indexed,
126-
Total_Files_To_Index => Self.Total_Files_To_Index,
127-
Progress_Report_Sent => Self.Progress_Report_Sent,
128-
Project_Stamp => Self.Project_Stamp);
129-
130-
begin
131-
Self.Server.Enqueue (Job);
132-
end;
133-
end Index_Files;
118+
end Execute;
134119

135120
-----------------------
136121
-- Schedule_Indexing --
@@ -155,7 +140,7 @@ package body LSP.Ada_Indexing is
155140
Server.Allocate_Request_Id;
156141
Token : constant LSP.Structures.ProgressToken :=
157142
Handler.Allocate_Progress_Token ("indexing");
158-
Job : LSP.Server_Jobs.Server_Jobs_Access :=
143+
Job : LSP.Server_Jobs.Server_Job_Access :=
159144
new Indexing_Job'
160145
(Server => Server,
161146
Handler => Handler,
@@ -167,7 +152,7 @@ package body LSP.Ada_Indexing is
167152
Project_Stamp => Project_Stamp);
168153

169154
begin
170-
Job.Server.On_Progress_Create_Request (Id, (token => Token));
155+
Server.On_Progress_Create_Request (Id, (token => Token));
171156
-- FIXME: wait response before sending progress notifications.
172157
-- Currenctly, we just send a `window/workDoneProgress/create`
173158
-- request and immediately after this start sending notifications.
@@ -178,16 +163,4 @@ package body LSP.Ada_Indexing is
178163
end;
179164
end Schedule_Indexing;
180165

181-
----------------------------------
182-
-- Visit_Server_Message_Visitor --
183-
----------------------------------
184-
185-
overriding procedure Visit_Server_Message_Visitor
186-
(Self : Indexing_Job;
187-
Value : in out
188-
LSP.Server_Message_Visitors.Server_Message_Visitor'Class) is
189-
begin
190-
Self'Unrestricted_Access.Index_Files;
191-
end Visit_Server_Message_Visitor;
192-
193166
end LSP.Ada_Indexing;

source/ada/lsp-ada_indexing.ads

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ with GNATCOLL.VFS;
2323
with LSP.Ada_Configurations;
2424
with LSP.Ada_Handlers;
2525
with LSP.Server_Jobs;
26-
private with LSP.Server_Message_Visitors;
2726
limited with LSP.Servers;
27+
private with LSP.Client_Message_Receivers;
28+
private with LSP.Server_Messages;
2829
private with LSP.Structures;
2930

3031
package LSP.Ada_Indexing is
@@ -42,7 +43,7 @@ package LSP.Ada_Indexing is
4243
Project_Stamp : LSP.Ada_Handlers.Project_Stamp;
4344
Files : File_Sets.Set);
4445

45-
type Indexing_Job (<>) is new LSP.Server_Jobs.Abstract_Server_Job
46+
type Indexing_Job (<>) is new LSP.Server_Jobs.Server_Job
4647
with private;
4748

4849
private
@@ -64,7 +65,7 @@ private
6465
type Indexing_Job
6566
(Server : not null access LSP.Servers.Server'Class;
6667
Handler : not null access LSP.Ada_Handlers.Message_Handler'Class) is
67-
new LSP.Server_Jobs.Abstract_Server_Job (Server) with
68+
new LSP.Server_Jobs.Server_Job with
6869
record
6970
Files_To_Index : File_Sets.Set;
7071
-- Contains any files that need indexing.
@@ -84,11 +85,19 @@ private
8485
Project_Stamp : LSP.Ada_Handlers.Project_Stamp;
8586
end record;
8687

87-
overriding procedure Visit_Server_Message_Visitor
88-
(Self : Indexing_Job;
89-
Value : in out
90-
LSP.Server_Message_Visitors.Server_Message_Visitor'Class);
88+
overriding function Priority
89+
(Self : Indexing_Job) return LSP.Server_Jobs.Job_Priority is
90+
(LSP.Server_Jobs.Low);
9191

92-
procedure Index_Files (Self : in out Indexing_Job'Class);
92+
overriding function Is_Done (Self : Indexing_Job) return Boolean is
93+
(Self.Files_To_Index.Is_Empty);
94+
95+
overriding procedure Execute
96+
(Self : in out Indexing_Job;
97+
Client :
98+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class);
99+
100+
overriding function Message (Self : Indexing_Job)
101+
return LSP.Server_Messages.Server_Message_Access is (null);
93102

94103
end LSP.Ada_Indexing;

source/server/lsp-job_schedulers.adb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,26 @@ package body LSP.Job_Schedulers is
6262

6363
if Job.Assigned then
6464
Message := null;
65-
66-
if Job.Priority in Self.Jobs'Range then
67-
Self.Jobs (Job.Priority).Append (Job);
68-
else
69-
Self.Blocker := Job;
70-
end if;
65+
Self.Enqueue (Job);
7166
end if;
7267
end if;
7368
end Create_Job;
7469

70+
-------------
71+
-- Enqueue --
72+
-------------
73+
74+
procedure Enqueue
75+
(Self : in out Job_Scheduler'Class;
76+
Job : not null LSP.Server_Jobs.Server_Job_Access) is
77+
begin
78+
if Job.Priority in Self.Jobs'Range then
79+
Self.Jobs (Job.Priority).Append (Job);
80+
else
81+
Self.Blocker := Job;
82+
end if;
83+
end Enqueue;
84+
7585
--------------
7686
-- Has_Jobs --
7787
--------------

source/server/lsp-job_schedulers.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ package LSP.Job_Schedulers is
4646
-- If there is no handler for the message, then the scheduler doesn't
4747
-- accept message and server should destroy it.
4848

49+
procedure Enqueue
50+
(Self : in out Job_Scheduler'Class;
51+
Job : not null LSP.Server_Jobs.Server_Job_Access);
52+
-- Put Job into the job queue.
53+
4954
procedure Process_High_Priority_Job
5055
(Self : in out Job_Scheduler'Class;
5156
Client :

source/server/lsp-server_jobs.ads

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
with LSP.Client_Message_Receivers;
1919
with LSP.Server_Messages;
20-
limited with LSP.Servers;
2120

2221
package LSP.Server_Jobs is
2322
pragma Preelaborate;
@@ -54,16 +53,15 @@ package LSP.Server_Jobs is
5453

5554
procedure Complete
5655
(Self : in out Server_Job;
57-
Next : LSP.Server_Messages.Server_Message_Access) is null
58-
with Pre'Class => Is_Done (Self);
56+
Next : LSP.Server_Messages.Server_Message_Access) is null;
5957
-- Complete message execution. The next message is provided if any.
6058
-- Currently this is called only for Fence jobs.
6159

6260
procedure Cancel
6361
(Self : in out Server_Job;
6462
Client :
6563
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class)
66-
is abstract;
64+
is null;
6765
-- Cancel job execution. Use Client to send messages if required.
6866

6967
-- function Progress (Self : Server_Job) return Job_Progress is abstract;
@@ -78,11 +76,4 @@ package LSP.Server_Jobs is
7876

7977
type Server_Job_Access is access all Server_Job'Class;
8078

81-
type Abstract_Server_Job
82-
(Server : not null access LSP.Servers.Server'Class) is
83-
new LSP.Server_Messages.Server_Message with null record;
84-
-- This type should be deleted after migration to Server_Job type.
85-
86-
type Server_Jobs_Access is access all Abstract_Server_Job'Class;
87-
8879
end LSP.Server_Jobs;

source/server/lsp-servers.adb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,10 @@ package body LSP.Servers is
117117

118118
procedure Enqueue
119119
(Self : in out Server'Class;
120-
Job : in out LSP.Server_Jobs.Server_Jobs_Access)
121-
is
122-
use type LSP.Server_Jobs.Server_Jobs_Access;
123-
120+
Job : in out LSP.Server_Jobs.Server_Job_Access) is
124121
begin
125-
if Job /= null then
126-
Self.Input_Queue.Enqueue (Server_Message_Access (Job));
127-
Job := null;
128-
end if;
122+
Self.Scheduler.Enqueue (Job);
123+
Job := null;
129124
end Enqueue;
130125

131126
--------------

source/server/lsp-servers.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ package LSP.Servers is
111111

112112
procedure Enqueue
113113
(Self : in out Server'Class;
114-
Job : in out LSP.Server_Jobs.Server_Jobs_Access);
114+
Job : in out LSP.Server_Jobs.Server_Job_Access);
115115
-- Put server job into the queue.
116116

117117
function Allocate_Request_Id

0 commit comments

Comments
 (0)