@@ -63,6 +63,9 @@ package body LSP.Ada_Handlers.Project_Loading is
6363 GNATCOLL.Traces.Create (" ALS.RUNTIME_INDEXING" , GNATCOLL.Traces.On);
6464 -- Trace to enable/disable runtime indexing. Useful for the testsuite.
6565
66+ Fallback_Msg : constant VSS.Strings.Virtual_String :=
67+ " Falling back to other methods to load a project" ;
68+
6669 type GPR2_Reporter is new GPR2.Reporter.Object with record
6770 Log : GPR2.Log.Object;
6871 end record ;
@@ -136,8 +139,8 @@ package body LSP.Ada_Handlers.Project_Loading is
136139
137140 C : constant Context_Access := new Context (Self.Tracer);
138141
139- Reader : LSP.Ada_Handlers.File_Readers.LSP_File_Reader
140- (Self'Unchecked_Access);
142+ Reader :
143+ LSP.Ada_Handlers.File_Readers.LSP_File_Reader (Self'Unchecked_Access);
141144
142145 Dirs : File_Sets.Set;
143146
@@ -160,17 +163,17 @@ package body LSP.Ada_Handlers.Project_Loading is
160163 Create_In_Memory_Project
161164 (" fallback_context" , Dirs, Project_Tree, Success);
162165
163- pragma Assert
164- (Success, " Can't create an empty project for the fallback context" );
166+ pragma
167+ Assert
168+ (Success, " Can't create an empty project for the fallback context" );
165169
166170 -- Create a basic GPR2_Provider_And_Projects containing only the
167171 -- implicit project and load it.
168172 declare
169173 Provider : Libadalang.Project_Provider.GPR2_Provider_And_Projects :=
170174 (Provider =>
171175 Libadalang.Project_Provider.Create_Project_Unit_Provider
172- (Tree => Project_Tree,
173- Project => Project_Tree.Root_Project),
176+ (Tree => Project_Tree, Project => Project_Tree.Root_Project),
174177 Projects => <>);
175178 begin
176179 Provider.Projects.Append (Project_Tree.Root_Project);
@@ -224,34 +227,54 @@ package body LSP.Ada_Handlers.Project_Loading is
224227 (LSP.Ada_Project_Loading.Configured_Project);
225228
226229 elsif Is_Alire_Crate then
227- Tracer.Trace (" Workspace is an Alire crate" );
228-
229- Tracer.Trace (" Performing minimal Alire sync" );
230- LSP.Alire.Conservative_Alire_Sync
231- (Self.Client.Root_Directory.Display_Full_Name, Alire_Error);
230+ declare
232231
233- if not Alire_Error.Is_Empty then
234- Tracer.Trace_Text (" Encountered errors: " & Alire_Error);
235- Self.Project_Status.Set_Alire_Messages ([Alire_Error]);
236- else
237- Tracer.Trace (" Determining project from 'alr show' output" );
232+ procedure Report_Alire_Errors ;
238233
239- LSP.Alire.Determine_Alire_Project
240- (Root => Self.Client.Root_Directory.Display_Full_Name,
241- Error => Alire_Error,
242- Project => Project_File);
234+ procedure Report_Alire_Errors is
235+ begin
236+ -- If the error is multi-line, use a separate line for the
237+ -- fallback message. Otherwise, keep a single line.
238+ if Alire_Error.Split_Lines.Length > 1 then
239+ Alire_Error.Append (VSS.Characters.Latin.Line_Feed);
240+ else
241+ Alire_Error.Append (" : " );
242+ end if ;
243+ Alire_Error.Append (Fallback_Msg);
243244
244- if not Alire_Error.Is_Empty then
245245 Tracer.Trace_Text (" Encountered errors: " & Alire_Error);
246246 Self.Project_Status.Set_Alire_Messages ([Alire_Error]);
247+ end Report_Alire_Errors ;
248+
249+ begin
250+
251+ Tracer.Trace (" Workspace is an Alire crate" );
252+
253+ Tracer.Trace (" Performing minimal Alire sync" );
254+ LSP.Alire.Conservative_Alire_Sync
255+ (Self.Client.Root_Directory.Display_Full_Name, Alire_Error);
256+
257+ if not Alire_Error.Is_Empty then
258+ Report_Alire_Errors;
247259 else
248- -- Report how we found the project
249- Self.Project_Status.Set_Project_Type
250- (LSP.Ada_Project_Loading.Alire_Project);
251- Self.Project_Status.Set_Alire_Messages ([]);
252- end if ;
260+ Tracer.Trace (" Determining project from 'alr show' output" );
253261
254- end if ;
262+ LSP.Alire.Determine_Alire_Project
263+ (Root => Self.Client.Root_Directory.Display_Full_Name,
264+ Error => Alire_Error,
265+ Project => Project_File);
266+
267+ if not Alire_Error.Is_Empty then
268+ Report_Alire_Errors;
269+ else
270+ -- Report how we found the project
271+ Self.Project_Status.Set_Project_Type
272+ (LSP.Ada_Project_Loading.Alire_Project);
273+ Self.Project_Status.Set_Alire_Messages ([]);
274+ end if ;
275+
276+ end if ;
277+ end ;
255278
256279 end if ;
257280
@@ -354,7 +377,8 @@ package body LSP.Ada_Handlers.Project_Loading is
354377
355378 Load_Implicit_Project
356379 (Self,
357- (if Candidates.Length = 0 then LSP.Ada_Project_Loading.No_Project
380+ (if Candidates.Length = 0
381+ then LSP.Ada_Project_Loading.No_Project
358382 elsif Candidates.Length > 1
359383 then LSP.Ada_Project_Loading.Multiple_Projects
360384 else LSP.Ada_Project_Loading.Project_Not_Found));
@@ -857,8 +881,7 @@ package body LSP.Ada_Handlers.Project_Loading is
857881 is
858882 Project : GPR2.Project.Tree.View_Builder.Object :=
859883 GPR2.Project.Tree.View_Builder.Create
860- (Project_Dir => GPR2.Path_Name.Create_Directory (" ." ),
861- Name => Name);
884+ (Project_Dir => GPR2.Path_Name.Create_Directory (" ." ), Name => Name);
862885 Values : GPR2.Containers.Value_List;
863886 Opts : GPR2.Options.Object;
864887 Reporter : GPR2_Reporter;
0 commit comments