Skip to content

Commit d9fa9b1

Browse files
committed
Merge branch 'topic/gpr2_warns/edge' into 'edge'
Emit a diagnostic if no runtime found. See merge request eng/ide/ada_language_server!1189
2 parents e57488a + 86b9626 commit d9fa9b1

File tree

7 files changed

+251
-47
lines changed

7 files changed

+251
-47
lines changed

source/ada/lsp-ada_handlers-project_diagnostics.adb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
2424
("Unique project in root directory was found and " &
2525
"loaded, but it wasn't explicitly configured.");
2626

27+
No_Runtime_Found_Message : constant VSS.Strings.Virtual_String :=
28+
VSS.Strings.To_Virtual_String
29+
("The project was loaded, but no Ada runtime found. " &
30+
"Please check the installation of the Ada compiler.");
31+
2732
No_Project_Found_Message : constant VSS.Strings.Virtual_String :=
2833
VSS.Strings.To_Virtual_String
2934
("No project found in root directory. " &
@@ -58,6 +63,9 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
5863
case Self.Last_Status is
5964
when Valid_Project_Configured | Alire_Project =>
6065
null;
66+
when No_Runtime_Found =>
67+
Item.message := No_Runtime_Found_Message;
68+
Errors.Append (Item);
6169
when Single_Project_Found =>
6270
Item.message := Single_Project_Found_Message;
6371
Item.severity := (True, LSP.Messages.Hint);

source/ada/lsp-ada_handlers.adb

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ with Ada.Characters.Handling; use Ada.Characters.Handling;
2020
with Ada.Characters.Wide_Wide_Latin_1;
2121
with Ada.Containers.Indefinite_Hashed_Maps;
2222
with Ada.Exceptions;
23-
with Ada.Characters.Latin_1;
2423
with Ada.Strings.Wide_Wide_Unbounded;
2524
with Ada.Strings.UTF_Encoding;
2625
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
@@ -31,7 +30,6 @@ with GNATCOLL.Utils; use GNATCOLL.Utils;
3130

3231
with GPR2.Containers;
3332
with GPR2.Environment;
34-
with GPR2.Log;
3533
with GPR2.Message;
3634
with GPR2.Project.Registry.Attribute;
3735
with GPR2.Project.Source.Set;
@@ -2295,6 +2293,9 @@ package body LSP.Ada_Handlers is
22952293
case Self.Project_Status is
22962294
when Valid_Project_Configured | Alire_Project =>
22972295
null;
2296+
when No_Runtime_Found =>
2297+
-- TODO: Provide help with the compiler installation
2298+
null;
22982299
when Single_Project_Found | Multiple_Projects_Found =>
22992300
declare
23002301
Item : LSP.Messages.CodeAction;
@@ -4861,8 +4862,9 @@ package body LSP.Ada_Handlers is
48614862
Charset : VSS.Strings.Virtual_String;
48624863
Status : Load_Project_Status)
48634864
is
4864-
Errors : LSP.Messages.ShowMessageParams;
4865-
Error_Text : VSS.String_Vectors.Virtual_String_Vector;
4865+
Message : LSP.Messages.ShowMessageParams;
4866+
Errors : VSS.String_Vectors.Virtual_String_Vector;
4867+
Warnings : VSS.String_Vectors.Virtual_String_Vector;
48664868

48674869
procedure Create_Context_For_Non_Aggregate
48684870
(View : GPR2.Project.View.Object);
@@ -4880,17 +4882,19 @@ package body LSP.Ada_Handlers is
48804882

48814883
procedure Append_Errors is
48824884
begin
4883-
for C in Self.Project_Tree.Log_Messages.Iterate
4884-
(Information => False,
4885-
Warning => False,
4886-
Error => True,
4887-
Lint => False,
4888-
Read => True,
4889-
Unread => True)
4890-
loop
4891-
Error_Text.Append
4892-
(VSS.Strings.Conversions.To_Virtual_String
4893-
(GPR2.Log.Element (C).Format));
4885+
for Message of Self.Project_Tree.Log_Messages.all loop
4886+
case Message.Level is
4887+
when GPR2.Message.Error =>
4888+
Errors.Append
4889+
(VSS.Strings.Conversions.To_Virtual_String
4890+
(Message.Format));
4891+
when GPR2.Message.Warning =>
4892+
Warnings.Append
4893+
(VSS.Strings.Conversions.To_Virtual_String
4894+
(Message.Format));
4895+
when others =>
4896+
null;
4897+
end case;
48944898
end loop;
48954899
end Append_Errors;
48964900

