Skip to content

Commit 5ff3e0a

Browse files
Merge branch 'topic/als.1516.configuration_ada_warning' into 'master'
Send Messages for invalid Ada configurations Closes #1516 See merge request eng/ide/ada_language_server!1801
2 parents bb1d4a1 + 0ebf6bd commit 5ff3e0a

File tree

19 files changed

+708
-156
lines changed

19 files changed

+708
-156
lines changed

source/ada/lsp-ada_configurations.adb

Lines changed: 234 additions & 142 deletions
Large diffs are not rendered by default.

source/ada/lsp-ada_configurations.ads

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ package LSP.Ada_Configurations is
4949
-- order of scenario variables doesn't trigger a reload, which is nice.
5050

5151
procedure Read_JSON
52-
(Self : in out Configuration'Class;
53-
JSON : LSP.Structures.LSPAny);
52+
(Self : in out Configuration'Class;
53+
JSON : LSP.Structures.LSPAny;
54+
Messages : out VSS.String_Vectors.Virtual_String_Vector);
5455

5556
procedure Read_File
56-
(Self : in out Configuration'Class;
57-
File : VSS.Strings.Virtual_String);
57+
(Self : in out Configuration'Class;
58+
File : VSS.Strings.Virtual_String;
59+
Messages : out VSS.String_Vectors.Virtual_String_Vector);
5860

