Skip to content

Commit 928732e

Browse files
committed
Rewrite workspace/executeCommand as a job
Refs #1141
1 parent 368b358 commit 928732e

30 files changed

+321
-60
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TESTER=$(ROOTDIR)/.obj/tester/tester-run$(EXE)
3535
MOCHA_ALS_UPDATE=
3636

3737
GPRBUILD_EXTRA=
38-
GPRBUILD_FLAGS=-m -j0 $(GPRBUILD_EXTRA)
38+
GPRBUILD_FLAGS=-m -j4 $(GPRBUILD_EXTRA)
3939
GPRBUILD=gprbuild $(GPRBUILD_FLAGS) -XSUPERPROJECT=
4040
GPRCLEAN_EXTRA=
4141
GPRCLEAN=gprclean -XSUPERPROJECT= $(GPRCLEAN_EXTRA)

source/ada/lsp-ada_commands.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ with Ada.Tags;
2626

2727
with VSS.String_Vectors;
2828

29-
with LSP.Structures;
3029
with LSP.Errors;
30+
with LSP.Server_Jobs;
31+
with LSP.Structures;
3132

3233
limited with LSP.Ada_Handlers;
3334

@@ -49,6 +50,9 @@ package LSP.Ada_Commands is
4950
-- Commands are executed on the server side only.
5051
-- The Handler is the access to the message handler executing the command.
5152

53+
function Priority (Self : Command) return LSP.Server_Jobs.Job_Priority
54+
is abstract;
55+
5256
procedure Register (Value : Ada.Tags.Tag);
5357
-- Register a new command type. The type should be in Command'Class
5458

