Skip to content

Commit 2004eed

Browse files
Clear source info diagnostics when the option changes
Improve existing test to cover this case. For eng/ide/ada_language_server#1593
1 parent e641912 commit 2004eed

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

source/ada/lsp-ada_documents-source_info_diagnostics.adb

Lines changed: 11 additions & 1 deletion
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,6 +42,14 @@ 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

@@ -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

source/ada/lsp-ada_documents-source_info_diagnostics.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

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)