Skip to content

Commit 001ba1a

Browse files
BoulangerAdrienBoulanger
Boulanger
authored andcommitted
Ignore informational message after loading the project.
Add diagnostic for missing runtime. Make the diagnostics more verbose. Adapt tests.
1 parent 8bf7741 commit 001ba1a

File tree

9 files changed

+90
-38
lines changed

9 files changed

+90
-38
lines changed

source/ada/lsp-ada_handlers-project_loading.adb

+2
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ package body LSP.Ada_Handlers.Project_Loading is
362362
Self.Tracer.Trace
363363
("The project set in the configuration doesn't exist: "
364364
& Project_File.Display_Full_Name);
365+
LSP.Ada_Project_Loading.Set_Project_File
366+
(Self.Project_Status, Project_File);
365367
LSP.Ada_Project_Loading.Set_Load_Status
366368
(Self.Project_Status,
367369
LSP.Ada_Project_Loading.Project_Not_Found);

source/ada/lsp-ada_project_loading.adb

+66-16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ package body LSP.Ada_Project_Loading is
4343
(Project : Project_Status_Type) return Boolean;
4444
-- Return True if Project has diagnostics
4545

46+
function Has_Pertinent_GPR2_Messages
47+
(Project : Project_Status_Type) return Boolean;
48+
-- Return True if GPR2_Messages has warnings or errors
49+
4650
-------------------------
4751
-- Load_Status_Message --
4852
-------------------------
@@ -55,28 +59,31 @@ package body LSP.Ada_Project_Loading is
5559
when Valid_Project =>
5660
if Project.Project_Type = Single_Project_Found then
5761
return VSS.Strings.To_Virtual_String
58-
("Unique project in root directory was found and "
59-
& "loaded, but it wasn't explicitly configured.");
62+
("A unique project in the root directory was found"
63+
& " and loaded but it was not explicitly configured.");
6064
else
6165
return VSS.Strings.Empty_Virtual_String;
6266
end if;
6367
when No_Project =>
6468
return VSS.Strings.To_Virtual_String
65-
("No project found in root directory. "
66-
& "Please create a project file and add it to the "
67-
& "configuration.");
69+
("No project was found in the root directory."
70+
& " Please create a GPR project file"
71+
& " and add it to the configuration.");
6872
when Project_Not_Found =>
69-
return VSS.Strings.To_Virtual_String
70-
("Configured project doesn't exist.");
73+
return VSS.Strings.Conversions.To_Virtual_String
74+
("The configured project "
75+
& URIs.Conversions.From_File
76+
(Project.Project_File.Display_Full_Name)
77+
& " does not exist.");
7178
when Multiple_Projects =>
7279
return VSS.Strings.To_Virtual_String
73-
("No project was loaded, because more than one "
74-
& "project file has been found in the root directory. "
75-
& "Please change configuration to point a correct project "
76-
& "file.");
80+
("No project was loaded because"
81+
& " multiple project files were found in the root directory."
82+
& " Please change the configuration"
83+
& " to point to a single project file.");
7784
when Invalid_Project =>
7885
return VSS.Strings.To_Virtual_String
79-
("Project file has errors and can't be loaded.");
86+
("The project file has errors and could not be loaded.");
8087
when Warning_In_Project =>
8188
return VSS.Strings.Empty_Virtual_String;
8289
end case;
@@ -124,6 +131,9 @@ package body LSP.Ada_Project_Loading is
124131
procedure Append_GPR2_Diagnostics;
125132
-- Append the GPR2 messages to the given parent diagnostic, if any.
126133

