@@ -1147,6 +1147,17 @@ package body LSP.Ada_Handlers is
1147
1147
Self.Line_Folding_Only := True;
1148
1148
end if ;
1149
1149
1150
+ if Value.capabilities.textDocument.publishDiagnostics.Is_Set
1151
+ and then Value.capabilities.textDocument.publishDiagnostics.Value.
1152
+ relatedInformation.Is_Set
1153
+ then
1154
+ -- Client capability to support relatedInformation field in
1155
+ -- diagnostics.
1156
+ Self.Supports_Related_Diagnostics :=
1157
+ Value.capabilities.textDocument.publishDiagnostics.Value.
1158
+ relatedInformation.Value;
1159
+ end if ;
1160
+
1150
1161
if Value.capabilities.textDocument.completion.completionItem.Is_Set
1151
1162
and then Value.capabilities.textDocument.completion.
1152
1163
completionItem.Value.snippetSupport = True
@@ -3887,15 +3898,29 @@ package body LSP.Ada_Handlers is
3887
3898
-- possible to encounter the same Text_Edit more than once, so this
3888
3899
-- stores all the unique edits
3889
3900
3890
- procedure Process_Context (C : Context_Access);
3901
+ Definition_Node : Defining_Name;
3902
+ -- Used to retrieve the definition node found for a given context
3903
+
3904
+ procedure Process_Context
3905
+ (C : Context_Access;
3906
+ Definition_Node : out Defining_Name);
3891
3907
-- Process the rename request for the given context, and add the
3892
3908
-- edits to `All_Edits`.
3893
3909
3910
+ function To_LSP_Diagnostic
3911
+ (Problem : Laltools.Refactor.Refactoring_Diagnotic'Class;
3912
+ Definition_Node : Defining_Name)
3913
+ return LSP.Messages.Diagnostic;
3914
+ -- Convert a laltool refactoring diagnostic into a LSP one.
3915
+
3894
3916
-- -------------------
3895
3917
-- Process_Context --
3896
3918
-- -------------------
3897
3919
3898
- procedure Process_Context (C : Context_Access) is
3920
+ procedure Process_Context
3921
+ (C : Context_Access;
3922
+ Definition_Node : out Defining_Name)
3923
+ is
3899
3924
use GNATCOLL.Projects;
3900
3925
use Laltools.Refactor.Safe_Rename;
3901
3926
@@ -4145,6 +4170,8 @@ package body LSP.Ada_Handlers is
4145
4170
end Process_References ;
4146
4171
4147
4172
begin
4173
+ Definition_Node := Definition;
4174
+
4148
4175
if Definition.Is_Null then
4149
4176
return ;
4150
4177
end if ;
@@ -4169,31 +4196,94 @@ package body LSP.Ada_Handlers is
4169
4196
Process_File_Renames;
4170
4197
end Process_Context ;
4171
4198
4199
+ -- ---------------------
4200
+ -- To_LSP_Diagnostic --
4201
+ -- ---------------------
4202
+
4203
+ function To_LSP_Diagnostic
4204
+ (Problem : Laltools.Refactor.Refactoring_Diagnotic'Class;
4205
+ Definition_Node : Defining_Name)
4206
+ return LSP.Messages.Diagnostic
4207
+ is
4208
+ Diagnostic : LSP.Messages.Diagnostic;
4209
+ begin
4210
+ Diagnostic := LSP.Messages.Diagnostic'
4211
+ (span =>
4212
+ To_Span (Definition_Node.Sloc_Range),
4213
+ severity => (True, LSP.Messages.Error),
4214
+ code => <>,
4215
+ codeDescription => <>,
4216
+ source =>
4217
+ (True, To_Virtual_String (" Ada" )),
4218
+ message =>
4219
+ (if Self.Supports_Related_Diagnostics then
4220
+ VSS.Strings.Conversions.To_Virtual_String
4221
+ (" Can't rename identifier '"
4222
+ & Langkit_Support.Text.To_UTF8
4223
+ (Definition_Node.Text)
4224
+ & " '" )
4225
+ else VSS.Strings.Conversions.To_Virtual_String
4226
+ (Problem.Info)),
4227
+ tags => <>,
4228
+ relatedInformation => <>);
4229
+
4230
+ if Self.Supports_Related_Diagnostics then
4231
+ Diagnostic.relatedInformation.Append
4232
+ (LSP.Messages.DiagnosticRelatedInformation'(
4233
+ location => LSP.Messages.Location'
4234
+ (uri => File_To_URI (Problem.Filename),
4235
+ span => To_Span (Problem.Location),
4236
+ alsKind => <>),
4237
+ message => VSS.Strings.Conversions.To_Virtual_String
4238
+ (Problem.Info)));
4239
+ end if ;
4240
+
4241
+ return Diagnostic;
4242
+ end To_LSP_Diagnostic ;
4243
+
4172
4244
begin
4173
4245
for C of Self.Contexts_For_URI (Value.textDocument.uri) loop
4174
- Process_Context (C);
4246
+ Process_Context (C, Definition_Node );
4175
4247
4176
- -- If problems were found, send an error message and do not proceed
4177
- -- with the renames.
4248
+ -- If problems were found, send an error reponse and a diagnostic for
4249
+ -- each issue. Do not proceed with the renames.
4178
4250
4179
4251
if not Context_Edits.Diagnostics.Is_Empty then
4180
4252
return Response : LSP.Messages.Server_Responses.Rename_Response
4181
4253
(Is_Error => True)
4182
4254
do
4183
4255
declare
4184
- Error_Message : VSS.String_Vectors.Virtual_String_Vector ;
4185
-
4256
+ Diag_Params : LSP.Messages.PublishDiagnosticsParams ;
4257
+ Diagnostic : LSP.Messages.Diagnostic;
4186
4258
begin
4259
+ -- For each problem detected in a given file by laltools,
4260
+ -- convert it to a LSP diagnostic and publish them when
4261
+ -- switching to another file.
4262
+
4187
4263
for Problem of Context_Edits.Diagnostics loop
4188
- Error_Message.Append
4189
- (VSS.Strings.Conversions.To_Virtual_String
4190
- (Problem.Info));
4264
+ Diagnostic := To_LSP_Diagnostic
4265
+ (Problem, Definition_Node);
4266
+
4267
+ if To_UTF_8_String (Diag_Params.uri) = " " or else
4268
+ To_UTF_8_String (Diag_Params.uri) = Problem.Filename
4269
+ then
4270
+ Diag_Params.diagnostics.Append (Diagnostic);
4271
+ Diag_Params.uri := Value.textDocument.uri;
4272
+ else
4273
+ Self.Server.On_Publish_Diagnostics (Diag_Params);
4274
+ Diag_Params.uri := File_To_URI (" " );
4275
+ Diag_Params.diagnostics.Clear;
4276
+ end if ;
4191
4277
end loop ;
4192
4278
4279
+ if not Diag_Params.diagnostics.Is_Empty then
4280
+ Self.Server.On_Publish_Diagnostics (Diag_Params);
4281
+ end if ;
4282
+
4193
4283
Response.error :=
4194
4284
(True,
4195
- (code => LSP.Errors.InvalidRequest ,
4196
- message => Error_Message.Join_Lines (VSS.Strings.LF) ,
4285
+ (code => LSP.Errors.RequestFailed ,
4286
+ message => <> ,
4197
4287
data => Empty));
4198
4288
end ;
4199
4289
end return ;
@@ -6159,16 +6249,16 @@ package body LSP.Ada_Handlers is
6159
6249
(Self : access Message_Handler'Class;
6160
6250
Document : not null LSP.Ada_Documents.Document_Access)
6161
6251
is
6162
- Ok : Boolean;
6163
- Diag : LSP.Messages.PublishDiagnosticsParams;
6252
+ Changed : Boolean;
6253
+ Diag : LSP.Messages.PublishDiagnosticsParams;
6164
6254
begin
6165
6255
if Self.Diagnostics_Enabled then
6166
6256
Document.Get_Errors
6167
- (Self.Contexts.Get_Best_Context (Document.URI).all ,
6168
- Ok ,
6169
- Diag.diagnostics);
6257
+ (Context => Self.Contexts.Get_Best_Context (Document.URI).all ,
6258
+ Changed => Changed ,
6259
+ Errors => Diag.diagnostics);
6170
6260
6171
- if Ok then
6261
+ if Changed then
6172
6262
Diag.uri := Document.URI;
6173
6263
Self.Server.On_Publish_Diagnostics (Diag);
6174
6264
end if ;
0 commit comments