@@ -1184,6 +1184,17 @@ package body LSP.Ada_Handlers is
1184
1184
Self.Line_Folding_Only := True;
1185
1185
end if ;
1186
1186
1187
+ if Value.capabilities.textDocument.publishDiagnostics.Is_Set
1188
+ and then Value.capabilities.textDocument.publishDiagnostics.Value.
1189
+ relatedInformation.Is_Set
1190
+ then
1191
+ -- Client capability to support relatedInformation field in
1192
+ -- diagnostics.
1193
+ Self.Supports_Related_Diagnostics :=
1194
+ Value.capabilities.textDocument.publishDiagnostics.Value.
1195
+ relatedInformation.Value;
1196
+ end if ;
1197
+
1187
1198
if Value.capabilities.textDocument.completion.completionItem.Is_Set
1188
1199
and then Value.capabilities.textDocument.completion.
1189
1200
completionItem.Value.snippetSupport = True
@@ -3924,15 +3935,29 @@ package body LSP.Ada_Handlers is
3924
3935
-- possible to encounter the same Text_Edit more than once, so this
3925
3936
-- stores all the unique edits
3926
3937
3927
- procedure Process_Context (C : Context_Access);
3938
+ Definition_Node : Defining_Name;
3939
+ -- Used to retrieve the definition node found for a given context
3940
+
3941
+ procedure Process_Context
3942
+ (C : Context_Access;
3943
+ Definition_Node : out Defining_Name);
3928
3944
-- Process the rename request for the given context, and add the
3929
3945
-- edits to `All_Edits`.
3930
3946
3947
+ function To_LSP_Diagnostic
3948
+ (Problem : Laltools.Refactor.Refactoring_Diagnotic'Class;
3949
+ Definition_Node : Defining_Name)
3950
+ return LSP.Messages.Diagnostic;
3951
+ -- Convert a laltool refactoring diagnostic into a LSP one.
3952
+
3931
3953
-- -------------------
3932
3954
-- Process_Context --
3933
3955
-- -------------------
3934
3956
3935
- procedure Process_Context (C : Context_Access) is
3957
+ procedure Process_Context
3958
+ (C : Context_Access;
3959
+ Definition_Node : out Defining_Name)
3960
+ is
3936
3961
use Laltools.Refactor.Safe_Rename;
3937
3962
3938
3963
Node : constant Ada_Node := C.Get_Node_At (Document, Position);
@@ -4182,6 +4207,8 @@ package body LSP.Ada_Handlers is
4182
4207
end Process_References ;
4183
4208
4184
4209
begin
4210
+ Definition_Node := Definition;
4211
+
4185
4212
if Definition.Is_Null then
4186
4213
return ;
4187
4214
end if ;
@@ -4206,31 +4233,94 @@ package body LSP.Ada_Handlers is
4206
4233
Process_File_Renames;
4207
4234
end Process_Context ;
4208
4235
4236
+ -- ---------------------
4237
+ -- To_LSP_Diagnostic --
4238
+ -- ---------------------
4239
+
4240
+ function To_LSP_Diagnostic
4241
+ (Problem : Laltools.Refactor.Refactoring_Diagnotic'Class;
4242
+ Definition_Node : Defining_Name)
4243
+ return LSP.Messages.Diagnostic
4244
+ is
4245
+ Diagnostic : LSP.Messages.Diagnostic;
4246
+ begin
4247
+ Diagnostic := LSP.Messages.Diagnostic'
4248
+ (span =>
4249
+ To_Span (Definition_Node.Sloc_Range),
4250
+ severity => (True, LSP.Messages.Error),
4251
+ code => <>,
4252
+ codeDescription => <>,
4253
+ source =>
4254
+ (True, To_Virtual_String (" Ada" )),
4255
+ message =>
4256
+ (if Self.Supports_Related_Diagnostics then
4257
+ VSS.Strings.Conversions.To_Virtual_String
4258
+ (" Can't rename identifier '"
4259
+ & Langkit_Support.Text.To_UTF8
4260
+ (Definition_Node.Text)
4261
+ & " '" )
4262
+ else VSS.Strings.Conversions.To_Virtual_String
4263
+ (Problem.Info)),
4264
+ tags => <>,
4265
+ relatedInformation => <>);
4266
+
4267
+ if Self.Supports_Related_Diagnostics then
4268
+ Diagnostic.relatedInformation.Append
4269
+ (LSP.Messages.DiagnosticRelatedInformation'(
4270
+ location => LSP.Messages.Location'
4271
+ (uri => File_To_URI (Problem.Filename),
4272
+ span => To_Span (Problem.Location),
4273
+ alsKind => <>),
4274
+ message => VSS.Strings.Conversions.To_Virtual_String
4275
+ (Problem.Info)));
4276
+ end if ;
4277
+
4278
+ return Diagnostic;
4279
+ end To_LSP_Diagnostic ;
4280
+
4209
4281
begin
4210
4282
for C of Self.Contexts_For_URI (Value.textDocument.uri) loop
4211
- Process_Context (C);
4283
+ Process_Context (C, Definition_Node );
4212
4284
4213
- -- If problems were found, send an error message and do not proceed
4214
- -- with the renames.
4285
+ -- If problems were found, send an error reponse and a diagnostic for
4286
+ -- each issue. Do not proceed with the renames.
4215
4287
4216
4288
if not Context_Edits.Diagnostics.Is_Empty then
4217
4289
return Response : LSP.Messages.Server_Responses.Rename_Response
4218
4290
(Is_Error => True)
4219
4291
do
4220
4292
declare
4221
- Error_Message : VSS.String_Vectors.Virtual_String_Vector ;
4222
-
4293
+ Diag_Params : LSP.Messages.PublishDiagnosticsParams ;
4294
+ Diagnostic : LSP.Messages.Diagnostic;
4223
4295
begin
4296
+ -- For each problem detected in a given file by laltools,
4297
+ -- convert it to a LSP diagnostic and publish them when
4298
+ -- switching to another file.
4299
+
4224
4300
for Problem of Context_Edits.Diagnostics loop
4225
- Error_Message.Append
4226
- (VSS.Strings.Conversions.To_Virtual_String
4227
- (Problem.Info));
4301
+ Diagnostic := To_LSP_Diagnostic
4302
+ (Problem, Definition_Node);
4303
+
4304
+ if To_UTF_8_String (Diag_Params.uri) = " " or else
4305
+ To_UTF_8_String (Diag_Params.uri) = Problem.Filename
4306
+ then
4307
+ Diag_Params.diagnostics.Append (Diagnostic);
4308
+ Diag_Params.uri := Value.textDocument.uri;
4309
+ else
4310
+ Self.Server.On_Publish_Diagnostics (Diag_Params);
4311
+ Diag_Params.uri := File_To_URI (" " );
4312
+ Diag_Params.diagnostics.Clear;
4313
+ end if ;
4228
4314
end loop ;
4229
4315
4316
+ if not Diag_Params.diagnostics.Is_Empty then
4317
+ Self.Server.On_Publish_Diagnostics (Diag_Params);
4318
+ end if ;
4319
+
4230
4320
Response.error :=
4231
4321
(True,
4232
- (code => LSP.Errors.InvalidRequest ,
4233
- message => Error_Message.Join_Lines (VSS.Strings.LF) ,
4322
+ (code => LSP.Errors.RequestFailed ,
4323
+ message => <> ,
4234
4324
data => Empty));
4235
4325
end ;
4236
4326
end return ;
@@ -6389,16 +6479,16 @@ package body LSP.Ada_Handlers is
6389
6479
(Self : access Message_Handler'Class;
6390
6480
Document : not null LSP.Ada_Documents.Document_Access)
6391
6481
is
6392
- Ok : Boolean;
6393
- Diag : LSP.Messages.PublishDiagnosticsParams;
6482
+ Changed : Boolean;
6483
+ Diag : LSP.Messages.PublishDiagnosticsParams;
6394
6484
begin
6395
6485
if Self.Diagnostics_Enabled then
6396
6486
Document.Get_Errors
6397
- (Self.Contexts.Get_Best_Context (Document.URI).all ,
6398
- Ok ,
6399
- Diag.diagnostics);
6487
+ (Context => Self.Contexts.Get_Best_Context (Document.URI).all ,
6488
+ Changed => Changed ,
6489
+ Errors => Diag.diagnostics);
6400
6490
6401
- if Ok then
6491
+ if Changed then
6402
6492
Diag.uri := Document.URI;
6403
6493
Self.Server.On_Publish_Diagnostics (Diag);
6404
6494
end if ;
0 commit comments