Skip to content

Commit 3c8a02e

Browse files
committed
Replace On_DidChangeConfiguration_Notification
with a job. Increment Project_Stamp on job creation to shutdown indexing jobs. Refs #1141
1 parent 6b50e0e commit 3c8a02e

8 files changed

+247
-28
lines changed

source/ada/lsp-ada_configurations.ads

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ with LSP.Structures;
2626

2727
package LSP.Ada_Configurations is
2828

29-
type Configuration is tagged limited private;
29+
type Configuration is tagged private;
3030

3131
procedure Read_JSON
3232
(Self : in out Configuration'Class;
@@ -116,7 +116,7 @@ private
116116

117117
use type VSS.Strings.Virtual_String;
118118

119-
type Configuration is tagged limited record
119+
type Configuration is tagged record
120120
Project_File : VSS.Strings.Virtual_String;
121121
Charset : VSS.Strings.Virtual_String;
122122
Relocate_Build_Tree : VSS.Strings.Virtual_String;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.Ada_Configurations;
19+
with LSP.Client_Message_Receivers;
20+
with LSP.Server_Notifications.DidChangeConfiguration;
21+
22+
package body LSP.Ada_Did_Change_Configurations is
23+
24+
type Apply_Config_Job
25+
(Parent : not null access constant Ada_Did_Change_Handler)
26+
is limited new LSP.Server_Jobs.Server_Job with record
27+
Message : LSP.Server_Messages.Server_Message_Access;
28+
Configuration : LSP.Ada_Configurations.Configuration;
29+
Reload : Boolean;
30+
Is_Done : Boolean := False;
31+
end record;
32+
33+
type Apply_Config_Job_Access is access all Apply_Config_Job;
34+
35+
overriding function Priority
36+
(Self : Apply_Config_Job) return LSP.Server_Jobs.Job_Priority is
37+
(LSP.Server_Jobs.Fence);
38+
39+
overriding function Is_Done (Self : Apply_Config_Job) return Boolean is
40+
(Self.Is_Done);
41+
42+
overriding procedure Execute
43+
(Self : in out Apply_Config_Job;
44+
Client :
45+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class);
46+
47+
overriding function Message (Self : Apply_Config_Job)
48+
return LSP.Server_Messages.Server_Message_Access is (Self.Message);
49+
50+
-------------
51+
-- Execute --
52+
-------------
53+
54+
overriding procedure Execute
55+
(Self : in out Apply_Config_Job;
56+
Client :
57+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class) is
58+
begin
59+
Self.Parent.Context.Set_Configuration (Self.Configuration);
60+
61+
if Self.Reload then
62+
Self.Parent.Context.Reload_Project;
63+
end if;
64+
65+
Self.Is_Done := True;
66+
end Execute;
67+
68+
----------------
69+
-- Create_Job --
70+
----------------
71+
72+
overriding function Create_Job
73+
(Self : Ada_Did_Change_Handler;
74+
Message : LSP.Server_Messages.Server_Message_Access)
75+
return LSP.Server_Jobs.Server_Job_Access
76+
is
77+
Value : LSP.Server_Notifications.DidChangeConfiguration.Notification
78+
renames LSP.Server_Notifications.DidChangeConfiguration.Notification
79+
(Message.all);
80+
81+
Result : constant Apply_Config_Job_Access :=
82+
new Apply_Config_Job (Self'Unchecked_Access);
83+
84+
Reload : Boolean renames Result.Reload;
85+
begin
86+
Result.Configuration := Self.Context.Get_Configuration.all;
87+
Result.Configuration.Read_JSON (Value.Params.settings, Reload);
88+
89+
-- Always reload project if Project_Tree isn't ready
90+
Reload := Reload or not Self.Context.Project_Tree_Is_Defined;
91+
92+
if Reload then
93+
-- Stop indexing by changing project stamp
94+
Self.Context.Increment_Project_Timestamp;
95+
end if;
96+
97+
return LSP.Server_Jobs.Server_Job_Access (Result);
98+
end Create_Job;
99+
100+
end LSP.Ada_Did_Change_Configurations;
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) 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 handler and job types for didChangeConfiguration
19+
-- notifications.
20+
21+
with LSP.Ada_Job_Contexts;
22+
with LSP.Server_Jobs;
23+
with LSP.Server_Message_Handlers;
24+
with LSP.Server_Messages;
25+
26+
package LSP.Ada_Did_Change_Configurations is
27+
28+
type Ada_Did_Change_Handler
29+
(Context : not null access LSP.Ada_Job_Contexts.Ada_Job_Context'Class) is
30+
limited new LSP.Server_Message_Handlers.Server_Message_Handler
31+
with null record;
32+
33+
overriding function Create_Job
34+
(Self : Ada_Did_Change_Handler;
35+
Message : LSP.Server_Messages.Server_Message_Access)
36+
return LSP.Server_Jobs.Server_Job_Access;
37+
38+
end LSP.Ada_Did_Change_Configurations;

source/ada/lsp-ada_driver.adb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ with GNATCOLL.VFS; use GNATCOLL.VFS;
3838
with GNATCOLL.Utils;
3939

4040
with LSP.Ada_Commands;
41+
with LSP.Ada_Did_Change_Configurations;
4142
with LSP.Ada_Handlers;
4243
with LSP.Ada_Handlers.Executables_Commands;
4344
with LSP.Ada_Handlers.Mains_Commands;
@@ -69,6 +70,7 @@ with LSP.GPR_External_Tools;
6970
with LSP.Memory_Statistics;
7071
with LSP.Predefined_Completion;
7172
with LSP.Secure_Message_Loggers;
73+
with LSP.Server_Notifications.DidChangeConfiguration;
7274
with LSP.Servers;
7375
with LSP.Stdio_Streams;
7476

@@ -166,6 +168,11 @@ procedure LSP.Ada_Driver is
166168
GPR_Handler : aliased LSP.GPR_Handlers.Message_Handler
167169
(Server'Access, Tracer'Unchecked_Access);
168170

171+
-- Job handlers
172+
Ada_Did_Change_Handler : aliased
173+
LSP.Ada_Did_Change_Configurations.Ada_Did_Change_Handler
174+
(Ada_Handler'Unchecked_Access);
175+
169176
Fuzzing_Activated : constant Boolean :=
170177
not VSS.Application.System_Environment.Value ("ALS_FUZZING").Is_Empty;
171178
pragma Unreferenced (Fuzzing_Activated);
@@ -358,6 +365,10 @@ begin
358365
LSP.Predefined_Completion.Load_Predefined_Completion_Db
359366
(Server_Trace);
360367

368+
Server.Register_Handler
369+
(LSP.Server_Notifications.DidChangeConfiguration.Notification'Tag,
370+
Ada_Did_Change_Handler'Unchecked_Access);
371+
361372
Server.Run
362373
(Ada_Handler'Unchecked_Access,
363374
Tracer'Unchecked_Access,

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ package body LSP.Ada_Handlers.Project_Loading is
654654
Self.Contexts.Cleanup;
655655

656656
Self.Project_Tree.Unload;
657-
-- Self.Project_Environment := Empty_Environment;
658657
Self.Project_Predefined_Sources.Clear;
659658
Self.Project_Dirs_Loaded.Clear;
660659

source/ada/lsp-ada_handlers.adb

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ package body LSP.Ada_Handlers is
412412
Imprecise => Imprecise);
413413
end Imprecise_Resolve_Name;
414414

415+
---------------------------------
416+
-- Increment_Project_Timestamp --
417+
---------------------------------
418+
419+
overriding procedure Increment_Project_Timestamp
420+
(Self : in out Message_Handler) is
421+
begin
422+
Self.Project_Stamp := Self.Project_Stamp + 1;
423+
end Increment_Project_Timestamp;
424+
415425
----------------
416426
-- Initialize --
417427
----------------
@@ -2155,26 +2165,6 @@ package body LSP.Ada_Handlers is
21552165
Self.Publish_Diagnostics (Document);
21562166
end On_DidChange_Notification;
21572167

2158-
--------------------------------------------
2159-
-- On_DidChangeConfiguration_Notification --
2160-
--------------------------------------------
2161-
2162-
overriding procedure On_DidChangeConfiguration_Notification
2163-
(Self : in out Message_Handler;
2164-
Value : LSP.Structures.DidChangeConfigurationParams)
2165-
is
2166-
Reload : Boolean;
2167-
begin
2168-
Self.Configuration.Read_JSON (Value.settings, Reload);
2169-
2170-
-- Always reload project if Project_Tree isn't ready
2171-
Reload := Reload or not Self.Project_Tree.Is_Defined;
2172-
2173-
if Reload then
2174-
LSP.Ada_Handlers.Project_Loading.Reload_Project (Self);
2175-
end if;
2176-
end On_DidChangeConfiguration_Notification;
2177-
21782168
-------------------------------------------
21792169
-- On_DidChangeWatchedFiles_Notification --
21802170
-------------------------------------------
@@ -4686,6 +4676,26 @@ package body LSP.Ada_Handlers is
46864676
end if;
46874677
end Publish_Diagnostics;
46884678

4679+
--------------------
4680+
-- Reload_Project --
4681+
--------------------
4682+
4683+
overriding procedure Reload_Project (Self : in out Message_Handler) is
4684+
begin
4685+
LSP.Ada_Handlers.Project_Loading.Reload_Project (Self);
4686+
end Reload_Project;
4687+
4688+
-----------------------
4689+
-- Set_Configuration --
4690+
-----------------------
4691+
4692+
overriding procedure Set_Configuration
4693+
(Self : in out Message_Handler;
4694+
Value : LSP.Ada_Configurations.Configuration) is
4695+
begin
4696+
Self.Configuration := Value;
4697+
end Set_Configuration;
4698+
46894699
-----------------------
46904700
-- To_Workspace_Edit --
46914701
-----------------------

source/ada/lsp-ada_handlers.ads

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ with LSP.Ada_Context_Sets;
3333
with LSP.Ada_Documents;
3434
with LSP.Ada_File_Sets;
3535
with LSP.Ada_Highlighters;
36+
with LSP.Ada_Job_Contexts;
3637
with LSP.Client_Message_Receivers;
3738
with LSP.File_Monitors;
3839
with LSP.Server_Message_Visitors;
@@ -60,6 +61,7 @@ package LSP.Ada_Handlers is
6061
new LSP.Server_Message_Visitors.Server_Message_Visitor
6162
and LSP.Server_Request_Receivers.Server_Request_Receiver
6263
and LSP.Server_Notification_Receivers.Server_Notification_Receiver
64+
and LSP.Ada_Job_Contexts.Ada_Job_Context
6365
with private;
6466

6567
procedure Initialize
@@ -203,9 +205,10 @@ private
203205
new LSP.Unimplemented_Handlers.Unimplemented_Handler
204206
and LSP.Server_Message_Visitors.Server_Message_Visitor
205207
and LSP.Server_Notification_Receivers.Server_Notification_Receiver
208+
and LSP.Ada_Job_Contexts.Ada_Job_Context
206209
with record
207210
Client : LSP.Ada_Client_Capabilities.Client_Capability;
208-
Configuration : LSP.Ada_Configurations.Configuration;
211+
Configuration : aliased LSP.Ada_Configurations.Configuration;
209212

210213
Contexts : LSP.Ada_Context_Sets.Context_Set;
211214
-- There is one context in this list per loaded project.
@@ -362,10 +365,6 @@ private
362365
Id : LSP.Structures.Integer_Or_Virtual_String;
363366
Value : LSP.Structures.DocumentRangeFormattingParams);
364367

365-
overriding procedure On_DidChangeConfiguration_Notification
366-
(Self : in out Message_Handler;
367-
Value : LSP.Structures.DidChangeConfigurationParams);
368-
369368
overriding procedure On_DidChangeWatchedFiles_Notification
370369
(Self : in out Message_Handler;
371370
Value : LSP.Structures.DidChangeWatchedFilesParams);
@@ -488,4 +487,24 @@ private
488487
-- project tree, or is a runtime file for this project. If the file
489488
-- is not known to any project, return an empty list.
490489

490+
------------------
491+
-- Job_Context --
492+
------------------
493+
494+
overriding function Get_Configuration (Self : Message_Handler)
495+
return access constant LSP.Ada_Configurations.Configuration is
496+
(Self.Configuration'Unchecked_Access);
497+
498+
overriding procedure Set_Configuration
499+
(Self : in out Message_Handler;
500+
Value : LSP.Ada_Configurations.Configuration);
501+
502+
overriding procedure Increment_Project_Timestamp
503+
(Self : in out Message_Handler);
504+
505+
overriding function Project_Tree_Is_Defined (Self : Message_Handler)
506+
return Boolean is (Self.Project_Tree.Is_Defined);
507+
508+
overriding procedure Reload_Project (Self : in out Message_Handler);
509+
491510
end LSP.Ada_Handlers;

source/ada/lsp-ada_job_contexts.ads

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 interface for data shared between jobs. This data
19+
-- includes open documents, non-aggregate project trees, settings, etc
20+
21+
with LSP.Ada_Configurations;
22+
23+
package LSP.Ada_Job_Contexts is
24+
25+
type Ada_Job_Context is limited interface;
26+
27+
function Get_Configuration (Self : Ada_Job_Context)
28+
return access constant LSP.Ada_Configurations.Configuration is abstract;
29+
30+
procedure Set_Configuration
31+
(Self : in out Ada_Job_Context;
32+
Value : LSP.Ada_Configurations.Configuration) is abstract;
33+
34+
procedure Increment_Project_Timestamp (Self : in out Ada_Job_Context)
35+
is abstract;
36+
37+
function Project_Tree_Is_Defined
38+
(Self : Ada_Job_Context) return Boolean is abstract;
39+
40+
procedure Reload_Project (Self : in out Ada_Job_Context) is abstract;
41+
42+
end LSP.Ada_Job_Contexts;

0 commit comments

Comments
 (0)