5961
function Project_File
6062
(Self : Configuration'Class) return VSS.Strings.Virtual_String;

source/ada/lsp-ada_did_change_configurations.adb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with GNATCOLL.VFS;
1819
with LSP.Ada_Configurations;
1920
with LSP.Client_Message_Receivers;
21+
with LSP.Enumerations;
2022
with LSP.Server_Notifications.DidChangeConfiguration;
23+
with VSS.String_Vectors;
2124

2225
package body LSP.Ada_Did_Change_Configurations is
2326

@@ -93,6 +96,8 @@ package body LSP.Ada_Did_Change_Configurations is
9396
New_Config : LSP.Ada_Configurations.Configuration
9497
renames Result.Configuration;
9598
Reload : Boolean renames Result.Reload;
99+
100+
Messages : VSS.String_Vectors.Virtual_String_Vector;
96101
begin
97102
Self.Context.Get_Trace_Handle.Trace
98103
("Processing received workspace/didChangeConfiguration notification");
@@ -112,10 +117,16 @@ package body LSP.Ada_Did_Change_Configurations is
112117

113118
-- Read the new received configuration. 'null' values will be ignored
114119
-- and thus keep the value from the base config.
115-
New_Config.Read_JSON (Value.Params.settings);
120+
New_Config.Read_JSON (Value.Params.settings, Messages);
116121

117122
Reload := False;
118123

124+
Self.Context.Send_Messages
125+
(Show => True,
126+
Messages => Messages,
127+
Severity => LSP.Enumerations.Warning,
128+
File => GNATCOLL.VFS.No_File);
129+
119130
-- Always reload project if Project_Tree isn't ready
120131
if not Self.Context.Project_Tree_Is_Defined then
121132
Self.Context.Get_Trace_Handle.Trace

source/ada/lsp-ada_handlers.adb

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ with VSS.Strings;
2929
with VSS.Strings.Formatters.Integers;
3030
with VSS.Strings.Formatters.Strings;
3131
with VSS.Strings.Templates;
32-
with VSS.String_Vectors;
3332

3433
with Laltools.Common;
3534
with Laltools.Partial_GNATPP;
@@ -91,7 +90,6 @@ with LSP.Search;
9190
with LSP.Servers.FS_Watch;
9291
with LSP.Structures.LSPAny_Vectors;
9392
with LSP.Utils;
94-
with LSP.Enumerations;
9593

9694
package body LSP.Ada_Handlers is
9795

@@ -412,7 +410,7 @@ package body LSP.Ada_Handlers is
412410
Self.File_Monitor :=
413411
new LSP.Servers.FS_Watch.FS_Watch_Monitor (Self.Server);
414412
Self.Diagnostic_Sources :=
415-
[new LSP.Ada_Handlers.Project_Diagnostics.Diagnostic_Source
413+
[new LSP.Ada_Handlers.Project_Diagnostics.Diagnostic_Source
416414
(Self'Unchecked_Access)];
417415

418416
Self.Load_Config_Files (CLI_Config_File);
@@ -455,6 +453,7 @@ package body LSP.Ada_Handlers is
455453

456454
Config_File_Processed : Boolean := False;
457455
New_Configuration : LSP.Ada_Configurations.Configuration;
456+
Messages : VSS.String_Vectors.Virtual_String_Vector;
458457
begin
459458
for F_Path of Candidates loop
460459
if not F_Path.Is_Empty then
@@ -465,7 +464,14 @@ package body LSP.Ada_Handlers is
465464
Self.Tracer.Trace_Text ("Trying config file: " & F_Path);
466465
if F.Is_Regular_File then
467466
Self.Tracer.Trace_Text ("Loading config file: " & F_Path);
468-
New_Configuration.Read_File (F_Path);
467+
New_Configuration.Read_File (F_Path, Messages);
468+
469+
Self.Send_Messages
470+
(Show => True,
471+
Messages => Messages,
472+
Severity => LSP.Enumerations.Warning,
473+
File => F);
474+
469475
Config_File_Processed := True;
470476
else
471477
Self.Tracer.Trace_Text (F_Path & " doesn't exist");
@@ -2453,9 +2459,17 @@ package body LSP.Ada_Handlers is
24532459
-- }
24542460
declare
24552461
New_Configuration : LSP.Ada_Configurations.Configuration;
2462+
Messages : VSS.String_Vectors.Virtual_String_Vector;
24562463
begin
24572464
-- Parse the configuration.
2458-
New_Configuration.Read_JSON (Value.initializationOptions);
2465+
New_Configuration.Read_JSON
2466+
(Value.initializationOptions, Messages);
2467+
2468+
Self.Send_Messages
2469+
(Show => True,
2470+
Messages => Messages,
2471+
Severity => LSP.Enumerations.Warning,
2472+
File => GNATCOLL.VFS.No_File);
24592473

24602474
-- Set it as the current configuration.
24612475
-- This will also save it as the initial configuration (if not done
@@ -3812,6 +3826,37 @@ package body LSP.Ada_Handlers is
38123826
return Definition;
38133827
end Resolve_Name;
38143828

3829+
-------------------
3830+
-- Send_Messages --
3831+
-------------------
3832+
3833+
overriding procedure Send_Messages
3834+
(Self : Message_Handler;
3835+
Show : Boolean;
3836+
Messages : VSS.String_Vectors.Virtual_String_Vector;
3837+
Severity : LSP.Enumerations.MessageType;
3838+
File : GNATCOLL.VFS.Virtual_File)
3839+
is
3840+
use GNATCOLL.VFS;
3841+
use VSS.Strings;
3842+
Prefix : constant VSS.Strings.Virtual_String :=
3843+
(if File /= No_File
3844+
then VSS.Strings.Virtual_String
3845+
(Self.To_URI (File.Display_Full_Name)) & ": "
3846+
else "");
3847+
begin
3848+
for Message of Messages loop
3849+
if Show then
3850+
Self.Sender.On_ShowMessage_Notification
3851+
((Severity, Prefix & Message));
3852+
end if;
3853+
3854+
Self.Sender.On_LogMessage_Notification
3855+
((Severity, Prefix & Message));
3856+
Self.Tracer.Trace_Text (Message);
3857+
end loop;
3858+
end Send_Messages;
3859+
38153860
-----------------------
38163861
-- Set_Configuration --
38173862
-----------------------

source/ada/lsp-ada_handlers.ads

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ with GPR2.Project.Tree;
3030
with Libadalang.Analysis;
3131
with Libadalang.Common;
3232

33+
with LSP.Enumerations;
34+
with VSS.String_Vectors;
3335
with VSS.Strings.Conversions;
3436

3537
with LSP.Ada_Client_Capabilities;
@@ -470,6 +472,13 @@ private
470472
overriding procedure Increment_Project_Timestamp
471473
(Self : in out Message_Handler);
472474

475+
overriding procedure Send_Messages
476+
(Self : Message_Handler;
477+
Show : Boolean;
478+
Messages : VSS.String_Vectors.Virtual_String_Vector;
479+
Severity : LSP.Enumerations.MessageType;
480+
File : GNATCOLL.VFS.Virtual_File);
481+
473482
overriding function Project_Tree_Is_Defined (Self : Message_Handler)
474483
return Boolean is (Self.Project_Tree.Is_Defined);
475484

source/ada/lsp-ada_job_contexts.ads

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ with Libadalang.Common;
2828

2929
with Laltools.Common;
3030

31+
with LSP.Enumerations;
32+
with VSS.String_Vectors;
3133
with VSS.Strings;
3234

3335
with LSP.Ada_Client_Capabilities;
@@ -71,6 +73,15 @@ package LSP.Ada_Job_Contexts is
7173
procedure Increment_Project_Timestamp (Self : in out Ada_Job_Context)
7274
is abstract;
7375

76+
procedure Send_Messages
77+
(Self : Ada_Job_Context;
78+
Show : Boolean;
79+
Messages : VSS.String_Vectors.Virtual_String_Vector;
80+
Severity : LSP.Enumerations.MessageType;
81+
File : GNATCOLL.VFS.Virtual_File) is abstract;
82+
-- Send Messages of Severity to the client using LogMessages.
83+
-- If Show is True then also send showMessages.
84+
7485
function Project_Tree_Is_Defined
7586
(Self : Ada_Job_Context) return Boolean is abstract;
7687

source/gpr/lsp-gpr_handlers.adb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ with LSP.Text_Documents.Langkit_Documents;
3535
with LSP.Utils;
3636

3737
with Gpr_Parser.Common;
38+
with VSS.String_Vectors;
3839

3940
package body LSP.GPR_Handlers is
4041

@@ -682,9 +683,16 @@ package body LSP.GPR_Handlers is
682683

683684
overriding procedure On_DidChangeConfiguration_Notification
684685
(Self : in out Message_Handler;
685-
Value : LSP.Structures.DidChangeConfigurationParams) is
686+
Value : LSP.Structures.DidChangeConfigurationParams)
687+
is
688+
Messages : VSS.String_Vectors.Virtual_String_Vector;
686689
begin
687-
Self.Configuration.Read_JSON (Value.settings);
690+
Self.Configuration.Read_JSON (Value.settings, Messages);
691+
for Message of Messages loop
692+
Self.Sender.On_LogMessage_Notification
693+
((LSP.Enumerations.Warning, Message));
694+
Self.Tracer.Trace_Text (Message);
695+
end loop;
688696

689697
for Document of Self.Open_Documents loop
690698
begin
@@ -693,7 +701,6 @@ package body LSP.GPR_Handlers is
693701
(Client => Self.Client,
694702
Configuration => Self.Configuration,
695703
Update_Sources => True);
696-
697704
exception
698705
when E : others =>
699706
Self.Tracer.Trace_Exception
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"unknownAttr": "Hello",
3+
"USEGNATFORMAT": false,
4+
"logThreshold": false,
5+
"insertWithClauses": true
6+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
[
2+
{
3+
"comment": [
4+
"Set an invalid configuration in .als.json ",
5+
"and verify we are receiving warnings."
6+
]
7+
},
8+
{
9+
"start": {
10+
"cmd": ["${ALS}"]
11+
}
12+
},
13+
{
14+
"send": {
15+
"request": {
16+
"jsonrpc": "2.0",
17+
"id": 1,
18+
"method": "initialize",
19+
"params": {
20+
"rootUri": "$URI{.}",
21+
"capabilities": {}
22+
}
23+
},
24+
"wait": [
25+
{
26+
"method": "window/showMessage",
27+
"params": {
28+
"type": 2,
29+
"message": "$URI{.als.json}: Ada settings are case sensitive: \"USEGNATFORMAT\" has been ignored please set it to \"useGnatformat\"."
30+
}
31+
},
32+
{
33+
"method": "window/logMessage",
34+
"params": {
35+
"type": 2,
36+
"message": "$URI{.als.json}: Ada settings are case sensitive: \"USEGNATFORMAT\" has been ignored please set it to \"useGnatformat\"."
37+
}
38+
},
39+
{
40+
"method": "window/showMessage",
41+
"params": {
42+
"type": 2,
43+
"message": "$URI{.als.json}: Invalid type for the Ada setting \"logThreshold\" please check the value."
44+
}
45+
},
46+
{
47+
"method": "window/logMessage",
48+
"params": {
49+
"type": 2,
50+
"message": "$URI{.als.json}: Invalid type for the Ada setting \"logThreshold\" please check the value."
51+
}
52+
},
53+
{
54+
"method": "window/showMessage",
55+
"params": {
56+
"type": 2,
57+
"message": "$URI{.als.json}: Unknown Ada setting \"unknownAttr\"."
58+
}
59+
},
60+
{
61+
"method": "window/logMessage",
62+
"params": {
63+
"type": 2,
64+
"message": "$URI{.als.json}: Unknown Ada setting \"unknownAttr\"."
65+
}
66+
}
67+
]
68+
}
69+
},
70+
{
71+
"send": {
72+
"request": {
73+
"jsonrpc": "2.0",
74+
"method": "initialized",
75+
"params": {}
76+
},
77+
"wait": []
78+
}
79+
},
80+
{
81+
"stop": {
82+
"exit_code": 0
83+
}
84+
}
85+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'configuration_warning.als_json'

0 commit comments

Comments
 (0)