Skip to content

Commit 52720e6

Browse files
BoulangerAdrienBoulanger
authored andcommitted
Revamp setting for diagnostics
Create a setting for each of the sources: alire, project, ada file. Add a concept of "Is_Enabled" to allow disabling/enabling diagnostics without restarting the server. Adapt the documentation and the tests. For eng/ide/ada_language_server#1455
1 parent ea53a2a commit 52720e6

File tree

175 files changed

+433
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+433
-288
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Here is an example config file:
146146
"BINUTILS_SRC_DIR": "/null"
147147
},
148148
"ada.defaultCharset": "utf-8",
149-
"ada.enableDiagnostics": false,
149+
"ada.adaFileDiagnostics": false,
150150
"ada.renameInComments": false
151151
}
152152
```

doc/settings.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ Settings understood by the Ada Language Server itself, independently from the LS
106106
* [defaultCharset](#defaultcharset)
107107
* [relocateBuildTree](#relocatebuildtree)
108108
* [rootDir](#rootdir)
109-
* [enableDiagnostics](#enablediagnostics)
109+
* [enableDiagnostics](#enableddiagnostics)
110+
* [adaFileDiagnostics](#adafilediagnostics)
110111
* [projectDiagnostics](#projectdiagnostics)
112+
* [alireDiagnostics](#alirediagnostics)
111113
* [enableIndexing](#enableindexing)
112114
* [renameInComments](#renameincomments)
113115
* [namedNotationThreshold](#namednotationthreshold)
@@ -217,27 +219,47 @@ for more details about the corresponding gprbuild switch.
217219

218220
### enableDiagnostics
219221

220-
You can explicitly deactivate the emission of diagnostics, via the
221-
`enableDiagnostics` key. By default, diagnostics are enabled.
222-
The value is a boolean.
222+
This setting has been deprecated please have a look at `projectDiagnostics`,
223+
`adaFileDiagnostics` and `alireDiagnostics`.
223224

224225
```javascript
225226
'enableDiagnostics': false
226227
```
227228

229+
### adaFileDiagnostics
230+
231+
You can explicitly deactivate the emission of diagnostics for Ada Files
232+
via the `adaFileDiagnostics` key. By default, diagnostics are enabled.
233+
The value is a boolean.
234+
235+
```javascript
236+
'adaFileDiagnostics': false
237+
```
238+
228239
### projectDiagnostics
229240

230-
This setting needs `enableDiagnostics` enabled and can be disabled to remove
231-
project related diagnotics.
241+
You can explicitly deactivate the emission of diagnostics when loading a
242+
project via the `projectDiagnostics` key. By default, diagnostics are enabled.
232243
The value is a boolean.
233244

234245
```javascript
235-
'enableDiagnostics': false
246+
'projectDiagnostics': false
247+
```
248+
249+
### alireDiagnostics
250+
251+
You can explicitly deactivate the emission of diagnostics when loading an
252+
alire crate via the `alireDiagnostics` key.
253+
By default, diagnostics are enabled.
254+
The value is a boolean.
255+
256+
```javascript
257+
'alireDiagnostics': false
236258
```
237259

238260
### enableIndexing
239261

240-
By default, the server indexes the source files after loading a project,
262+
By default, the server indexes the source files after loading a project
241263
to speed up subsequent requests. This behavior can be controlled
242264
via the `enableIndexing` flag in this request.
243265
The value is a boolean.

integration/vscode/ada/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@
308308
"scope": "window",
309309
"type": "boolean",
310310
"default": null,
311-
"description": "Controls whether or not the Ada Language Server should emit project diagnostics into the VS Code Problems view.\n\nNote: this setting is ignored if `ada.enableDiagnostics` is disabled and a workspace reload is necessary to refresh the diagnostics after modifying this setting."
311+
"description": "Controls whether or not the Ada Language Server should emit project diagnostics into the VS Code Problems view."
312+
},
313+
"ada.alireDiagnostics": {
314+
"scope": "window",
315+
"type": "boolean",
316+
"default": null,
317+
"description": "Controls whether or not the Ada Language Server should emit diagnostics related to alire into the VS Code Problems view."
312318
},
313319
"ada.defaultCharset": {
314320
"scope": "window",
@@ -392,11 +398,11 @@
392398
"default": null,
393399
"description": "Controls the policy for displaying overriding and overridden subprograms on navigation requests such as 'Go To Definition' or 'Go To Implementations'."
394400
},
395-
"ada.enableDiagnostics": {
401+
"ada.adaFileDiagnostics": {
396402
"scope": "window",
397403
"type": "boolean",
398404
"default": null,
399-
"description": "Controls whether or not the Ada Language Server should emit diagnostics into the VS Code Problems view."
405+
"description": "Controls whether or not the Ada Language Server should emit diagnostics related to Ada files into the VS Code Problems view."
400406
},
401407
"ada.foldComments": {
402408
"scope": "window",

integration/vscode/ada/schemas/als-settings-schema.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
"projectDiagnostics": {
2626
"type": "boolean",
2727
"default": true,
28-
"description": "Controls whether or not the Ada Language Server should emit project diagnostics into the VS Code Problems view.\n\nNote: this setting is ignored if `ada.enableDiagnostics` is disabled and a workspace reload is necessary to refresh the diagnostics after modifying this setting."
28+
"description": "Controls whether or not the Ada Language Server should emit project diagnostics into the VS Code Problems view."
29+
},
30+
"alireDiagnostics": {
31+
"type": "boolean",
32+
"default": true,
33+
"description": "Controls whether or not the Ada Language Server should emit diagnostics related to alire into the VS Code Problems view."
2934
},
3035
"defaultCharset": {
3136
"type": "string",
@@ -80,10 +85,10 @@
8085
"default": "usage_and_abstract_only",
8186
"description": "Controls the policy for displaying overriding and overridden subprograms on navigation requests such as 'Go To Definition' or 'Go To Implementations'."
8287
},
83-
"enableDiagnostics": {
88+
"adaFileDiagnostics": {
8489
"type": "boolean",
8590
"default": true,
86-
"description": "Controls whether or not the Ada Language Server should emit diagnostics into the VS Code Problems view."
91+
"description": "Controls whether or not the Ada Language Server should emit diagnostics related to Ada Files into the VS Code Problems view."
8792
},
8893
"foldComments": {
8994
"type": "boolean",

source/ada/lsp-ada_configurations.adb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,19 @@ package body LSP.Ada_Configurations is
302302
then
303303
Self.Project_Diagnostics_Enabled := JSON (Index).Boolean_Value;
304304

305+
elsif Check_Variable
306+
(Name, JSON (Index).Kind, "alireDiagnostics", Boolean_Value)
307+
then
308+
Self.Alire_Diagnostics_Enabled := JSON (Index).Boolean_Value;
309+
310+
elsif Check_Variable
311+
(Name, JSON (Index).Kind, "enableDiagnostics", Boolean_Value)
312+
then
313+
Messages.Append
314+
("enableDiagnostics has been deprecated please have a look at"
315+
& " adaFileDiagnostics, projectDiagnostics"
316+
& "and alireDiagnostics");
317+
305318
elsif Check_Variable
306319
(Name, JSON (Index).Kind, "scenarioVariables", Start_Object)
307320
then
@@ -328,9 +341,9 @@ package body LSP.Ada_Configurations is
328341
Self.Charset := JSON (Index).String_Value;
329342

330343
elsif Check_Variable
331-
(Name, JSON (Index).Kind, "enableDiagnostics", Boolean_Value)
344+
(Name, JSON (Index).Kind, "adaFileDiagnostics", Boolean_Value)
332345
then
333-
Self.Diagnostics_Enabled := JSON (Index).Boolean_Value;
346+
Self.Ada_File_Diagnostics_Enabled := JSON (Index).Boolean_Value;
334347

335348
elsif Check_Variable
336349
(Name, JSON (Index).Kind, "enableIndexing", Boolean_Value)

source/ada/lsp-ada_configurations.ads

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@ package LSP.Ada_Configurations is
8888
-- Maximum number of logs (should be > to the number of servers run
8989
-- simultaneously)
9090

91-
function Diagnostics_Enabled (Self : Configuration'Class) return Boolean;
92-
-- Whether to publish diagnostics
91+
function Ada_File_Diagnostics_Enabled
92+
(Self : Configuration'Class) return Boolean;
93+
-- Whether to publish file related diagnostics
9394

9495
function Project_Diagnostics_Enabled
9596
(Self : Configuration'Class) return Boolean;
9697
-- Whether to publish project related diagnostics
9798

99+
function Alire_Diagnostics_Enabled
100+
(Self : Configuration'Class) return Boolean;
101+
-- Whether to publish alire related diagnostics
102+
98103
function Indexing_Enabled (Self : Configuration'Class) return Boolean;
99104
-- Whether to index sources in the background. This should be True
100105
-- for normal use, and can be disabled for debug or testing purposes.
@@ -154,23 +159,24 @@ private
154159
use type VSS.Strings.Virtual_String;
155160

156161
type Configuration is tagged record
157-
Project_File : VSS.Strings.Virtual_String;
158-
GPR_Configuration_File : VSS.Strings.Virtual_String;
159-
Charset : VSS.Strings.Virtual_String;
160-
Relocate_Build_Tree : VSS.Strings.Virtual_String;
161-
Relocate_Root : VSS.Strings.Virtual_String;
162-
Named_Notation_Threshold : Natural := 3;
163-
Log_Threshold : Natural := 10;
164-
Diagnostics_Enabled : Boolean := True;
165-
Project_Diagnostics_Enabled : Boolean := True;
166-
Indexing_Enabled : Boolean := True;
167-
Rename_In_Comments : Boolean := False;
168-
Folding_Comments : Boolean := True;
169-
Use_Completion_Snippets : Boolean := True;
170-
Use_Gnatformat : Boolean := True;
171-
Indent_Only : Boolean := True;
172-
Follow_Symlinks : Boolean := True;
173-
Insert_With_Clauses : Boolean := True;
162+
Project_File : VSS.Strings.Virtual_String;
163+
GPR_Configuration_File : VSS.Strings.Virtual_String;
164+
Charset : VSS.Strings.Virtual_String;
165+
Relocate_Build_Tree : VSS.Strings.Virtual_String;
166+
Relocate_Root : VSS.Strings.Virtual_String;
167+
Named_Notation_Threshold : Natural := 3;
168+
Log_Threshold : Natural := 10;
169+
Ada_File_Diagnostics_Enabled : Boolean := True;
170+
Project_Diagnostics_Enabled : Boolean := True;
171+
Alire_Diagnostics_Enabled : Boolean := True;
172+
Indexing_Enabled : Boolean := True;
173+
Rename_In_Comments : Boolean := False;
174+
Folding_Comments : Boolean := True;
175+
Use_Completion_Snippets : Boolean := True;
176+
Use_Gnatformat : Boolean := True;
177+
Indent_Only : Boolean := True;
178+
Follow_Symlinks : Boolean := True;
179+
Insert_With_Clauses : Boolean := True;
174180

175181
Documentation_Style : GNATdoc.Comments.Options.Documentation_Style
176182
:= GNATdoc.Comments.Options.GNAT;
@@ -205,13 +211,19 @@ private
205211
(Self : Configuration'Class) return VSS.Strings.Virtual_String is
206212
(Self.Relocate_Root);
207213

208-
function Diagnostics_Enabled (Self : Configuration'Class) return Boolean is
209-
(Self.Diagnostics_Enabled);
214+
function Ada_File_Diagnostics_Enabled
215+
(Self : Configuration'Class)
216+
return Boolean is
217+
(Self.Ada_File_Diagnostics_Enabled);
210218

211219
function Project_Diagnostics_Enabled
212220
(Self : Configuration'Class)
213221
return Boolean is (Self.Project_Diagnostics_Enabled);
214222

223+
function Alire_Diagnostics_Enabled
224+
(Self : Configuration'Class)
225+
return Boolean is (Self.Alire_Diagnostics_Enabled);
226+
215227
function Indexing_Enabled (Self : Configuration'Class) return Boolean is
216228
(Self.Indexing_Enabled);
217229

source/ada/lsp-ada_documents-lal_diagnostics.adb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ package body LSP.Ada_Documents.LAL_Diagnostics is
5757

5858
overriding function Has_New_Diagnostic
5959
(Self : in out Diagnostic_Source;
60-
Context : LSP.Ada_Contexts.Context) return Boolean
61-
is
60+
Context : LSP.Ada_Contexts.Context) return Boolean is
6261
begin
63-
return Self.Errors /= Self.Get_Diagnostics (Context);
62+
if Self.Is_Enabled then
63+
return Self.Errors /= Self.Get_Diagnostics (Context);
64+
else
65+
return False;
66+
end if;
6467
end Has_New_Diagnostic;
6568

6669
--------------------
@@ -78,7 +81,9 @@ package body LSP.Ada_Documents.LAL_Diagnostics is
7881
Unit : constant Libadalang.Analysis.Analysis_Unit :=
7982
Self.Document.Unit (Context);
8083
begin
81-
if Unit.Has_Diagnostics then
84+
if Self.Is_Enabled
85+
and then Unit.Has_Diagnostics
86+
then
8287
for Error of Unit.Diagnostics loop
8388

8489
-- Filter out diagnostics that simply report "Cannot parse <..>",
@@ -98,4 +103,14 @@ package body LSP.Ada_Documents.LAL_Diagnostics is
98103
end if;
99104
end Get_Diagnostics;
100105

106+
----------------
107+
-- Is_Enabled --
108+
----------------
109+
110+
overriding function Is_Enabled
111+
(Self : Diagnostic_Source) return Boolean is
112+
begin
113+
return Self.Handler.Ada_File_Diagnostics_Enabled;
114+
end Is_Enabled;
115+
101116
end LSP.Ada_Documents.LAL_Diagnostics;

source/ada/lsp-ada_documents-lal_diagnostics.ads

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with LSP.Ada_Handlers;
1819
with LSP.Diagnostic_Sources;
1920
private with Langkit_Support.Diagnostics;
2021

2122
package LSP.Ada_Documents.LAL_Diagnostics is
2223

2324
type Diagnostic_Source
24-
(Document : not null LSP.Ada_Documents.Document_Access)
25+
(Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
26+
Document : not null LSP.Ada_Documents.Document_Access)
2527
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with private;
2628

2729
overriding procedure Get_Diagnostic
@@ -34,6 +36,9 @@ package LSP.Ada_Documents.LAL_Diagnostics is
3436
(Self : in out Diagnostic_Source;
3537
Context : LSP.Ada_Contexts.Context) return Boolean;
3638

39+
overriding function Is_Enabled
40+
(Self : Diagnostic_Source) return Boolean;
41+
3742
private
3843

3944
subtype Diagnostic_Index is Natural range 0 .. MAX_NB_DIAGNOSTICS;
@@ -43,7 +48,8 @@ private
4348
end record;
4449

4550
type Diagnostic_Source
46-
(Document : not null LSP.Ada_Documents.Document_Access)
51+
(Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
52+
Document : not null LSP.Ada_Documents.Document_Access)
4753
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with record
4854
Errors : Diagnostics;
4955
end record;

source/ada/lsp-ada_documents.adb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,16 +1132,18 @@ package body LSP.Ada_Documents is
11321132
----------------
11331133

11341134
procedure Initialize
1135-
(Self : in out Document;
1136-
URI : LSP.Structures.DocumentUri;
1137-
Text : VSS.Strings.Virtual_String) is
1135+
(Self : in out Document;
1136+
Handler : LSP.Ada_Handlers.Message_Handler'Class;
1137+
URI : LSP.Structures.DocumentUri;
1138+
Text : VSS.Strings.Virtual_String) is
11381139
begin
11391140
LSP.Text_Documents.Constructors.Initialize (Self, URI, Text);
11401141

11411142
Self.Refresh_Symbol_Cache := True;
11421143
Self.Diagnostic_Sources.Append
11431144
(new LSP.Ada_Documents.LAL_Diagnostics.Diagnostic_Source
1144-
(Self'Unchecked_Access));
1145+
(Handler => Handler'Unrestricted_Access,
1146+
Document => Self'Unchecked_Access));
11451147
end Initialize;
11461148

11471149
----------------------

source/ada/lsp-ada_documents.ads

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ package LSP.Ada_Documents is
5252
with Storage_Size => 0;
5353

5454
procedure Initialize
55-
(Self : in out Document;
56-
URI : LSP.Structures.DocumentUri;
57-
Text : VSS.Strings.Virtual_String);
55+
(Self : in out Document;
56+
Handler : LSP.Ada_Handlers.Message_Handler'Class;
57+
URI : LSP.Structures.DocumentUri;
58+
Text : VSS.Strings.Virtual_String);
5859
-- Create a new document from a TextDocumentItem.
5960

6061
procedure Cleanup (Self : in out Document);

0 commit comments

Comments
 (0)