134+
procedure Append_Runtime_Diagnostic;
135+
-- Append a diagnostic if no runtime has been found for the project
136+
127137
---------------------------------------
128138
-- Create_Project_Loading_Diagnostic --
129139
---------------------------------------
@@ -193,7 +203,7 @@ package body LSP.Ada_Project_Loading is
193203
-- attached to the message is defined.
194204
if File.Is_Defined and then File.Has_Value then
195205
Parent_Diagnostic.relatedInformation.Append
196-
(LSP .Structures.DiagnosticRelatedInformation'
206+
(LSP.Structures.DiagnosticRelatedInformation'
197207
(location => LSP.Structures.Location'
198208
(uri => LSP.Utils.To_URI (File),
199209
a_range => LSP.Utils.To_Range (Sloc),
@@ -220,6 +230,28 @@ package body LSP.Ada_Project_Loading is
220230
end loop;
221231
end Append_GPR2_Diagnostics;
222232

233+
-------------------------------
234+
-- Append_Runtime_Diagnostic --
235+
-------------------------------
236+
237+
procedure Append_Runtime_Diagnostic is
238+
begin
239+
if Project.Status not in No_Project .. Project_Not_Found
240+
and then not Project.Has_Runtime
241+
then
242+
Parent_Diagnostic.relatedInformation.Append
243+
(LSP.Structures.DiagnosticRelatedInformation'
244+
(location =>
245+
(uri => "",
246+
a_range => (start => (0, 0),
247+
an_end => (0, 0)),
248+
others => <>),
249+
message => VSS.Strings.Conversions.To_Virtual_String
250+
("The project was loaded, but no Ada runtime found. "
251+
& "Please check the installation of the Ada compiler.")));
252+
end if;
253+
end Append_Runtime_Diagnostic;
254+
223255
begin
224256

225257
if not Has_Diagnostics (Project) then
@@ -228,6 +260,7 @@ package body LSP.Ada_Project_Loading is
228260

229261
Create_Project_Loading_Diagnostic;
230262
Append_GPR2_Diagnostics;
263+
Append_Runtime_Diagnostic;
231264
Result.Append (Parent_Diagnostic);
232265
return Result;
233266
end Get_Diagnostics;
@@ -244,7 +277,7 @@ package body LSP.Ada_Project_Loading is
244277
return
245278
Old_Project.Status /= New_Project.Status
246279
or else (Old_Project.Project_Type /= New_Project.Project_Type
247-
and then not New_Project.GPR2_Messages.Is_Empty);
280+
and then Has_Pertinent_GPR2_Messages (New_Project));
248281
end Has_New_Diagnostics;
249282

250283
---------------------
@@ -264,10 +297,26 @@ package body LSP.Ada_Project_Loading is
264297
return True;
265298
when others =>
266299
return Project.Status /= Valid_Project
267-
or else not Project.GPR2_Messages.Is_Empty;
300+
or else Has_Pertinent_GPR2_Messages (Project);
268301
end case;
269302
end Has_Diagnostics;
270303

304+
---------------------------------
305+
-- Has_Pertinent_GPR2_Messages --
306+
---------------------------------
307+
308+
function Has_Pertinent_GPR2_Messages
309+
(Project : Project_Status_Type) return Boolean is
310+
begin
311+
for Msg of Project.GPR2_Messages loop
312+
if Msg.Level in GPR2.Message.Warning .. GPR2.Message.Error then
313+
return True;
314+
end if;
315+
end loop;
316+
317+
return False;
318+
end Has_Pertinent_GPR2_Messages;
319+
271320
---------------------
272321
-- Set_Load_Status --
273322
---------------------
@@ -367,7 +416,8 @@ package body LSP.Ada_Project_Loading is
367416
(Kind => VSS.JSON.Streams.String_Value,
368417
String_Value => "ada.projectFile");
369418
begin
370-
Command.title := "Open settings for ada.projectFile";
419+
Command.title :=
420+
"Open settings to set ada.projectFile to a valid project";
371421
Command.command := "workbench.action.openSettings";
372422
Command.arguments.Append (Arg);
373423

testsuite/ada_lsp/editor.incremental/test.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424
},
425425
"severity": 2,
426426
"source": "project",
427-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
427+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
428428
}
429429
]
430430
},
@@ -480,7 +480,7 @@
480480
},
481481
"severity": 2,
482482
"source": "project",
483-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
483+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
484484
}
485485
]
486486
},
@@ -549,7 +549,7 @@
549549
},
550550
"severity": 2,
551551
"source": "project",
552-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
552+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
553553
}
554554
]
555555
},
@@ -605,7 +605,7 @@
605605
},
606606
"severity": 2,
607607
"source": "project",
608-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
608+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
609609
}
610610
]
611611
},
@@ -687,7 +687,7 @@
687687
},
688688
"severity": 2,
689689
"source": "project",
690-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
690+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
691691
}
692692
]
693693
},
@@ -743,7 +743,7 @@
743743
},
744744
"severity": 2,
745745
"source": "project",
746-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
746+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
747747
}
748748
]
749749
},
@@ -825,7 +825,7 @@
825825
},
826826
"severity": 2,
827827
"source": "project",
828-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
828+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
829829
}
830830
]
831831
},
@@ -881,7 +881,7 @@
881881
},
882882
"severity": 2,
883883
"source": "project",
884-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
884+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
885885
}
886886
]
887887
},
@@ -963,7 +963,7 @@
963963
},
964964
"severity": 2,
965965
"source": "project",
966-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
966+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
967967
}
968968
]
969969
},
@@ -1019,7 +1019,7 @@
10191019
},
10201020
"severity": 2,
10211021
"source": "project",
1022-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
1022+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
10231023
}
10241024
]
10251025
},