source/ada/lsp-ada_driver.adb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ with LSP.Ada_Declaration;
4343
with LSP.Ada_Document_Symbol;
4444
with LSP.Ada_Did_Change_Configurations;
4545
with LSP.Ada_Did_Change_Document;
46+
with LSP.Ada_Execute_Command;
4647
with LSP.Ada_Folding_Range;
4748
with LSP.Ada_Hover;
4849
with LSP.Ada_References;
@@ -85,6 +86,7 @@ with LSP.Server_Notifications.DidChangeConfiguration;
8586
with LSP.Server_Requests.Definition;
8687
with LSP.Server_Requests.Declaration;
8788
with LSP.Server_Requests.DocumentSymbol;
89+
with LSP.Server_Requests.ExecuteCommand;
8890
with LSP.Server_Requests.FoldingRange;
8991
with LSP.Server_Requests.Hover;
9092
with LSP.Server_Requests.References;
@@ -213,6 +215,10 @@ procedure LSP.Ada_Driver is
213215
LSP.Ada_Document_Symbol.Ada_Document_Symbol_Handler
214216
(Ada_Handler'Unchecked_Access);
215217

218+
Ada_Execute_Command_Handler : aliased
219+
LSP.Ada_Execute_Command.Execute_Command_Handler
220+
(Ada_Handler'Unchecked_Access);
221+
216222
Ada_Folding_Range_Handler : aliased
217223
LSP.Ada_Folding_Range.Ada_Folding_Range_Handler
218224
(Ada_Handler'Unchecked_Access);
@@ -449,6 +455,10 @@ begin
449455
(LSP.Server_Requests.DocumentSymbol.Request'Tag,
450456
Ada_Document_Symbol_Handler'Unchecked_Access);
451457

458+
Server.Register_Handler
459+
(LSP.Server_Requests.ExecuteCommand.Request'Tag,
460+
Ada_Execute_Command_Handler'Unchecked_Access);
461+
452462
Server.Register_Handler
453463
(LSP.Server_Requests.FoldingRange.Request'Tag,
454464
Ada_Folding_Range_Handler'Unchecked_Access);
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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 Ada.Tags.Generic_Dispatching_Constructor;
19+
with Ada.Unchecked_Deallocation;
20+
21+
with VSS.Strings.Conversions;
22+
23+
with LSP.Ada_Commands;
24+
with LSP.Ada_Handlers;
25+
with LSP.Ada_Request_Jobs;
26+
with LSP.Client_Message_Receivers;
27+
with LSP.Enumerations;
28+
with LSP.Errors;
29+
with LSP.Server_Requests.ExecuteCommand;
30+
with LSP.Structures;
31+
32+
package body LSP.Ada_Execute_Command is
33+
34+
type Command_Access is access LSP.Ada_Commands.Command'Class;
35+
36+
procedure Free is new Ada.Unchecked_Deallocation
37+
(LSP.Ada_Commands.Command'Class, Command_Access);
38+
39+
type Ada_Execute_Command_Job
40+
(Parent : not null access constant Execute_Command_Handler) is limited
41+
new LSP.Ada_Request_Jobs.Ada_Request_Job (Priority => LSP.Server_Jobs.Low)
42+
with record
43+
Command : Command_Access;
44+
end record;
45+
46+
overriding function Priority
47+
(Self : Ada_Execute_Command_Job) return LSP.Server_Jobs.Job_Priority is
48+
(if Self.Request.Canceled then LSP.Server_Jobs.Immediate
49+
elsif Self.Command = null then LSP.Server_Jobs.Low
50+
else Self.Command.Priority);
51+
-- Use command priority when we have a command
52+
53+
overriding procedure Execute_Ada_Request
54+
(Self : in out Ada_Execute_Command_Job;
55+
Client :
56+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
57+
Status : out LSP.Server_Jobs.Execution_Status);
58+
59+
function Create_Command is new Ada.Tags.Generic_Dispatching_Constructor
60+
(T => LSP.Ada_Commands.Command,
61+
Parameters => LSP.Structures.LSPAny_Vector,
62+
Constructor => LSP.Ada_Commands.Create);
63+
64+
----------------
65+
-- Create_Job --
66+
----------------
67+
68+
overriding function Create_Job
69+
(Self : Execute_Command_Handler;
70+
Message : LSP.Server_Messages.Server_Message_Access)
71+
return LSP.Server_Jobs.Server_Job_Access
72+
is
73+
use type Ada.Tags.Tag;
74+
75+
Request : LSP.Server_Requests.ExecuteCommand.Request
76+
renames LSP.Server_Requests.ExecuteCommand.Request (Message.all);
77+
78+
Params : LSP.Structures.ExecuteCommandParams renames Request.Params;
79+
80+
Tag : constant Ada.Tags.Tag :=
81+
(if Params.command.Is_Empty then Ada.Tags.No_Tag
82+
else Ada.Tags.Internal_Tag
83+
(VSS.Strings.Conversions.To_UTF_8_String (Params.command)));
84+
85+
Command : constant Command_Access :=
86+
(if Tag = Ada.Tags.No_Tag then null
87+
else new LSP.Ada_Commands.Command'Class'
88+
(Create_Command (Tag, Params.arguments'Unrestricted_Access)));
89+
90+
Result : constant LSP.Server_Jobs.Server_Job_Access :=
91+
new Ada_Execute_Command_Job'
92+
(Parent => Self'Unchecked_Access,
93+
Command => Command,
94+
Request => LSP.Ada_Request_Jobs.Request_Access (Message));
95+
begin
96+
return Result;
97+
end Create_Job;
98+
99+
-------------------------
100+
-- Execute_Ada_Request --
101+
-------------------------
102+
103+
overriding procedure Execute_Ada_Request
104+
(Self : in out Ada_Execute_Command_Job;
105+
Client :
106+
in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
107+
Status : out LSP.Server_Jobs.Execution_Status)
108+
is
109+
110+
Handler : constant not null access
111+
LSP.Ada_Handlers.Message_Handler'Class :=
112+
LSP.Ada_Handlers.Message_Handler'Class
113+
(Self.Parent.Context.all)'Access;
114+
115+
Message : LSP.Server_Requests.ExecuteCommand.Request
116+
renames LSP.Server_Requests.ExecuteCommand.Request (Self.Message.all);
117+
118+
Response : LSP.Structures.LSPAny_Or_Null;
119+
Error : LSP.Errors.ResponseError_Optional;
120+
121+
begin
122+
Status := LSP.Server_Jobs.Done;
123+
124+
if Self.Command = null then
125+
Client.On_Error_Response
126+
(Message.Id,
127+
(code => LSP.Enumerations.InternalError,
128+
message => "Unknown command"));
129+
130+
else
131+
Self.Command.Execute
132+
(Handler => Handler,
133+
Response => Response,
134+
Error => Error);
135+
136+
if Error.Is_Set then
137+
Client.On_Error_Response (Message.Id, Error.Value);
138+
else
139+
Client.On_ExecuteCommand_Response (Message.Id, Response);
140+
end if;
141+
142+
Free (Self.Command);
143+
end if;
144+
end Execute_Ada_Request;
145+
146+
end LSP.Ada_Execute_Command;
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 workspace/executeCommand
19+
-- requests.
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_Execute_Command is
27+
28+
type Execute_Command_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 : Execute_Command_Handler;
35+
Message : LSP.Server_Messages.Server_Message_Access)
36+
return LSP.Server_Jobs.Server_Job_Access;
37+
38+
end LSP.Ada_Execute_Command;

source/ada/lsp-ada_handlers-executables_commands.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
with LSP.Ada_Commands;
2121
with LSP.Errors;
22+
with LSP.Server_Jobs;
2223

2324
package LSP.Ada_Handlers.Executables_Commands is
2425

@@ -38,6 +39,10 @@ private
3839
Response : in out LSP.Structures.LSPAny_Or_Null;
3940
Error : in out LSP.Errors.ResponseError_Optional);
4041

42+
overriding function Priority (Self : Command)
43+
return LSP.Server_Jobs.Job_Priority
44+
is (LSP.Server_Jobs.Low);
45+
4146
for Command'External_Tag use "als-executables";
4247

4348
end LSP.Ada_Handlers.Executables_Commands;

source/ada/lsp-ada_handlers-mains_commands.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
with LSP.Ada_Commands;
2121
with LSP.Errors;
22+
with LSP.Server_Jobs;
2223

2324
package LSP.Ada_Handlers.Mains_Commands is
2425

@@ -38,6 +39,10 @@ private
3839
Response : in out LSP.Structures.LSPAny_Or_Null;
3940
Error : in out LSP.Errors.ResponseError_Optional);
4041

42+
overriding function Priority (Self : Command)
43+
return LSP.Server_Jobs.Job_Priority
44+
is (LSP.Server_Jobs.Low);
45+
4146
for Command'External_Tag use "als-mains";
4247

4348
end LSP.Ada_Handlers.Mains_Commands;

source/ada/lsp-ada_handlers-named_parameters_commands.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
with LSP.Ada_Commands;
2222
with LSP.Errors;
23+
with LSP.Server_Jobs;
2324

2425
package LSP.Ada_Handlers.Named_Parameters_Commands is
2526

@@ -57,6 +58,10 @@ private
5758
Response : in out LSP.Structures.LSPAny_Or_Null;
5859
Error : in out LSP.Errors.ResponseError_Optional);
5960

61+
overriding function Priority (Self : Command)
62+
return LSP.Server_Jobs.Job_Priority
63+
is (LSP.Server_Jobs.Low);
64+
6065
function Write_Command
6166
(Self : Command) return LSP.Structures.LSPAny_Vector;
6267

source/ada/lsp-ada_handlers-object_dir_commands.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
with LSP.Ada_Commands;
2222
with LSP.Errors;
23+
with LSP.Server_Jobs;
2324

2425
package LSP.Ada_Handlers.Object_Dir_Commands is
2526

@@ -39,6 +40,10 @@ private
3940
Response : in out LSP.Structures.LSPAny_Or_Null;
4041
Error : in out LSP.Errors.ResponseError_Optional);
4142

43+
overriding function Priority (Self : Command)
44+
return LSP.Server_Jobs.Job_Priority
45+
is (LSP.Server_Jobs.Low);
46+
4247
for Command'External_Tag use "als-object-dir";
4348

4449
end LSP.Ada_Handlers.Object_Dir_Commands;

source/ada/lsp-ada_handlers-other_file_commands.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
with LSP.Ada_Commands;
2121
with LSP.Errors;
22+
with LSP.Server_Jobs;
2223

2324
package LSP.Ada_Handlers.Other_File_Commands is
2425

@@ -44,6 +45,10 @@ private
4445
Response : in out LSP.Structures.LSPAny_Or_Null;
4546
Error : in out LSP.Errors.ResponseError_Optional);
4647

48+
overriding function Priority (Self : Command)
49+
return LSP.Server_Jobs.Job_Priority
50+
is (LSP.Server_Jobs.Low);
51+
4752
for Command'External_Tag use "als-other-file";
4853

4954
end LSP.Ada_Handlers.Other_File_Commands;

0 commit comments

Comments
 (0)