@@ -4976,11 +4980,8 @@ package body LSP.Ada_Handlers is
49764980
-- Unload the project tree and the project environment
49774981
Self.Release_Contexts_And_Project_Info;
49784982

4979-
Self.Project_Status := Status;
4980-
49814983
-- Now load the new project
4982-
Errors.a_type := LSP.Messages.Warning;
4983-
4984+
Self.Project_Status := Status;
49844985
Self.Project_Environment := Default_Environment;
49854986

49864987
if Relocate_Build_Tree /= No_File then
@@ -5013,43 +5014,60 @@ package body LSP.Ada_Handlers is
50135014
Build_Path => Self.Project_Environment.Build_Path,
50145015
Environment => Environment);
50155016

5016-
Self.Project_Tree.Update_Sources (With_Runtime => True);
5017+
exception
5018+
when E : GPR2.Project_Error
5019+
| GPR2.Processing_Error
5020+
| GPR2.Attribute_Error =>
5021+
5022+
Self.Trace.Trace (E);
50175023

5018-
Append_Errors;
5024+
Self.Project_Status := Invalid_Project_Configured;
5025+
end;
5026+
5027+
-- Keep errors and warnings
5028+
Append_Errors;
50195029

5030+
if Self.Project_Status /= Status
5031+
or else not Self.Project_Tree.Is_Defined
5032+
then
5033+
-- The project was invalid: fallback on loading the implicit project.
5034+
Errors.Prepend
5035+
(VSS.Strings.Conversions.To_Virtual_String
5036+
("Unable to load project file: " & GPR.Display_Full_Name));
5037+
5038+
Self.Load_Implicit_Project (Invalid_Project_Configured);
5039+
5040+
else
5041+
-- No exception during Load_Autoconf, check if we have runtime
5042+
if not Self.Project_Tree.Has_Runtime_Project then
5043+
Self.Project_Status := No_Runtime_Found;
5044+
end if;
5045+
5046+
Self.Project_Tree.Update_Sources (With_Runtime => True);
50205047
Update_Project_Predefined_Sources (Self);
50215048

50225049
if Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind then
50235050
for View of Self.Project_Tree.Root_Project.Aggregated loop
50245051
Create_Context_For_Non_Aggregate (View);
50255052
end loop;
50265053
else
5027-
Create_Context_For_Non_Aggregate (Self.Project_Tree.Root_Project);
5054+
Create_Context_For_Non_Aggregate
5055+
(Self.Project_Tree.Root_Project);
50285056
end if;
5029-
exception
5030-
when E : GPR2.Project_Error | GPR2.Processing_Error
5031-
| GPR2.Attribute_Error =>
5032-
Append_Errors;
5033-
5034-
Self.Trace.Trace (E);
5035-
Errors.a_type := LSP.Messages.Error;
5036-
5037-
Errors.message.Append
5038-
(VSS.Strings.Conversions.To_Virtual_String
5039-
("Unable to load project file: " &
5040-
String (GPR.Full_Name.all) & Ada.Characters.Latin_1.LF));
5057+
end if;
50415058

5042-
-- The project was invalid: fallback on loading the implicit
5043-
-- project.
5044-
Self.Load_Implicit_Project (Invalid_Project_Configured);
5045-
end;
5059+
-- Report the warnings, if any
5060+
if not Warnings.Is_Empty then
5061+
Message.message := Warnings.Join_Lines (VSS.Strings.LF);
5062+
Message.a_type := LSP.Messages.Warning;
5063+
Self.Server.On_Show_Message (Message);
5064+
end if;
50465065

50475066
-- Report the errors, if any
5048-
if not Error_Text.Is_Empty then
5049-
for Line of Error_Text loop
5050-
Errors.message.Append (Line);
5051-
end loop;
5052-
Self.Server.On_Show_Message (Errors);
5067+
if not Errors.Is_Empty then
5068+
Message.message := Errors.Join_Lines (VSS.Strings.LF);
5069+
Message.a_type := LSP.Messages.Error;
5070+
Self.Server.On_Show_Message (Message);
50535071
end if;
50545072

50555073
-- Reindex all open documents immediately after project reload, so

