Skip to content

Commit a25d0b0

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents eede788 + 9a310e7 commit a25d0b0

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ procedure LSP.Ada_Driver is
283283
then VSS.Standard_Paths.Writable_Location
284284
(VSS.Standard_Paths.Home_Location)
285285
else ALS_Home)));
286-
ALS_Dir : constant Virtual_File := Home_Dir / ".als";
286+
ALS_Dir : Virtual_File := Home_Dir / ".als";
287287
Clean_ALS_Dir : Boolean := False;
288288
GNATdebug : constant Virtual_File := Create_From_Base
289289
(".gnatdebug");
@@ -358,36 +358,57 @@ begin
358358
else
359359
-- No $HOME/.als directory: create one first
360360
if not ALS_Dir.Is_Directory then
361-
Make_Dir (ALS_Dir);
362-
end if;
363-
364-
Traces_File := Create_From_Dir
365-
(Dir => ALS_Dir,
366-
Base_Name =>
367-
(if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
368-
"gpr_ls" else "ada_ls") & "_traces.cfg");
369-
370-
-- No default traces file found: create one
371-
if not Traces_File.Is_Regular_File then
372-
declare
373-
W_Traces_File : Writable_File;
374-
Default_Traces_File_Contents : constant String :=
375-
">"
376-
& (if VSS.Command_Line.Is_Specified (Language_GPR_Option)
377-
then "gpr_ls" else "ada_ls")
378-
& "_log.$T.log:buffer_size=0" & Ada.Characters.Latin_1.LF
379-
& "ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
380-
& "ALS.IN=no" & Ada.Characters.Latin_1.LF
381-
& "ALS.OUT=no" & Ada.Characters.Latin_1.LF;
382361
begin
383-
W_Traces_File := Traces_File.Write_File;
384-
W_Traces_File.Write (Default_Traces_File_Contents);
385-
W_Traces_File.Close;
362+
Make_Dir (ALS_Dir);
363+
364+
exception
365+
-- We have caught an exception when trying to create the .als
366+
-- directory: warn the user.
367+
when GNATCOLL.VFS.VFS_Directory_Error =>
368+
Ada.Text_IO.Put_Line
369+
(Ada.Text_IO.Standard_Error,
370+
"warning: Could not create default ALS log directory at '"
371+
& ALS_Dir.Display_Full_Name & "'"
372+
& Ada.Characters.Latin_1.LF
373+
& "Please make sure the parent directory is writable or "
374+
& "specify another parent directory via the ALS_HOME "
375+
& "environment variable.");
376+
ALS_Dir := GNATCOLL.VFS.No_File;
386377
end;
387378
end if;
388379

389-
Clean_ALS_Dir := True;
380+
-- If the ALS directory is valid, parse any existing trace file or
381+
-- create a default one if needed.
382+
383+
if ALS_Dir.Is_Directory then
384+
Traces_File := Create_From_Dir
385+
(Dir => ALS_Dir,
386+
Base_Name =>
387+
(if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
388+
"gpr_ls" else "ada_ls") & "_traces.cfg");
389+
390+
-- No default traces file found: create one if we can
391+
if not Traces_File.Is_Regular_File and then ALS_Dir.Is_Writable then
392+
declare
393+
W_Traces_File : Writable_File;
394+
Default_Traces_File_Contents : constant String :=
395+
">"
396+
& (if VSS.Command_Line.Is_Specified (Language_GPR_Option)
397+
then "gpr_ls" else "ada_ls")
398+
& "_log.$T.log:buffer_size=0" & Ada.Characters.Latin_1.LF
399+
& "ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
400+
& "ALS.IN=no" & Ada.Characters.Latin_1.LF
401+
& "ALS.OUT=no" & Ada.Characters.Latin_1.LF;
402+
begin
403+
W_Traces_File := Traces_File.Write_File;
404+
W_Traces_File.Write (Default_Traces_File_Contents);
405+
W_Traces_File.Close;
406+
end;
407+
end if;
408+
end if;
409+
390410
Parse_Config_File (Traces_File);
411+
Clean_ALS_Dir := True;
391412
end if;
392413

393414
-- Look for a config file, that contains the configuration for the server

0 commit comments

Comments
 (0)