Skip to content

Commit b4573a8

Browse files
BoulangerAdrienBoulanger
authored andcommitted
Fix calls sending diagnostics directly
1 parent 8b458f3 commit b4573a8

File tree

2 files changed

+79
-70
lines changed

2 files changed

+79
-70
lines changed

source/ada/lsp-ada_configurations.ads

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ package LSP.Ada_Configurations is
9494

9595
function GPR_File_Diagnostics_Enabled
9696
(Self : Configuration'Class) return Boolean;
97-
-- Wheter to publish gpr file related diagnostics. This is used by the
98-
-- GLS only and is different from Project_Diagnostics_Enabled.
97+
-- Whether to publish diagnostics related to GPR files' edition. This
98+
-- is used by GLS only and is different from Project_Diagnostics_Enabled.
9999

100100
function Project_Diagnostics_Enabled
101101
(Self : Configuration'Class) return Boolean;

source/ada/lsp-ada_handlers.adb

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,50 +3076,53 @@ package body LSP.Ada_Handlers is
30763076

30773077
if not Errors.Is_Empty then
30783078
declare
3079-
Template : constant
3080-
VSS.Strings.Templates.Virtual_String_Template :=
3079+
use type LSP.Ada_Documents.Document_Access;
3080+
Template :
3081+
constant VSS.Strings.Templates.Virtual_String_Template :=
30813082
"Can't rename identifier '{}'";
3082-
Message : constant VSS.Strings.Virtual_String :=
3083+
Message : constant VSS.Strings.Virtual_String :=
30833084
Template.Format
30843085
(LSP.Formatters.Texts.Image (Name_Node.Text));
30853086

3086-
Diag_Params : LSP.Structures.PublishDiagnosticsParams;
30873087
Diagnostic : LSP.Structures.Diagnostic;
3088-
3088+
Loc : constant LSP.Structures.Location :=
3089+
Self.To_LSP_Location (Name_Node);
3090+
Document : constant LSP.Ada_Documents.Document_Access :=
3091+
Get_Open_Document (Self, Loc.uri);
30893092
begin
3090-
Diagnostic.a_range :=
3091-
Self.To_LSP_Location (Name_Node).a_range;
3092-
Diagnostic.severity := LSP.Constants.Error;
3093-
Diagnostic.source := "Ada";
3094-
3095-
if Self.Client.Supports_Related_Diagnostics then
3096-
3097-
Diagnostic.message := Message;
3098-
3099-
for Problem of Errors loop
3100-
Diagnostic.relatedInformation.Append
3101-
(LSP.Structures.DiagnosticRelatedInformation'
3102-
(location =>
3103-
LSP.Ada_Handlers.Locations.To_LSP_Location
3104-
(Self,
3105-
C.all,
3106-
Problem.Filename,
3107-
Problem.Location),
3108-
3109-
message =>
3110-
VSS.Strings.Conversions.To_Virtual_String
3111-
(Problem.Info)));
3112-
end loop;
3113-
else
3114-
Diagnostic.message :=
3115-
VSS.Strings.Conversions.To_Virtual_String
3116-
(Errors.First_Element.Info);
3093+
if Document /= null then
3094+
Diagnostic.a_range := Loc.a_range;
3095+
Diagnostic.severity := LSP.Constants.Error;
3096+
Diagnostic.source := "Ada";
3097+
3098+
if Self.Client.Supports_Related_Diagnostics then
3099+
3100+
Diagnostic.message := Message;
3101+
3102+
for Problem of Errors loop
3103+
Diagnostic.relatedInformation.Append
3104+
(LSP.Structures.DiagnosticRelatedInformation'
3105+
(location =>
3106+
LSP.Ada_Handlers.Locations.To_LSP_Location
3107+
(Self,
3108+
C.all,
3109+
Problem.Filename,
3110+
Problem.Location),
3111+
3112+
message =>
3113+
VSS.Strings.Conversions.To_Virtual_String
3114+
(Problem.Info)));
3115+
end loop;
3116+
else
3117+
Diagnostic.message :=
3118+
VSS.Strings.Conversions.To_Virtual_String
3119+
(Errors.First_Element.Info);
31173120

3121+
end if;
3122+
Self.Publish_Diagnostics
3123+
(Document => Document,
3124+
Other_Diagnostics => [Diagnostic]);
31183125
end if;
3119-
3120-
Diag_Params.uri := Value.textDocument.uri;
3121-
Diag_Params.diagnostics.Append (Diagnostic);
3122-
Self.Sender.On_PublishDiagnostics_Notification (Diag_Params);
31233126
exit;
31243127
end;
31253128
end if;
@@ -3819,44 +3822,50 @@ package body LSP.Ada_Handlers is
38193822

38203823
if Result_Kind in Libadalang.Common.Error then
38213824
declare
3825+
use type LSP.Ada_Documents.Document_Access;
38223826
Err_Msg : constant String :=
38233827
"Failed to resolve " & Name_Node.Image;
3824-
Diag_Params : LSP.Structures.PublishDiagnosticsParams;
38253828
Diagnostic : LSP.Structures.Diagnostic;
38263829
Loc : constant LSP.Structures.Location :=
38273830
Self.To_LSP_Location (Name_Node);
3831+
Document : constant LSP.Ada_Documents.Document_Access :=
3832+
Get_Open_Document (Self, Loc.uri);
38283833
begin
3829-
-- Internal tracing of failed resolution with context info
3830-
Self.Tracer.Trace
3831-
(Err_Msg
3832-
& " in context "
3833-
& VSS.Strings.Conversions.To_UTF_8_String (Context.Id)
3834-
& " for request "
3835-
& Id_Image);
3836-
3837-
-- Send a diagnostic for the user
3838-
Diagnostic.a_range := Loc.a_range;
3839-
Diagnostic.severity := LSP.Constants.Error;
3840-
Diagnostic.source := "Ada";
3841-
-- Diagnostics are shown to the user so show a simple
3842-
-- representation of Namer_Node
3843-
Diagnostic.message :=
3844-
VSS.Strings.Conversions.To_Virtual_String
3845-
("Failed to resolve "
3846-
& Langkit_Support.Text.To_UTF8 (Name_Node.Text)
3847-
& Ada.Characters.Latin_1.LF
3848-
& "Please check the output of the following command:"
3849-
& Ada.Characters.Latin_1.LF
3850-
& " lal_nameres -P "
3851-
& String
3852-
(Self.Project_Tree.Root_Project.Path_Name.Filesystem_String)
3853-
& " --all --only-show-failures "
3854-
& VSS.Strings.Conversions.To_UTF_8_String (Loc.uri));
3855-
3856-
Diag_Params.uri := Loc.uri;
3857-
Diag_Params.diagnostics.Append (Diagnostic);
3858-
Self.Sender.On_PublishDiagnostics_Notification (Diag_Params);
3859-
3834+
if Document /= null then
3835+
-- Internal tracing of failed resolution with context info
3836+
Self.Tracer.Trace
3837+
(Err_Msg
3838+
& " in context "
3839+
& VSS.Strings.Conversions.To_UTF_8_String (Context.Id)
3840+
& " for request "
3841+
& Id_Image);
3842+
3843+
-- Send a diagnostic for the user
3844+
Diagnostic.a_range := Loc.a_range;
3845+
Diagnostic.severity := LSP.Constants.Error;
3846+
Diagnostic.source := "Ada";
3847+
-- Diagnostics are shown to the user so show a simple
3848+
-- representation of Namer_Node
3849+
Diagnostic.message :=
3850+
VSS.Strings.Conversions.To_Virtual_String
3851+
("Failed to resolve "
3852+
& Langkit_Support.Text.To_UTF8 (Name_Node.Text)
3853+
& Ada.Characters.Latin_1.LF
3854+
& "Please check the output of the following command:"
3855+
& Ada.Characters.Latin_1.LF
3856+
& " lal_nameres -P "
3857+
& String
3858+
(Self
3859+
.Project_Tree
3860+
.Root_Project
3861+
.Path_Name
3862+
.Filesystem_String)
3863+
& " --all --only-show-failures "
3864+
& VSS.Strings.Conversions.To_UTF_8_String (Loc.uri));
3865+
3866+
Self.Publish_Diagnostics
3867+
(Document => Document, Other_Diagnostics => [Diagnostic]);
3868+
end if;
38603869
-- Inform the client that the request failed
38613870
Self.Sender.On_Error_Response
38623871
(Id,

0 commit comments

Comments
 (0)