@@ -282,7 +282,7 @@ procedure LSP.Ada_Driver is
282282 then VSS.Standard_Paths.Writable_Location
283283 (VSS.Standard_Paths.Home_Location)
284284 else ALS_Home)));
285- ALS_Dir : constant Virtual_File := Home_Dir / " .als" ;
285+ ALS_Dir : Virtual_File := Home_Dir / " .als" ;
286286 Clean_ALS_Dir : Boolean := False;
287287 GNATdebug : constant Virtual_File := Create_From_Base
288288 (" .gnatdebug" );
@@ -357,36 +357,57 @@ begin
357357 else
358358 -- No $HOME/.als directory: create one first
359359 if not ALS_Dir.Is_Directory then
360- Make_Dir (ALS_Dir);
361- end if ;
362-
363- Traces_File := Create_From_Dir
364- (Dir => ALS_Dir,
365- Base_Name =>
366- (if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
367- " gpr_ls" else " ada_ls" ) & " _traces.cfg" );
368-
369- -- No default traces file found: create one
370- if not Traces_File.Is_Regular_File then
371- declare
372- W_Traces_File : Writable_File;
373- Default_Traces_File_Contents : constant String :=
374- " >"
375- & (if VSS.Command_Line.Is_Specified (Language_GPR_Option)
376- then " gpr_ls" else " ada_ls" )
377- & " _log.$T.log:buffer_size=0" & Ada.Characters.Latin_1.LF
378- & " ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
379- & " ALS.IN=no" & Ada.Characters.Latin_1.LF
380- & " ALS.OUT=no" & Ada.Characters.Latin_1.LF;
381360 begin
382- W_Traces_File := Traces_File.Write_File;
383- W_Traces_File.Write (Default_Traces_File_Contents);
384- W_Traces_File.Close;
361+ Make_Dir (ALS_Dir);
362+
363+ exception
364+ -- We have caught an exception when trying to create a default
365+ -- traces file: warn the user
366+ when GNATCOLL.VFS.VFS_Directory_Error =>
367+ Ada.Text_IO.Put_Line
368+ (Ada.Text_IO.Standard_Error,
369+ " warning: Could not create default ALS log directory at '"
370+ & ALS_Dir.Display_Full_Name & " '"
371+ & Ada.Characters.Latin_1.LF
372+ & " Please make sure the parent directory is writable or "
373+ & " specify another parent directory via the ALS_HOME "
374+ & " environment variable." );
375+ ALS_Dir := GNATCOLL.VFS.No_File;
385376 end ;
386377 end if ;
387378
388- Clean_ALS_Dir := True;
379+ -- If the ALS directory is valid, parse any existing trace file or
380+ -- create a default one if needed.
381+
382+ if ALS_Dir.Is_Directory then
383+ Traces_File := Create_From_Dir
384+ (Dir => ALS_Dir,
385+ Base_Name =>
386+ (if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
387+ " gpr_ls" else " ada_ls" ) & " _traces.cfg" );
388+
389+ -- No default traces file found: create one if we can
390+ if not Traces_File.Is_Regular_File and then ALS_Dir.Is_Writable then
391+ declare
392+ W_Traces_File : Writable_File;
393+ Default_Traces_File_Contents : constant String :=
394+ " >"
395+ & (if VSS.Command_Line.Is_Specified (Language_GPR_Option)
396+ then " gpr_ls" else " ada_ls" )
397+ & " _log.$T.log:buffer_size=0" & Ada.Characters.Latin_1.LF
398+ & " ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
399+ & " ALS.IN=no" & Ada.Characters.Latin_1.LF
400+ & " ALS.OUT=no" & Ada.Characters.Latin_1.LF;
401+ begin
402+ W_Traces_File := Traces_File.Write_File;
403+ W_Traces_File.Write (Default_Traces_File_Contents);
404+ W_Traces_File.Close;
405+ end ;
406+ end if ;
407+ end if ;
408+
389409 Parse_Config_File (Traces_File);
410+ Clean_ALS_Dir := True;
390411 end if ;
391412
392413 -- Look for a config file, that contains the configuration for the server
0 commit comments