Skip to content

Commit ee376ae

Browse files
Merge branch 'topic/source_info_diags' into 'master'
Clear source info diagnostics when option changes See merge request eng/ide/ada_language_server!1991
2 parents 3b59412 + 2004eed commit ee376ae

File tree

7 files changed

+50
-11
lines changed

7 files changed

+50
-11
lines changed

source/ada/lsp-ada_documents-lal_diagnostics.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package body LSP.Ada_Documents.LAL_Diagnostics is
2929
-- Get_Diagnostic --
3030
--------------------
3131

32-
overriding procedure Get_Diagnostic
32+
overriding procedure Get_Diagnostics
3333
(Self : in out Diagnostic_Source;
3434
Context : LSP.Ada_Contexts.Context;
3535
Errors : out LSP.Structures.Diagnostic_Vector)
@@ -49,7 +49,7 @@ package body LSP.Ada_Documents.LAL_Diagnostics is
4949

5050
Errors.Append (Item);
5151
end loop;
52-
end Get_Diagnostic;
52+
end Get_Diagnostics;
5353

5454
------------------------
5555
-- Has_New_Diagnostic --

source/ada/lsp-ada_documents-lal_diagnostics.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package LSP.Ada_Documents.LAL_Diagnostics is
2626
Document : not null LSP.Ada_Documents.Document_Access)
2727
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with private;
2828

29-
overriding procedure Get_Diagnostic
29+
overriding procedure Get_Diagnostics
3030
(Self : in out Diagnostic_Source;
3131
Context : LSP.Ada_Contexts.Context;
3232
Errors : out LSP.Structures.Diagnostic_Vector);

source/ada/lsp-ada_documents-source_info_diagnostics.adb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ package body LSP.Ada_Documents.Source_Info_Diagnostics is
3232

3333
Current_Project_Stamp : constant LSP.Ada_Handlers.Project_Stamp :=
3434
Self.Handler.Get_Project_Stamp;
35+
Is_Enabled : constant Boolean :=
36+
Self.Handler.Source_Info_Diagnostics_Enabled;
3537
begin
3638
-- The project has been reloaded: compute source information diagnostics
3739
-- again since the set of source files might have been changed.
@@ -40,15 +42,23 @@ package body LSP.Ada_Documents.Source_Info_Diagnostics is
4042
return True;
4143
end if;
4244

45+
-- The 'sourceInfoDiagnostics' option has just changed: always return
46+
-- True in this case (e.g: to clear any existing diagnostic when the
47+
-- option gets disabled)
48+
if Self.Enabled /= Is_Enabled then
49+
Self.Enabled := Is_Enabled;
50+
return True;
51+
end if;
52+
4353
return False;
4454
end Has_New_Diagnostic;
4555

46-
--------------------
56+
---------------------
4757
-- Get_Diagnostics --
48-
--------------------
58+
---------------------
4959

5060
overriding
51-
procedure Get_Diagnostic
61+
procedure Get_Diagnostics
5262
(Self : in out Diagnostic_Source;
5363
Context : LSP.Ada_Contexts.Context;
5464
Errors : out LSP.Structures.Diagnostic_Vector)
@@ -57,7 +67,7 @@ package body LSP.Ada_Documents.Source_Info_Diagnostics is
5767
-- If the unit associated to the document belongs to the fallback context
5868
-- it means that the document's file does not belong the loaded project:
5969
-- emit a hint diagnostic in that case.
60-
if Context.Is_Fallback_Context then
70+
if Self.Is_Enabled and then Context.Is_Fallback_Context then
6171
declare
6272
Diag_Msg : constant String :=
6373
(if Self.Handler.Get_Project_Status.Is_Project_Loaded
@@ -78,7 +88,7 @@ package body LSP.Ada_Documents.Source_Info_Diagnostics is
7888
others => <>));
7989
end;
8090
end if;
81-
end Get_Diagnostic;
91+
end Get_Diagnostics;
8292

8393
----------------
8494
-- Is_Enabled --

source/ada/lsp-ada_documents-source_info_diagnostics.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package LSP.Ada_Documents.Source_Info_Diagnostics is
2828
Document : not null LSP.Ada_Documents.Document_Access)
2929
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with private;
3030

31-
overriding procedure Get_Diagnostic
31+
overriding procedure Get_Diagnostics
3232
(Self : in out Diagnostic_Source;
3333
Context : LSP.Ada_Contexts.Context;
3434
Errors : out LSP.Structures.Diagnostic_Vector);
@@ -51,6 +51,10 @@ private
5151
-- Used to detect when the project has been reloaded.
5252
-- We want to update source information diagnostics only after
5353
-- project reloade.
54+
55+
Enabled : Boolean := True;
56+
-- Used to keep track of the 'sourceInfoDiagnostics' option, which
57+
-- enables/disables source information diagnostics.
5458
end record;
5559

5660
end LSP.Ada_Documents.Source_Info_Diagnostics;

source/ada/lsp-ada_documents.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ package body LSP.Ada_Documents is
966966

967967
if Changed or else Force then
968968
for Source of Self.Diagnostic_Sources loop
969-
Source.Get_Diagnostic (Context, Errors);
969+
Source.Get_Diagnostics (Context, Errors);
970970
end loop;
971971
end if;
972972
end Get_Errors;

source/ada/lsp-diagnostic_sources.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ package LSP.Diagnostic_Sources is
3333
LSP.Diagnostic_Sources.Diagnostic_Source_Access,
3434
LSP.Diagnostic_Sources."=");
3535

36-
procedure Get_Diagnostic
36+
procedure Get_Diagnostics
3737
(Self : in out Diagnostic_Source;
3838
Context : LSP.Ada_Contexts.Context;
3939
Errors : out LSP.Structures.Diagnostic_Vector) is abstract;

testsuite/ada_lsp/diagnostics.source_information/test.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@
112112
]
113113
}
114114
},
115+
{
116+
"send": {
117+
"request": {
118+
"jsonrpc": "2.0",
119+
"method": "workspace/didChangeConfiguration",
120+
"params": {
121+
"settings": {
122+
"ada": {
123+
"projectFile": "$URI{default.gpr}",
124+
"sourceInfoDiagnostics": false
125+
}
126+
}
127+
}
128+
},
129+
"wait": [
130+
{
131+
"method": "textDocument/publishDiagnostics",
132+
"params": {
133+
"uri": "$URI{main.adb}",
134+
"diagnostics": []
135+
}
136+
}
137+
]
138+
}
139+
},
115140
{
116141
"stop": {
117142
"exit_code": 0

0 commit comments

Comments
 (0)