Skip to content

Commit f959021

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 17dfefa + 3b59412 commit f959021

24 files changed

+534
-47
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ section below it for the last release. -->
99
* Support loading a fresh checkout of an Alire crate by automatically performing the necessary Alire workspace initializations
1010
* VS Code status bar now displays an item showing the project-loading status and useful commands provided by the extension when hovering on it
1111
* Consider the `Gnattest.Harness_Dir` project attribute in the GNATtest integration in VS Code
12+
* New source information diagnostics for opened Ada files
1213

1314
## 26.0.202502240
1415

doc/settings.md

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Settings understood by the Ada Language Server itself, independently from the LS
109109
* [enableDiagnostics](#enableddiagnostics)
110110
* [adaFileDiagnostics](#adafilediagnostics)
111111
* [gprFileDiagnostics](#gprfilediagnostics)
112+
* [sourceInfoDiagnostics](#sourceinfodiagnostics)
112113
* [projectDiagnostics](#projectdiagnostics)
113114
* [alireDiagnostics](#alirediagnostics)
114115
* [enableIndexing](#enableindexing)
@@ -248,6 +249,17 @@ The value is a boolean.
248249
'gprFileDiagnostics': false
249250
```
250251

252+
### sourceInfoDiagnostics
253+
254+
You can explicitly deactivate the emission of source infomration diagnostics
255+
when opening Ada files via the `sourceInfoDiagnostics` key. By default,
256+
diagnostics are enabled.
257+
The value is a boolean.
258+
259+
```javascript
260+
'sourceInfoDiagnostics': false
261+
```
262+
251263
### projectDiagnostics
252264

253265
You can explicitly deactivate the emission of diagnostics when loading a

integration/vscode/ada/package.json

+36-16
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,26 @@
559559
"default": null,
560560
"markdownDescription": "Controls whether or not the Ada Language Server should emit diagnostics related to alire into the VS Code Problems view.\n\nIf not set in VS Code, this setting takes its value from the [`.als.json`](https://github.com/AdaCore/ada_language_server/blob/master/doc/settings.md) file at the root of the workspace, if that file exists. Otherwise it defaults to `true`."
561561
},
562+
"ada.sourceInfoDiagnostics": {
563+
"scope": "window",
564+
"enum": [
565+
true,
566+
false,
567+
null
568+
],
569+
"enumItemLabels": [
570+
null,
571+
null,
572+
"Provided by .als.json (default: true)"
573+
],
574+
"markdownEnumDescriptions": [
575+
"true",
576+
"false",
577+
"Provided by [`.als.json`](https://github.com/AdaCore/ada_language_server/blob/master/doc/settings.md) if it exists at the workspace root, otherwise defaults to `true`."
578+
],
579+
"default": null,
580+
"markdownDescription": "Controls whether or not the Ada Language Server should emit source information diagnostics (e.g: for opened files that do not belong to the loaded project tree).\n\nIf not set in VS Code, this setting takes its value from the [`.als.json`](https://github.com/AdaCore/ada_language_server/blob/master/doc/settings.md) file at the root of the workspace, if that file exists. Otherwise it defaults to `true`."
581+
},
562582
"ada.adaFileDiagnostics": {
563583
"scope": "window",
564584
"enum": [
@@ -693,23 +713,23 @@
693713
}
694714
],
695715
"problemMatchers": [
696-
{
716+
{
697717
"name": "ada",
698718
"label": "Gnat Ada Problem Matcher (obsolete)",
699-
"fileLocation": [
700-
"autoDetect",
701-
"${workspaceRoot}"
702-
],
703-
"pattern": [
704-
{
719+
"fileLocation": [
720+
"autoDetect",
721+
"${workspaceRoot}"
722+
],
723+
"pattern": [
724+
{
705725
"regexp": "^([^:]:?[^:]*):(\\d+):(\\d+):\\s+(?:([a-z]+):\\s+)?(.*)$",
706-
"file": 1,
707-
"line": 2,
708-
"column": 3,
709-
"severity": 4,
710-
"message": 5
711-
}
712-
]
726+
"file": 1,
727+
"line": 2,
728+
"column": 3,
729+
"severity": 4,
730+
"message": 5
731+
}
732+
]
713733
},
714734
{
715735
"name": "ada-error",
@@ -760,14 +780,14 @@
760780
"severity": "info",
761781
"pattern": [
762782
{
763-
"regexp": "^([^:]:?[^:]*):(\\d+):(\\d+):\\s+[\\(:]?(info|[Nn]ote|check)[\\):]?\\s+(.*)$",
783+
"regexp": "^([^:]:?[^:]*):(\\d+):(\\d+):\\s+[\\(:]?(info|[Nn]ote|check)[\\):]?\\s+(.*)$",
764784
"file": 1,
765785
"line": 2,
766786
"column": 3,
767787
"message": 5
768788
}
769789
]
770-
}
790+
}
771791
],
772792
"taskDefinitions": [
773793
{

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

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
"default": "usage_and_abstract_only",
8686
"description": "Controls the policy for displaying overriding and overridden subprograms on navigation requests such as 'Go To Definition' or 'Go To Implementations'."
8787
},
88+
"sourceInfoDiagnostics": {
89+
"type": "boolean",
90+
"default": true,
91+
"description": "Controls whether or not the Ada Language Server should emit source information diagnostics for opened Ada files."
92+
},
8893
"adaFileDiagnostics": {
8994
"type": "boolean",
9095
"default": true,

source/ada/lsp-ada_configurations.adb

+5
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ package body LSP.Ada_Configurations is
340340
then
341341
Self.Charset := JSON (Index).String_Value;
342342

343+
elsif Check_Variable
344+
(Name, JSON (Index).Kind, "sourceInfoDiagnostics", Boolean_Value)
345+
then
346+
Self.Source_Info_Diagnostics_Enabled := JSON (Index).Boolean_Value;
347+
343348
elsif Check_Variable
344349
(Name, JSON (Index).Kind, "adaFileDiagnostics", Boolean_Value)
345350
then

source/ada/lsp-ada_configurations.ads

+37-27
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ package LSP.Ada_Configurations is
9292
(Self : Configuration'Class) return Boolean;
9393
-- Whether to publish ada file related diagnostics
9494

95+
function Source_Info_Diagnostics_Enabled
96+
(Self : Configuration'Class) return Boolean;
97+
-- Whether to publish source information diagnostics
98+
9599
function GPR_File_Diagnostics_Enabled
96100
(Self : Configuration'Class) return Boolean;
97101
-- Whether to publish diagnostics related to GPR files' edition. This
@@ -165,37 +169,38 @@ private
165169
use type VSS.Strings.Virtual_String;
166170

167171
type Configuration is tagged record
168-
Project_File : VSS.Strings.Virtual_String;
169-
GPR_Configuration_File : VSS.Strings.Virtual_String;
170-
Charset : VSS.Strings.Virtual_String;
171-
Relocate_Build_Tree : VSS.Strings.Virtual_String;
172-
Relocate_Root : VSS.Strings.Virtual_String;
173-
Named_Notation_Threshold : Natural := 3;
174-
Log_Threshold : Natural := 10;
175-
Ada_File_Diagnostics_Enabled : Boolean := True;
176-
GPR_File_Diagnostics_Enabled : Boolean := True;
177-
Project_Diagnostics_Enabled : Boolean := True;
178-
Alire_Diagnostics_Enabled : Boolean := True;
179-
Indexing_Enabled : Boolean := True;
180-
Rename_In_Comments : Boolean := False;
181-
Folding_Comments : Boolean := True;
182-
Use_Completion_Snippets : Boolean := True;
183-
Use_Gnatformat : Boolean := True;
184-
Indent_Only : Boolean := True;
185-
Follow_Symlinks : Boolean := True;
186-
Insert_With_Clauses : Boolean := True;
187-
188-
Documentation_Style : GNATdoc.Comments.Options.Documentation_Style
189-
:= GNATdoc.Comments.Options.GNAT;
190-
191-
Method_Ancestry_Policy :
172+
Project_File : VSS.Strings.Virtual_String;
173+
GPR_Configuration_File : VSS.Strings.Virtual_String;
174+
Charset : VSS.Strings.Virtual_String;
175+
Relocate_Build_Tree : VSS.Strings.Virtual_String;
176+
Relocate_Root : VSS.Strings.Virtual_String;
177+
Named_Notation_Threshold : Natural := 3;
178+
Log_Threshold : Natural := 10;
179+
Ada_File_Diagnostics_Enabled : Boolean := True;
180+
GPR_File_Diagnostics_Enabled : Boolean := True;
181+
Project_Diagnostics_Enabled : Boolean := True;
182+
Source_Info_Diagnostics_Enabled : Boolean := True;
183+
Alire_Diagnostics_Enabled : Boolean := True;
184+
Indexing_Enabled : Boolean := True;
185+
Rename_In_Comments : Boolean := False;
186+
Folding_Comments : Boolean := True;
187+
Use_Completion_Snippets : Boolean := True;
188+
Use_Gnatformat : Boolean := True;
189+
Indent_Only : Boolean := True;
190+
Follow_Symlinks : Boolean := True;
191+
Insert_With_Clauses : Boolean := True;
192+
193+
Documentation_Style : GNATdoc.Comments.Options.Documentation_Style :=
194+
GNATdoc.Comments.Options.GNAT;
195+
196+
Method_Ancestry_Policy :
192197
LSP.Enumerations.AlsDisplayMethodAncestryOnNavigationPolicy :=
193198
LSP.Enumerations.Usage_And_Abstract_Only;
194199

195-
Variables_Names : VSS.String_Vectors.Virtual_String_Vector;
196-
Variables_Values : VSS.String_Vectors.Virtual_String_Vector;
200+
Variables_Names : VSS.String_Vectors.Virtual_String_Vector;
201+
Variables_Values : VSS.String_Vectors.Virtual_String_Vector;
197202

198-
Context : GPR2.Context.Object;
203+
Context : GPR2.Context.Object;
199204
end record;
200205

201206
function Project_File
@@ -223,6 +228,11 @@ private
223228
return Boolean is
224229
(Self.Ada_File_Diagnostics_Enabled);
225230

231+
function Source_Info_Diagnostics_Enabled
232+
(Self : Configuration'Class)
233+
return Boolean is
234+
(Self.Source_Info_Diagnostics_Enabled);
235+
226236
function GPR_File_Diagnostics_Enabled
227237
(Self : Configuration'Class)
228238
return Boolean is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2023, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
with LSP.Enumerations;
19+
with VSS.Strings.Conversions;
20+
21+
package body LSP.Ada_Documents.Source_Info_Diagnostics is
22+
23+
------------------------
24+
-- Has_New_Diagnostic --
25+
------------------------
26+
27+
overriding function Has_New_Diagnostic
28+
(Self : in out Diagnostic_Source;
29+
Context : LSP.Ada_Contexts.Context) return Boolean
30+
is
31+
use LSP.Ada_Handlers;
32+
33+
Current_Project_Stamp : constant LSP.Ada_Handlers.Project_Stamp :=
34+
Self.Handler.Get_Project_Stamp;
35+
begin
36+
-- The project has been reloaded: compute source information diagnostics
37+
-- again since the set of source files might have been changed.
38+
if Self.Last_Project_Stamp /= Current_Project_Stamp then
39+
Self.Last_Project_Stamp := Current_Project_Stamp;
40+
return True;
41+
end if;
42+
43+
return False;
44+
end Has_New_Diagnostic;
45+
46+
--------------------
47+
-- Get_Diagnostics --
48+
--------------------
49+
50+
overriding
51+
procedure Get_Diagnostic
52+
(Self : in out Diagnostic_Source;
53+
Context : LSP.Ada_Contexts.Context;
54+
Errors : out LSP.Structures.Diagnostic_Vector)
55+
is
56+
begin
57+
-- If the unit associated to the document belongs to the fallback context
58+
-- it means that the document's file does not belong the loaded project:
59+
-- emit a hint diagnostic in that case.
60+
if Context.Is_Fallback_Context then
61+
declare
62+
Diag_Msg : constant String :=
63+
(if Self.Handler.Get_Project_Status.Is_Project_Loaded
64+
then "This file does not belong to the loaded project tree"
65+
else "No project tree currently loaded");
66+
begin
67+
Errors.Append
68+
(LSP.Structures.Diagnostic'
69+
(a_range => ((0, 0), (0, 0)),
70+
source => "ada.sourceInformation",
71+
severity => (True, LSP.Enumerations.Hint),
72+
message =>
73+
VSS.Strings.Conversions.To_Virtual_String
74+
(Diag_Msg
75+
& ": some features might be imprecise "
76+
& "(e.g: Find All References) or not available "
77+
& "(e.g: Rename)."),
78+
others => <>));
79+
end;
80+
end if;
81+
end Get_Diagnostic;
82+
83+
----------------
84+
-- Is_Enabled --
85+
----------------
86+
87+
overriding function Is_Enabled
88+
(Self : Diagnostic_Source) return Boolean is
89+
begin
90+
return Self.Handler.Source_Info_Diagnostics_Enabled;
91+
end Is_Enabled;
92+
93+
end LSP.Ada_Documents.Source_Info_Diagnostics;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2023, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
--
18+
-- This package provides diagnostics displaying source information about files
19+
-- being opened.
20+
21+
with LSP.Ada_Handlers;
22+
with LSP.Diagnostic_Sources;
23+
24+
package LSP.Ada_Documents.Source_Info_Diagnostics is
25+
26+
type Diagnostic_Source
27+
(Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
28+
Document : not null LSP.Ada_Documents.Document_Access)
29+
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with private;
30+
31+
overriding procedure Get_Diagnostic
32+
(Self : in out Diagnostic_Source;
33+
Context : LSP.Ada_Contexts.Context;
34+
Errors : out LSP.Structures.Diagnostic_Vector);
35+
36+
overriding function Has_New_Diagnostic
37+
(Self : in out Diagnostic_Source;
38+
Context : LSP.Ada_Contexts.Context) return Boolean;
39+
40+
overriding function Is_Enabled
41+
(Self : Diagnostic_Source) return Boolean;
42+
43+
private
44+
45+
type Diagnostic_Source
46+
(Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
47+
Document : not null LSP.Ada_Documents.Document_Access)
48+
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with record
49+
Last_Project_Stamp : LSP.Ada_Handlers.Project_Stamp :=
50+
LSP.Ada_Handlers.No_Project_Stamp;
51+
-- Used to detect when the project has been reloaded.
52+
-- We want to update source information diagnostics only after
53+
-- project reloade.
54+
end record;
55+
56+
end LSP.Ada_Documents.Source_Info_Diagnostics;

0 commit comments

Comments
 (0)