1616-- ----------------------------------------------------------------------------
1717
1818with LSP.Utils ;
19+ with VSS.Standard_Paths ;
1920
2021package body LSP.Env is
2122
@@ -24,55 +25,75 @@ package body LSP.Env is
2425 -- ------------
2526
2627 function Home_Dir return GNATCOLL.VFS.Virtual_File is
28+ Home_Path : constant VSS.Strings.Virtual_String :=
29+ VSS.Standard_Paths.Writable_Location
30+ (VSS.Standard_Paths.Home_Location);
2731 begin
28- if Home .Is_Empty then
32+ if Home_Path .Is_Empty then
2933 raise Program_Error
30- with
31- " The HOME environment variable is empty, ALS cannot proceed safely." ;
34+ with " Unable to determine the user home location, ALS cannot proceed safely." ;
35+ else
36+ declare
37+ Result : constant GNATCOLL.VFS.Virtual_File :=
38+ LSP.Utils.To_Virtual_File (Home_Path);
39+ begin
40+ if Result.Is_Directory then
41+ return Result;
42+ else
43+ raise Program_Error
44+ with " The user home location is not a directory: " &
45+ Result.Display_Full_Name;
46+ end if ;
47+ end ;
3248 end if ;
3349
34- return LSP.Utils.To_Virtual_File (Home);
3550 end Home_Dir ;
3651
3752 -- ---------------
3853 -- ALS_Log_Dir --
3954 -- ---------------
4055
41- function ALS_Log_Dir return GNATCOLL.VFS.Virtual_File
42- is ((if not ALS_Home.Is_Empty then LSP.Utils.To_Virtual_File (ALS_Home)
43- else
44- (if Home_Dir.Is_Directory then Home_Dir
45- else GNATCOLL.VFS.Create (" ." )))
46- / " .als" );
56+ function ALS_Log_Dir return GNATCOLL.VFS.Virtual_File is
57+ ((if not ALS_Home.Is_Empty then LSP.Utils.To_Virtual_File (ALS_Home)
58+ else
59+ (if Home_Dir.Is_Directory then Home_Dir
60+ else GNATCOLL.VFS.Create (" ." ))) /
61+ " .als" );
4762
4863 -- -------------------
4964 -- XDG_CONFIG_HOME --
5065 -- -------------------
5166
52- function XDG_CONFIG_HOME return VSS.Strings.Virtual_String
53- is (VSS.Application.System_Environment.Value
54- (" XDG_CONFIG_HOME" ,
55- LSP.Utils.To_Virtual_String (Home_Dir / " .config" )));
67+ function XDG_CONFIG_HOME return GNATCOLL.VFS.Virtual_File is
68+ Xdg_Config_Home_Value : constant VSS.Strings.Virtual_String :=
69+ VSS.Application.System_Environment.Value (" XDG_CONFIG_HOME" );
70+ begin
71+ if not Xdg_Config_Home_Value.Is_Empty then
72+ return LSP.Utils.To_Virtual_File (Xdg_Config_Home_Value);
73+ else
74+ return Home_Dir / " .config" ;
75+ end if ;
76+ end XDG_CONFIG_HOME ;
5677
5778 -- -----------------------
5879 -- ALS_User_Config_Dir --
5980 -- -----------------------
6081
61- function ALS_User_Config_Dir return GNATCOLL.VFS.Virtual_File
62- is (LSP.Utils.To_Virtual_File (XDG_CONFIG_HOME) / " als" );
82+ function ALS_User_Config_Dir return GNATCOLL.VFS.Virtual_File is
83+ (XDG_CONFIG_HOME / " als" );
6384
6485 -- ------------------------
6586 -- ALS_User_Config_File --
6687 -- ------------------------
6788
68- function ALS_User_Config_File return GNATCOLL.VFS.Virtual_File
69- is (ALS_User_Config_Dir / " config.json" );
89+ function ALS_User_Config_File return GNATCOLL.VFS.Virtual_File is
90+ (ALS_User_Config_Dir / " config.json" );
7091
7192 -- -----------------------------
7293 -- ALS_Workspace_Config_File --
7394 -- -----------------------------
7495
75- function ALS_Workspace_Config_File return GNATCOLL.VFS.Virtual_File
76- is (GNATCOLL.VFS.Create_From_Base (" .als.json" ));
96+ function ALS_Workspace_Config_File return GNATCOLL.VFS.Virtual_File is
97+ (GNATCOLL.VFS.Create_From_Base (" .als.json" ));
7798
7899end LSP.Env ;
0 commit comments