Skip to content

Commit 8bf7741

Browse files
BoulangerAdrienBoulanger
Boulanger
authored andcommitted
Rewrite project status data
Create a specific package to handle project status which is a combination of project type and a load status. Only use implicit project for specific cases and remove it as a fallback mechanism. To replace it, create an empty context when the project can't be loaded. Add a test For eng/ide/ada_language_server#1358
1 parent 5c940b2 commit 8bf7741

15 files changed

+883
-454
lines changed

Diff for: gnat/lsp_server.gpr

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ project LSP_Server is
3838

3939
for Object_Dir use "../.obj/server";
4040
for Main use ("lsp-ada_driver.adb");
41+
-- Need C++ to use a linker compatible with libfswatch
4142
for Languages use ("Ada", "C++");
4243

4344
package Naming is

Diff for: source/ada/lsp-ada_handlers-project_diagnostics.adb

+8-170
Original file line numberDiff line numberDiff line change
@@ -15,188 +15,26 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with GPR2.Source_Reference;
19-
with GPR2.Message;
20-
with GPR2.Path_Name;
21-
22-
with VSS.Strings;
23-
24-
with LSP.Enumerations;
25-
with LSP.Utils;
26-
2718
package body LSP.Ada_Handlers.Project_Diagnostics is
2819

29-
Project_Loading_Status_Messages : constant array (Load_Project_Status)
30-
of VSS.Strings.Virtual_String :=
31-
(Single_Project_Found =>
32-
VSS.Strings.To_Virtual_String
33-
("Unique project in root directory was found and "
34-
& "loaded, but it wasn't explicitly configured."),
35-
No_Runtime_Found =>
36-
VSS.Strings.To_Virtual_String
37-
("The project was loaded, but no Ada runtime found. "
38-
& "Please check the installation of the Ada compiler."),
39-
No_Project_Found =>
40-
VSS.Strings.To_Virtual_String
41-
("No project found in root directory. "
42-
& "Please create a project file and add it to the "
43-
& "configuration."),
44-
Multiple_Projects_Found =>
45-
VSS.Strings.To_Virtual_String
46-
("No project was loaded, because more than one "
47-
& "project file has been found in the root directory. "
48-
& "Please change configuration to point a correct project "
49-
& "file."),
50-
Invalid_Project_Configured =>
51-
VSS.Strings.To_Virtual_String
52-
("Project file has errors and can't be loaded."),
53-
others => VSS.Strings.Empty_Virtual_String);
54-
-- The diagnostics' messages depending on the project loading status.
55-
56-
Project_Loading_Status_Severities : constant array (Load_Project_Status)
57-
of LSP.Enumerations.DiagnosticSeverity :=
58-
(Valid_Project_Configured => LSP.Enumerations.Hint,
59-
Alire_Project => LSP.Enumerations.Hint,
60-
Single_Project_Found => LSP.Enumerations.Hint,
61-
No_Runtime_Found => LSP.Enumerations.Warning,
62-
Multiple_Projects_Found => LSP.Enumerations.Error,
63-
No_Project_Found => LSP.Enumerations.Error,
64-
Invalid_Project_Configured => LSP.Enumerations.Error);
65-
-- The diagnostics' severities depending on the project loading status.
66-
6720
--------------------
6821
-- Get_Diagnostic --
6922
--------------------
7023

