15
15
-- of the license. --
16
16
-- ----------------------------------------------------------------------------
17
17
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
-
27
18
package body LSP.Ada_Handlers.Project_Diagnostics is
28
19
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
-
67
20
-- ------------------
68
21
-- Get_Diagnostic --
69
22
-- ------------------
70
23
71
24
overriding procedure Get_Diagnostic
72
25
(Self : in out Diagnostic_Source;
73
26
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
184
28
begin
185
- Self.Last_Status := Self.Handler.Project_Status.Load_Status ;
29
+ Self.Last_Status := Self.Handler.Project_Status;
186
30
31
+ Self.Handler.Tracer.Trace (" Diag: " & Self.Last_Status'Image);
187
32
-- If we have a valid project return immediately: we want to display
188
33
-- diagnostics only if there is an issue to solve or a potential
189
34
-- 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;
198
35
199
- Errors.Append (Parent_Diagnostic);
36
+ Errors.Append_Vector
37
+ (LSP.Ada_Project_Loading.Get_Diagnostics (Self.Last_Status));
200
38
end Get_Diagnostic ;
201
39
202
40
-- ----------------------
@@ -210,9 +48,9 @@ package body LSP.Ada_Handlers.Project_Diagnostics is
210
48
is
211
49
pragma Unreferenced (Context);
212
50
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);
216
54
end Has_New_Diagnostic ;
217
55
218
56
end LSP.Ada_Handlers.Project_Diagnostics ;
0 commit comments