Skip to content

Commit 25a20d4

Browse files
Merge branch 'topic/als#1149' into 'edge'
Revamp error reporting for refactoring commands See merge request eng/ide/ada_language_server!1247
2 parents 64d5a01 + b36b15e commit 25a20d4

File tree

33 files changed

+590
-884
lines changed

33 files changed

+590
-884
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ with LSP.Ada_Handlers;
4444
with LSP.Ada_Handlers.Named_Parameters_Commands;
4545
with LSP.Ada_Handlers.Other_File_Commands;
4646
with LSP.Ada_Handlers.Project_Reload_Commands;
47-
with LSP.Ada_Handlers.Refactor_Imports_Commands;
48-
with LSP.Ada_Handlers.Refactor_Add_Parameter;
49-
with LSP.Ada_Handlers.Refactor_Remove_Parameter;
50-
with LSP.Ada_Handlers.Refactor_Move_Parameter;
51-
with LSP.Ada_Handlers.Refactor_Change_Parameter_Mode;
52-
with LSP.Ada_Handlers.Refactor_Change_Parameters_Type;
53-
with LSP.Ada_Handlers.Refactor_Change_Parameters_Default_Value;
54-
with LSP.Ada_Handlers.Refactor_Suppress_Seperate;
55-
with LSP.Ada_Handlers.Refactor_Extract_Subprogram;
56-
with LSP.Ada_Handlers.Refactor_Introduce_Parameter;
57-
with LSP.Ada_Handlers.Refactor_Pull_Up_Declaration;
58-
with LSP.Ada_Handlers.Refactor_Replace_Type;
59-
with LSP.Ada_Handlers.Refactor_Sort_Dependencies;
47+
with LSP.Ada_Handlers.Refactor.Imports_Commands;
48+
with LSP.Ada_Handlers.Refactor.Add_Parameter;
49+
with LSP.Ada_Handlers.Refactor.Remove_Parameter;
50+
with LSP.Ada_Handlers.Refactor.Move_Parameter;
51+
with LSP.Ada_Handlers.Refactor.Change_Parameter_Mode;
52+
with LSP.Ada_Handlers.Refactor.Change_Parameters_Type;
53+
with LSP.Ada_Handlers.Refactor.Change_Parameters_Default_Value;
54+
with LSP.Ada_Handlers.Refactor.Suppress_Seperate;
55+
with LSP.Ada_Handlers.Refactor.Extract_Subprogram;
56+
with LSP.Ada_Handlers.Refactor.Introduce_Parameter;
57+
with LSP.Ada_Handlers.Refactor.Pull_Up_Declaration;
58+
with LSP.Ada_Handlers.Refactor.Replace_Type;
59+
with LSP.Ada_Handlers.Refactor.Sort_Dependencies;
6060
with LSP.Commands;
6161
with LSP.Error_Decorators;
6262
with LSP.Fuzz_Decorators;
@@ -148,33 +148,33 @@ procedure LSP.Ada_Driver is
148148
LSP.Commands.Register
149149
(LSP.Ada_Handlers.Named_Parameters_Commands.Command'Tag);
150150
LSP.Commands.Register
151-
(LSP.Ada_Handlers.Refactor_Imports_Commands.Command'Tag);
151+
(LSP.Ada_Handlers.Refactor.Imports_Commands.Command'Tag);
152152
LSP.Commands.Register
153-
(LSP.Ada_Handlers.Refactor_Suppress_Seperate.Command'Tag);
153+
(LSP.Ada_Handlers.Refactor.Suppress_Seperate.Command'Tag);
154154
LSP.Commands.Register
155-
(LSP.Ada_Handlers.Refactor_Extract_Subprogram.Command'Tag);
155+
(LSP.Ada_Handlers.Refactor.Extract_Subprogram.Command'Tag);
156156
LSP.Commands.Register
157-
(LSP.Ada_Handlers.Refactor_Introduce_Parameter.Command'Tag);
157+
(LSP.Ada_Handlers.Refactor.Introduce_Parameter.Command'Tag);
158158
LSP.Commands.Register
159-
(LSP.Ada_Handlers.Refactor_Pull_Up_Declaration.Command'Tag);
159+
(LSP.Ada_Handlers.Refactor.Pull_Up_Declaration.Command'Tag);
160160
LSP.Commands.Register
161-
(LSP.Ada_Handlers.Refactor_Replace_Type.Command'Tag);
161+
(LSP.Ada_Handlers.Refactor.Replace_Type.Command'Tag);
162162
LSP.Commands.Register
163-
(LSP.Ada_Handlers.Refactor_Sort_Dependencies.Command'Tag);
163+
(LSP.Ada_Handlers.Refactor.Sort_Dependencies.Command'Tag);
164164

165165
-- Refactoring - Change Subprogram Signature Commands
166166
LSP.Commands.Register
167-
(LSP.Ada_Handlers.Refactor_Add_Parameter.Command'Tag);
167+
(LSP.Ada_Handlers.Refactor.Add_Parameter.Command'Tag);
168168
LSP.Commands.Register
169-
(LSP.Ada_Handlers.Refactor_Remove_Parameter.Command'Tag);
169+
(LSP.Ada_Handlers.Refactor.Remove_Parameter.Command'Tag);
170170
LSP.Commands.Register
171-
(LSP.Ada_Handlers.Refactor_Move_Parameter.Command'Tag);
171+
(LSP.Ada_Handlers.Refactor.Move_Parameter.Command'Tag);
172172
LSP.Commands.Register
173-
(LSP.Ada_Handlers.Refactor_Change_Parameter_Mode.Command'Tag);
173+
(LSP.Ada_Handlers.Refactor.Change_Parameter_Mode.Command'Tag);
174174
LSP.Commands.Register
175-
(LSP.Ada_Handlers.Refactor_Change_Parameters_Type.Command'Tag);
175+
(LSP.Ada_Handlers.Refactor.Change_Parameters_Type.Command'Tag);
176176
LSP.Commands.Register
177-
(LSP.Ada_Handlers.Refactor_Change_Parameters_Default_Value.
177+
(LSP.Ada_Handlers.Refactor.Change_Parameters_Default_Value.
178178
Command'Tag);
179179
end Register_Commands;
180180

source/ada/lsp-ada_handlers-refactor_add_parameter.adb renamed to source/ada/lsp-ada_handlers-refactor-add_parameter.adb

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ with Libadalang.Analysis; use Libadalang.Analysis;
2424
with LAL_Refactor.Subprogram_Signature;
2525
use LAL_Refactor.Subprogram_Signature;
2626

27-
with LSP.Common;
28-
with LSP.Messages.Client_Requests;
29-
with LSP.Lal_Utils;
30-
3127
with VSS.Strings.Conversions;
28+
with LSP.Commands;
3229

33-
package body LSP.Ada_Handlers.Refactor_Add_Parameter is
30+
package body LSP.Ada_Handlers.Refactor.Add_Parameter is
3431

3532
------------------------
3633
-- Append_Code_Action --
@@ -119,33 +116,27 @@ package body LSP.Ada_Handlers.Refactor_Add_Parameter is
119116
end return;
120117
end Create;
121118

122-
-------------
123-
-- Execute --
124-
-------------
119+
--------------
120+
-- Refactor --
121+
--------------
125122

126-
overriding procedure Execute
123+
overriding procedure Refactor
127124
(Self : Command;
128125
Handler : not null access LSP.Server_Notification_Receivers.
129126
Server_Notification_Receiver'Class;
130127
Client : not null access LSP.Client_Message_Receivers.
131128
Client_Message_Receiver'Class;
132-
Error : in out LSP.Errors.Optional_ResponseError)
129+
Edits : out LAL_Refactor.Refactoring_Edits)
133130
is
134131
use Langkit_Support.Slocs;
135132
use LAL_Refactor;
136-
use LSP.Messages;
137133
use LSP.Types;
138-
use VSS.Strings.Conversions;
139134

140135
Message_Handler : LSP.Ada_Handlers.Message_Handler renames
141136
LSP.Ada_Handlers.Message_Handler (Handler.all);
142137
Context : LSP.Ada_Contexts.Context renames
143138
Message_Handler.Contexts.Get (Self.Context_Id).all;
144139

145-
Apply : Client_Requests.Workspace_Apply_Edit_Request;
146-
Workspace_Edits : WorkspaceEdit renames Apply.params.edit;
147-
Label : Optional_Virtual_String renames Apply.params.label;
148-
149140
function Analysis_Units return Analysis_Unit_Array is
150141
(Context.Analysis_Units);
151142
-- Provides the Context Analysis_Unit_Array to the Mode_Changer
@@ -162,44 +153,9 @@ package body LSP.Ada_Handlers.Refactor_Add_Parameter is
162153
New_Parameter =>
163154
VSS.Strings.Conversions.To_Unbounded_UTF_8_String
164155
(Self.New_Parameter));
165-
Edits : constant LAL_Refactor.Refactoring_Edits :=
166-
Adder.Refactor (Analysis_Units'Access);
167-
168156
begin
169-
if Edits = No_Refactoring_Edits then
170-
Error :=
171-
(Is_Set => True,
172-
Value =>
173-
(code => LSP.Errors.UnknownErrorCode,
174-
message => VSS.Strings.Conversions.To_Virtual_String
175-
("Failed to execute the Add Parameter refactoring."),
176-
data => <>));
177-
178-
else
179-
Workspace_Edits :=
180-
LSP.Lal_Utils.To_Workspace_Edit
181-
(Edits => Edits,
182-
Resource_Operations => Message_Handler.Resource_Operations,
183-
Versioned_Documents => Message_Handler.Versioned_Documents,
184-
Document_Provider => Message_Handler'Access);
185-
Label :=
186-
(Is_Set => True,
187-
Value => To_Virtual_String (Command'External_Tag));
188-
189-
Client.On_Workspace_Apply_Edit_Request (Apply);
190-
end if;
191-
192-
exception
193-
when E : others =>
194-
LSP.Common.Log (Message_Handler.Trace, E);
195-
Error :=
196-
(Is_Set => True,
197-
Value =>
198-
(code => LSP.Errors.UnknownErrorCode,
199-
message => VSS.Strings.Conversions.To_Virtual_String
200-
("Failed to execute the Add Parameter refactoring."),
201-
data => <>));
202-
end Execute;
157+
Edits := Adder.Refactor (Analysis_Units'Access);
158+
end Refactor;
203159

204160
----------------
205161
-- Initialize --
@@ -246,4 +202,4 @@ package body LSP.Ada_Handlers.Refactor_Add_Parameter is
246202
JS.End_Object;
247203
end Write_Command;
248204

249-
end LSP.Ada_Handlers.Refactor_Add_Parameter;
205+
end LSP.Ada_Handlers.Refactor.Add_Parameter;

source/ada/lsp-ada_handlers-refactor_add_parameter.ads renamed to source/ada/lsp-ada_handlers-refactor-add_parameter.ads

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020
with Ada.Streams;
2121

2222
with LSP.Client_Message_Receivers;
23-
with LSP.Commands;
2423
with LSP.Messages;
25-
with LSP.Errors;
2624
with LSP.JSON_Streams;
2725

2826
with VSS.Strings;
2927

30-
package LSP.Ada_Handlers.Refactor_Add_Parameter is
28+
package LSP.Ada_Handlers.Refactor.Add_Parameter is
3129

32-
type Command is new LSP.Commands.Command with private;
30+
type Command is new LSP.Ada_Handlers.Refactor.Command with private;
31+
32+
overriding function Name (Self : Command) return String
33+
is
34+
("Add Parameter");
3335

3436
procedure Append_Code_Action
3537
(Self : in out Command;
@@ -41,7 +43,7 @@ package LSP.Ada_Handlers.Refactor_Add_Parameter is
4143

4244
private
4345

44-
type Command is new LSP.Commands.Command with record
46+
type Command is new LSP.Ada_Handlers.Refactor.Command with record
4547
Context_Id : VSS.Strings.Virtual_String;
4648
Where : LSP.Messages.Location;
4749
New_Parameter : VSS.Strings.Virtual_String;
@@ -55,13 +57,13 @@ private
5557
-- Reads JS and creates a new Command
5658

5759
overriding
58-
procedure Execute
60+
procedure Refactor
5961
(Self : Command;
6062
Handler : not null access
6163
LSP.Server_Notification_Receivers.Server_Notification_Receiver'Class;
6264
Client : not null access
6365
LSP.Client_Message_Receivers.Client_Message_Receiver'Class;
64-
Error : in out LSP.Errors.Optional_ResponseError);
66+
Edits : out LAL_Refactor.Refactoring_Edits);
6567
-- Executes Self by computing the necessary refactorings
6668

6769
procedure Initialize
@@ -79,4 +81,4 @@ private
7981
for Command'Write use Write_Command;
8082
for Command'External_Tag use "als-refactor-add-parameters";
8183

82-
end LSP.Ada_Handlers.Refactor_Add_Parameter;
84+
end LSP.Ada_Handlers.Refactor.Add_Parameter;

source/ada/lsp-ada_handlers-refactor_change_parameter_mode.adb renamed to source/ada/lsp-ada_handlers-refactor-change_parameter_mode.adb

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ with Libadalang.Common; use Libadalang.Common;
2222

2323
with Laltools.Common; use Laltools.Common;
2424

25-
with LSP.Common;
2625
with LSP.Messages;
27-
with LSP.Messages.Client_Requests;
2826
with LSP.Lal_Utils;
2927

3028
with VSS.Strings.Conversions;
29+
with LSP.Commands;
3130

32-
package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
31+
package body LSP.Ada_Handlers.Refactor.Change_Parameter_Mode is
3332

3433
------------------------
3534
-- Append_Code_Action --
@@ -234,23 +233,21 @@ package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
234233
end return;
235234
end Create;
236235

237-
-------------
238-
-- Execute --
239-
-------------
236+
--------------
237+
-- Refactor --
238+
--------------
240239

241240
overriding
242-
procedure Execute
241+
procedure Refactor
243242
(Self : Command;
244243
Handler : not null access LSP.Server_Notification_Receivers.
245244
Server_Notification_Receiver'Class;
246245
Client : not null access LSP.Client_Message_Receivers.
247246
Client_Message_Receiver'Class;
248-
Error : in out LSP.Errors.Optional_ResponseError)
247+
Edits : out LAL_Refactor.Refactoring_Edits)
249248
is
250249
use LAL_Refactor;
251-
use LSP.Messages;
252250
use LSP.Types;
253-
use VSS.Strings.Conversions;
254251

255252
Message_Handler : LSP.Ada_Handlers.Message_Handler renames
256253
LSP.Ada_Handlers.Message_Handler (Handler.all);
@@ -260,10 +257,6 @@ package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
260257
Document : constant LSP.Ada_Documents.Document_Access :=
261258
Message_Handler.Get_Open_Document (Self.Where.textDocument.uri);
262259

263-
Apply : Client_Requests.Workspace_Apply_Edit_Request;
264-
Workspace_Edits : WorkspaceEdit renames Apply.params.edit;
265-
Label : Optional_Virtual_String renames Apply.params.label;
266-
267260
Node : constant Ada_Node :=
268261
Document.Get_Node_At (Context, Self.Where.position);
269262

@@ -274,7 +267,6 @@ package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
274267
Last => Positive (Self.Last_Param_Index));
275268

276269
Changer : Mode_Changer;
277-
Edits : LAL_Refactor.Refactoring_Edits;
278270

279271
function Analysis_Units return Analysis_Unit_Array is
280272
(Context.Analysis_Units);
@@ -304,14 +296,14 @@ package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
304296

305297
begin
306298
if Target_Subp.Is_Null then
307-
Error :=
308-
(Is_Set => True,
309-
Value =>
310-
(code => LSP.Errors.InvalidRequest,
311-
message => VSS.Strings.To_Virtual_String
312-
("Could not execute Change Parameter Mode command. "
313-
& "The target subprogram could not be resolved precisely."),
314-
data => <>));
299+
Edits :=
300+
(Diagnostics =>
301+
[LAL_Refactor.Subprogram_Signature.Create
302+
(Subp => Node,
303+
Info => VSS.Strings.To_Virtual_String
304+
("The target subprogram could "
305+
& "not be resolved precisely."))],
306+
others => <>);
315307
return;
316308
end if;
317309

@@ -321,41 +313,7 @@ package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
321313
Value (Self.New_Mode));
322314

323315
Edits := Changer.Refactor (Analysis_Units'Access);
324-
325-
if Edits = No_Refactoring_Edits then
326-
Error :=
327-
(Is_Set => True,
328-
Value =>
329-
(code => LSP.Errors.UnknownErrorCode,
330-
message => VSS.Strings.Conversions.To_Virtual_String
331-
("Failed to execute the Change Parameter Mode refactoring."),
332-
data => <>));
333-
334-
else
335-
Workspace_Edits :=
336-
LSP.Lal_Utils.To_Workspace_Edit
337-
(Edits => Edits,
338-
Resource_Operations => Message_Handler.Resource_Operations,
339-
Versioned_Documents => Message_Handler.Versioned_Documents,
340-
Document_Provider => Message_Handler'Access);
341-
Label :=
342-
(Is_Set => True,
343-
Value => To_Virtual_String (Command'External_Tag));
344-
345-
Client.On_Workspace_Apply_Edit_Request (Apply);
346-
end if;
347-
348-
exception
349-
when E : others =>
350-
LSP.Common.Log (Message_Handler.Trace, E);
351-
Error :=
352-
(Is_Set => True,
353-
Value =>
354-
(code => LSP.Errors.UnknownErrorCode,
355-
message => VSS.Strings.Conversions.To_Virtual_String
356-
("Failed to execute the Change Parameter Mode refactoring."),
357-
data => <>));
358-
end Execute;
316+
end Refactor;
359317

360318
----------------
361319
-- Initialize --
@@ -400,4 +358,4 @@ package body LSP.Ada_Handlers.Refactor_Change_Parameter_Mode is
400358
LSP.Types.Write_String (S, C.New_Mode);
401359
JS.End_Object;
402360
end Write_Command;
403-
end LSP.Ada_Handlers.Refactor_Change_Parameter_Mode;
361+
end LSP.Ada_Handlers.Refactor.Change_Parameter_Mode;

0 commit comments

Comments
 (0)