7124
overriding procedure Get_Diagnostic
7225
(Self : in out Diagnostic_Source;
7326
Context : LSP.Ada_Contexts.Context;
74-
Errors : out LSP.Structures.Diagnostic_Vector)
75-
is
76-
use LSP.Structures;
77-
78-
Parent_Diagnostic : LSP.Structures.Diagnostic;
79-
GPR2_Messages : GPR2.Log.Object renames
80-
Self.Handler.Project_Status.GPR2_Messages;
81-
82-
procedure Create_Project_Loading_Diagnostic;
83-
-- Create a parent diagnostic for the project loading status.
84-
85-
procedure Append_GPR2_Diagnostics;
86-
-- Append the GPR2 messages to the given parent diagnostic, if any.
87-
88-
---------------------------------------
89-
-- Create_Project_Loading_Diagnostic --
90-
---------------------------------------
91-
92-
procedure Create_Project_Loading_Diagnostic is
93-
Sloc : constant LSP.Structures.A_Range :=
94-
(start => (0, 0),
95-
an_end => (0, 0));
96-
begin
97-
-- Initialize the parent diagnostic.
98-
Parent_Diagnostic.a_range := ((0, 0), (0, 0));
99-
Parent_Diagnostic.source := "project";
100-
Parent_Diagnostic.severity :=
101-
(True, Project_Loading_Status_Severities (Self.Last_Status));
102-
103-
-- If we don't have any GPR2 messages, display the project loading
104-
-- status message in the parent diagnostic directly.
105-
-- Otherwise display a generic message in the parent amnd append it
106-
-- to its children, along with the other GPR2 messages.
107-
if GPR2_Messages.Is_Empty then
108-
Parent_Diagnostic.message := Project_Loading_Status_Messages
109-
(Self.Last_Status);
110-
else
111-
declare
112-
Project_File : GNATCOLL.VFS.Virtual_File renames
113-
Self.Handler.Project_Status.Project_File;
114-
URI : constant LSP.Structures.DocumentUri :=
115-
Self.Handler.To_URI
116-
(Project_File.Display_Full_Name);
117-
begin
118-
Parent_Diagnostic.message := "Project Problems";
119-
Parent_Diagnostic.relatedInformation.Append
120-
(LSP.Structures.DiagnosticRelatedInformation'
121-
(location =>
122-
LSP.Structures.Location'
123-
(uri => URI, a_range => Sloc,
124-
others => <>),
125-
message =>
126-
Project_Loading_Status_Messages
127-
(Self.Last_Status)));
128-
end;
129-
end if;
130-
end Create_Project_Loading_Diagnostic;
131-
132-
-----------------------------
133-
-- Append_GPR2_Diagnostics --
134-
-----------------------------
135-
136-
procedure Append_GPR2_Diagnostics is
137-
use GPR2.Message;
138-
use LSP.Enumerations;
139-
begin
140-
for Msg of GPR2_Messages loop
141-
if Msg.Level in GPR2.Message.Warning .. GPR2.Message.Error then
142-
declare
143-
Sloc : constant GPR2.Source_Reference.Object :=
144-
GPR2.Message.Sloc (Msg);
145-
File : constant GPR2.Path_Name.Object :=
146-
(if Sloc.Is_Defined and then Sloc.Has_Source_Reference
147-
then
148-
GPR2.Path_Name.Create_File
149-
(GPR2.Filename_Type (Sloc.Filename))
150-
else
151-
Self.Handler.Project_Tree.Root_Path);
152-
begin
153-
-- Display a diagnostic for GPR2 messages only if the file
154-
-- attached to the message is defined.
155-
if File.Is_Defined and then File.Has_Value then
156-
Parent_Diagnostic.relatedInformation.Append
157-
(LSP .Structures.DiagnosticRelatedInformation'
158-
(location => LSP.Structures.Location'
159-
(uri => LSP.Utils.To_URI (File),
160-
a_range => LSP.Utils.To_Range (Sloc),
161-
others => <>),
162-
message =>
163-
VSS.Strings.Conversions.To_Virtual_String
164-
(Msg.Message)));
165-
end if;
166-
end;
167-
168-
-- If we have one error in the GPR2 messages, the parent
169-
-- diagnostic's severity should be "error" too, otherwise
170-
-- "warning".
171-
if Msg.Level = GPR2.Message.Error then
172-
Parent_Diagnostic.severity :=
173-
(True, LSP.Enumerations.Error);
174-
elsif Parent_Diagnostic.severity.Value /=
175-
LSP.Enumerations.Error
176-
then
177-
Parent_Diagnostic.severity :=
178-
(True, LSP.Enumerations.Warning);
179-
end if;
180-
end if;
181-
end loop;
182-
end Append_GPR2_Diagnostics;
183-
27+
Errors : out LSP.Structures.Diagnostic_Vector) is
18428
begin
185-
Self.Last_Status := Self.Handler.Project_Status.Load_Status;
29+
Self.Last_Status := Self.Handler.Project_Status;
18630

31+
Self.Handler.Tracer.Trace ("Diag: " & Self.Last_Status'Image);
18732
-- If we have a valid project return immediately: we want to display
18833
-- diagnostics only if there is an issue to solve or a potential
18934
-- enhancement.
190-
if Self.Last_Status = Valid_Project_Configured
191-
or else (Self.Last_Status = Alire_Project and then GPR2_Messages.Is_Empty)
192-
then
193-
return;
194-
end if;
195-
196-
Create_Project_Loading_Diagnostic;
197-
Append_GPR2_Diagnostics;
19835

199-
Errors.Append (Parent_Diagnostic);
36+
Errors.Append_Vector
37+
(LSP.Ada_Project_Loading.Get_Diagnostics (Self.Last_Status));
20038
end Get_Diagnostic;
20139

20240
------------------------
@@ -210,9 +48,9 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
21048
is
21149
pragma Unreferenced (Context);
21250
begin
213-
return
214-
(Self.Last_Status /= Self.Handler.Project_Status.Load_Status
215-
or else not Self.Handler.Project_Status.GPR2_Messages.Is_Empty);
51+
return LSP.Ada_Project_Loading.Has_New_Diagnostics
52+
(Self.Last_Status,
53+
Self.Handler.Project_Status);
21654
end Has_New_Diagnostic;
21755

21856
end LSP.Ada_Handlers.Project_Diagnostics;

Diff for: source/ada/lsp-ada_handlers-project_diagnostics.ads

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
------------------------------------------------------------------------------
1717

1818
with LSP.Ada_Contexts;
19+
with LSP.Ada_Project_Loading;
1920
with LSP.Diagnostic_Sources;
2021

2122
package LSP.Ada_Handlers.Project_Diagnostics is
@@ -39,7 +40,7 @@ private
3940
type Diagnostic_Source
4041
(Handler : not null access LSP.Ada_Handlers.Message_Handler)
4142
is limited new LSP.Diagnostic_Sources.Diagnostic_Source with record
42-
Last_Status : Load_Project_Status := No_Project_Found;
43+
Last_Status : LSP.Ada_Project_Loading.Project_Status_Type;
4344
end record;
4445

4546
end LSP.Ada_Handlers.Project_Diagnostics;

0 commit comments

Comments
 (0)