Skip to content

Commit ccde5ff

Browse files
committed
Merge branch 'topic/config-env-win' into 'master'
Fix accessing XDG_CONFIG_HOME and the user home directory on Windows See merge request eng/ide/ada_language_server!1840
2 parents b18b15f + ce69b27 commit ccde5ff

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

source/ada/lsp-env.adb

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
------------------------------------------------------------------------------
1717

1818
with LSP.Utils;
19+
with VSS.Standard_Paths;
1920

2021
package 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

7899
end LSP.Env;

source/ada/lsp-env.ads

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ package LSP.Env is
2626
use type GNATCOLL.VFS.Virtual_File;
2727

2828
Testing : constant Boolean :=
29-
VSS.Application.System_Environment.Contains ("ALS_TESTING");
29+
VSS.Application.System_Environment.Contains ("ALS_TESTING");
3030
-- Constant set to True when ALS is running within a testsuite.
3131

32-
Home : constant VSS.Strings.Virtual_String :=
33-
VSS.Application.System_Environment.Value ("HOME");
34-
-- Value of the HOME environment variable
35-
3632
function Home_Dir return GNATCOLL.VFS.Virtual_File;
37-
-- Directory pointed by the HOME environment variable
33+
-- The user home directory on POSIX or the user profile directory on
34+
-- Windows.
3835

3936
ALS_Home : constant VSS.Strings.Virtual_String :=
4037
VSS.Application.System_Environment.Value ("ALS_HOME");
@@ -57,7 +54,7 @@ package LSP.Env is
5754
--
5855
-- In an exotic case where HOME is not defined, use the current directory
5956

60-
function XDG_CONFIG_HOME return VSS.Strings.Virtual_String;
57+
function XDG_CONFIG_HOME return GNATCOLL.VFS.Virtual_File;
6158
-- The XDG_CONFIG_HOME environment variable, defaulting to $HOME/.config if
6259
-- unspecified.
6360
--

testsuite/ada_lsp/empty_env/test.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

testsuite/ada_lsp/empty_env/test.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)