16
16
-- ----------------------------------------------------------------------------
17
17
18
18
with LSP.Utils ;
19
+ with VSS.Standard_Paths ;
19
20
20
21
package body LSP.Env is
21
22
@@ -24,55 +25,75 @@ package body LSP.Env is
24
25
-- ------------
25
26
26
27
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);
27
31
begin
28
- if Home .Is_Empty then
32
+ if Home_Path .Is_Empty then
29
33
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 ;
32
48
end if ;
33
49
34
- return LSP.Utils.To_Virtual_File (Home);
35
50
end Home_Dir ;
36
51
37
52
-- ---------------
38
53
-- ALS_Log_Dir --
39
54
-- ---------------
40
55
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" );
47
62
48
63
-- -------------------
49
64
-- XDG_CONFIG_HOME --
50
65
-- -------------------
51
66
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 ;
56
77
57
78
-- -----------------------
58
79
-- ALS_User_Config_Dir --
59
80
-- -----------------------
60
81
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" );
63
84
64
85
-- ------------------------
65
86
-- ALS_User_Config_File --
66
87
-- ------------------------
67
88
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" );
70
91
71
92
-- -----------------------------
72
93
-- ALS_Workspace_Config_File --
73
94
-- -----------------------------
74
95
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" ));
77
98
78
99
end LSP.Env ;
0 commit comments