source/ada/lsp-ada_handlers.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ private
176176
(Valid_Project_Configured,
177177
Single_Project_Found,
178178
Alire_Project,
179+
No_Runtime_Found,
179180
No_Project_Found,
180181
Multiple_Projects_Found,
181182
Invalid_Project_Configured);
@@ -190,6 +191,9 @@ private
190191
-- @value Alire_Project no project in didChangeConfiguration, but Alire
191192
-- knows what project to use
192193
--
194+
-- @value No_Runtime_Found project loaded, but no Ada runtime library was
195+
-- found
196+
--
193197
-- @value No_Project_Found no project in didChangeConfiguration and no
194198
-- project in Root dir
195199
--
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
project Default is
22
for Main use ("foo.adb");
3-
-- Magical line to not parse the runtime:
4-
-- it prevents the test for being timeout
5-
for Runtime ("Ada") use "hello";
3+
for Runtime ("Ada") use "./rts-empty";
64
end Default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
------------------------------------------------------------------------------
2+
-- --
3+
-- GNAT RUN-TIME COMPONENTS --
4+
-- --
5+
-- A D A --
6+
-- --
7+
-- S p e c --
8+
-- --
9+
-- This specification is derived from the Ada Reference Manual for use with --
10+
-- GNAT. In accordance with the copyright of that document, you can freely --
11+
-- copy and modify this specification, provided that if you redistribute a --
12+
-- modified version, any changes that you have made are clearly indicated. --
13+
-- --
14+
------------------------------------------------------------------------------
15+
16+
package Ada is
17+
pragma No_Elaboration_Code_All;
18+
pragma Pure;
19+
20+
end Ada;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
------------------------------------------------------------------------------
2+
-- --
3+
-- GNAT RUN-TIME COMPONENTS --
4+
-- --
5+
-- S Y S T E M --
6+
-- --
7+
-- S p e c --
8+
-- (GNU-Linux/x86 Version) --
9+
-- --
10+
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
11+
-- --
12+
-- This specification is derived from the Ada Reference Manual for use with --
13+
-- GNAT. The copyright notice above, and the license provisions that follow --
14+
-- apply solely to the contents of the part following the private keyword. --
15+
-- --
16+
-- GNAT is free software; you can redistribute it and/or modify it under --
17+
-- terms of the GNU General Public License as published by the Free Soft- --
18+
-- ware Foundation; either version 3, or (at your option) any later ver- --
19+
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
20+
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
21+
-- or FITNESS FOR A PARTICULAR PURPOSE. --
22+
-- --
23+
-- As a special exception under Section 7 of GPL version 3, you are granted --
24+
-- additional permissions described in the GCC Runtime Library Exception, --
25+
-- version 3.1, as published by the Free Software Foundation. --
26+
-- --
27+
-- You should have received a copy of the GNU General Public License and --
28+
-- a copy of the GCC Runtime Library Exception along with this program; --
29+
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
30+
-- <http://www.gnu.org/licenses/>. --
31+
-- --
32+
-- GNAT was originally developed by the GNAT team at New York University. --
33+
-- Extensive contributions were provided by Ada Core Technologies Inc. --
34+
-- --
35+
------------------------------------------------------------------------------
36+
37+
package System is
38+
pragma Pure;
39+
-- Note that we take advantage of the implementation permission to make
40+
-- this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada
41+
-- 2005, this is Pure in any case (AI-362).
42+
43+
pragma No_Elaboration_Code_All;
44+
-- Allow the use of that restriction in units that WITH this unit
45+
46+
type Name is (SYSTEM_NAME_GNAT);
47+
System_Name : constant Name := SYSTEM_NAME_GNAT;
48+
49+
-- System-Dependent Named Numbers
50+
51+
Min_Int : constant := -2 ** (Standard'Max_Integer_Size - 1);
52+
Max_Int : constant := 2 ** (Standard'Max_Integer_Size - 1) - 1;
53+
54+
Max_Binary_Modulus : constant := 2 ** Standard'Max_Integer_Size;
55+
Max_Nonbinary_Modulus : constant := 2 ** Integer'Size - 1;
56+
57+
Max_Base_Digits : constant := Long_Long_Float'Digits;
58+
Max_Digits : constant := Long_Long_Float'Digits;
59+
60+
Max_Mantissa : constant := 63;
61+
Fine_Delta : constant := 2.0 ** (-Max_Mantissa);
62+
63+
Tick : constant := 0.000_001;
64+
65+
-- Storage-related Declarations
66+
67+
type Address is private;
68+
pragma Preelaborable_Initialization (Address);
69+
Null_Address : constant Address;
70+
71+
Storage_Unit : constant := 8;
72+
Word_Size : constant := Standard'Word_Size;
73+
Memory_Size : constant := 2 ** Long_Integer'Size;
74+
75+
-- Address comparison
76+
77+
function "<" (Left, Right : Address) return Boolean;
78+
function "<=" (Left, Right : Address) return Boolean;
79+
function ">" (Left, Right : Address) return Boolean;
80+
function ">=" (Left, Right : Address) return Boolean;
81+
function "=" (Left, Right : Address) return Boolean;
82+
83+
pragma Import (Intrinsic, "<");
84+
pragma Import (Intrinsic, "<=");
85+
pragma Import (Intrinsic, ">");
86+
pragma Import (Intrinsic, ">=");
87+
pragma Import (Intrinsic, "=");
88+
89+
-- Other System-Dependent Declarations
90+
91+
type Bit_Order is (High_Order_First, Low_Order_First);
92+
Default_Bit_Order : constant Bit_Order := Low_Order_First;
93+
pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning
94+
95+
-- Priority-related Declarations (RM D.1)
96+
97+
-- 0 .. 98 corresponds to the system priority range 1 .. 99.
98+
--
99+
-- If the scheduling policy is SCHED_FIFO or SCHED_RR the runtime makes use
100+
-- of the entire range provided by the system.
101+
--
102+
-- If the scheduling policy is SCHED_OTHER the only valid system priority
103+
-- is 1 and other values are simply ignored.
104+
105+
Max_Priority : constant Positive := 97;
106+
Max_Interrupt_Priority : constant Positive := 98;
107+
108+
subtype Any_Priority is Integer range 0 .. 98;
109+
subtype Priority is Any_Priority range 0 .. 97;
110+
subtype Interrupt_Priority is Any_Priority range 98 .. 98;
111+
112+
Default_Priority : constant Priority := 48;
113+
114+
private
115+
116+
type Address is mod Memory_Size;
117+
Null_Address : constant Address := 0;
118+
119+
--------------------------------------
120+
-- System Implementation Parameters --
121+
--------------------------------------
122+
123+
-- These parameters provide information about the target that is used
124+
-- by the compiler. They are in the private part of System, where they
125+
-- can be accessed using the special circuitry in the Targparm unit
126+
-- whose source should be consulted for more detailed descriptions
127+
-- of the individual switch values.
128+
129+
Backend_Divide_Checks : constant Boolean := False;
130+
Backend_Overflow_Checks : constant Boolean := True;
131+
Command_Line_Args : constant Boolean := True;
132+
Configurable_Run_Time : constant Boolean := False;
133+
Denorm : constant Boolean := True;
134+
Duration_32_Bits : constant Boolean := False;
135+
Exit_Status_Supported : constant Boolean := True;
136+
Fractional_Fixed_Ops : constant Boolean := False;
137+
Frontend_Layout : constant Boolean := False;
138+
Machine_Overflows : constant Boolean := False;
139+
Machine_Rounds : constant Boolean := True;
140+
Preallocated_Stacks : constant Boolean := False;
141+
Signed_Zeros : constant Boolean := True;
142+
Stack_Check_Default : constant Boolean := False;
143+
Stack_Check_Probes : constant Boolean := True;
144+
Stack_Check_Limits : constant Boolean := False;
145+
Support_Aggregates : constant Boolean := True;
146+
Support_Atomic_Primitives : constant Boolean := True;
147+
Support_Composite_Assign : constant Boolean := True;
148+
Support_Composite_Compare : constant Boolean := True;
149+
Support_Long_Shifts : constant Boolean := True;
150+
Always_Compatible_Rep : constant Boolean := False;
151+
Suppress_Standard_Library : constant Boolean := False;
152+
Use_Ada_Main_Program_Name : constant Boolean := False;
153+
Frontend_Exceptions : constant Boolean := False;
154+
ZCX_By_Default : constant Boolean := False;
155+
156+
end System;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
project Default is
22
for Main use ("main.adb");
3-
for Runtime ("Ada") use "rts-empty";
3+
for Runtime ("Ada") use "./rts-empty";
44
end Default;

0 commit comments

Comments
 (0)