testsuite/ada_lsp/project_config.missing_file/test.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
}
9696
}
9797
},
98-
"message": "Project file has errors and can't be loaded."
98+
"message": "The project file has errors and could not be loaded."
9999
},
100100
{
101101
"location": {

testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
},
9393
"severity": 1,
9494
"source": "project",
95-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file."
95+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file."
9696
}
9797
]
9898
}
@@ -133,7 +133,7 @@
133133
"character": 0
134134
}
135135
},
136-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file.",
136+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file.",
137137
"severity": 1,
138138
"source": "project"
139139
}
@@ -178,7 +178,7 @@
178178
"character": 0
179179
}
180180
},
181-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file.",
181+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file.",
182182
"severity": 1,
183183
"source": "project"
184184
}
@@ -192,7 +192,7 @@
192192
"id": 13,
193193
"result": [
194194
{
195-
"title": "Open settings for ada.projectFile",
195+
"title": "Open settings to set ada.projectFile to a valid project",
196196
"kind": "quickfix",
197197
"diagnostics": [
198198
{
@@ -208,12 +208,12 @@
208208
},
209209
"severity": 1,
210210
"source": "project",
211-
"message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file."
211+
"message": "No project was loaded because multiple project files were found in the root directory. Please change the configuration to point to a single project file."
212212
}
213213
],
214214
"isPreferred": true,
215215
"command": {
216-
"title": "Open settings for ada.projectFile",
216+
"title": "Open settings to set ada.projectFile to a valid project",
217217
"command": "workbench.action.openSettings",
218218
"arguments": "ada.projectFile"
219219
}

testsuite/ada_lsp/project_configured_not_found/test.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"params": {
5151
"settings": {
5252
"ada": {
53-
"projectFile": "URI{foo_bar.gpr}"
53+
"projectFile": "$URI{foo_bar.gpr}"
5454
}
5555
}
5656
}
@@ -86,7 +86,7 @@
8686
},
8787
"severity": 1,
8888
"source": "project",
89-
"message": "Configured project doesn't exist."
89+
"message": "The configured project $URI{foo_bar.gpr} does not exist."
9090
}
9191
]
9292
}

testsuite/ada_lsp/publish_diag/diag_on_open.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
},
7777
"severity": 2,
7878
"source": "project",
79-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
79+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
8080
}
8181
]
8282
}

testsuite/ada_lsp/publish_diag/publish_diag.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
},
113113
"severity": 2,
114114
"source": "project",
115-
"message": "No project found in root directory. Please create a project file and add it to the configuration."
115+
"message": "No project was found in the root directory. Please create a GPR project file and add it to the configuration."
116116
}
117117
]
118118
}

testsuite/ada_lsp/refactoring_diagnostics/test.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
}
186186
}
187187
},
188-
"message": "Unique project in root directory was found and loaded, but it wasn't explicitly configured."
188+
"message": "A unique project in the root directory was found and loaded but it was not explicitly configured."
189189
}
190190
]
191191
},

0 commit comments

Comments
 (0)