Skip to content

Commit 03db965

Browse files
authored
fix(runtime): correctly set MIX_HOME in runtime (#452)
Closes #451
1 parent 287968b commit 03db965

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

lib/next_ls.ex

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ defmodule NextLS do
7979
runtime_task_supervisor = Keyword.fetch!(args, :runtime_task_supervisor)
8080
dynamic_supervisor = Keyword.fetch!(args, :dynamic_supervisor)
8181
bundle_base = Keyword.get(args, :bundle_base, Path.expand("~/.cache/elixir-tools/nextls"))
82-
mixhome = Keyword.get(args, :mix_home, Path.expand("~/.mix"))
82+
mix_home = Keyword.get(args, :mix_home)
8383

8484
registry = Keyword.fetch!(args, :registry)
8585

@@ -89,12 +89,13 @@ defmodule NextLS do
8989
cache = Keyword.fetch!(args, :cache)
9090
{:ok, logger} = DynamicSupervisor.start_child(dynamic_supervisor, {NextLS.Logger, lsp: lsp})
9191

92-
NextLS.Runtime.BundledElixir.install(bundle_base, logger, mix_home: mixhome)
92+
NextLS.Runtime.BundledElixir.install(bundle_base, logger, mix_home: mix_home)
9393

9494
{:ok,
9595
assign(lsp,
9696
auto_update: Keyword.get(args, :auto_update, false),
9797
bundle_base: bundle_base,
98+
mix_home: mix_home,
9899
exit_code: 1,
99100
documents: %{},
100101
refresh_refs: %{},
@@ -904,6 +905,7 @@ defmodule NextLS do
904905
uri: uri,
905906
mix_env: lsp.assigns.init_opts.mix_env,
906907
mix_target: lsp.assigns.init_opts.mix_target,
908+
mix_home: lsp.assigns.mix_home,
907909
elixir_bin_path: elixir_bin_path,
908910
on_initialized: fn status ->
909911
if status == :ready do
@@ -1026,6 +1028,7 @@ defmodule NextLS do
10261028
uri: uri,
10271029
mix_env: lsp.assigns.init_opts.mix_env,
10281030
mix_target: lsp.assigns.init_opts.mix_target,
1031+
mix_home: lsp.assigns.mix_home,
10291032
on_initialized: fn status ->
10301033
if status == :ready do
10311034
Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!")

lib/next_ls/runtime.ex

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ defmodule NextLS.Runtime do
111111
mix_env = Keyword.fetch!(opts, :mix_env)
112112
mix_target = Keyword.fetch!(opts, :mix_target)
113113
elixir_bin_path = Keyword.get(opts, :elixir_bin_path)
114+
mix_home = Keyword.get(opts, :mix_home)
114115

115116
elixir_exe = Path.join(elixir_bin_path, "elixir")
116117

@@ -145,6 +146,7 @@ defmodule NextLS.Runtime do
145146
{~c"MIX_ENV", ~c"#{mix_env}"},
146147
{~c"MIX_TARGET", ~c"#{mix_target}"},
147148
{~c"MIX_BUILD_ROOT", ~c".elixir-tools/_build"},
149+
{~c"MIX_HOME", ~c"#{mix_home}"},
148150
{~c"ROOTDIR", false},
149151
{~c"BINDIR", false},
150152
{~c"RELEASE_ROOT", false},

lib/next_ls/runtime/bundled_elixir.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ defmodule NextLS.Runtime.BundledElixir do
2121
end
2222

2323
def install(base, logger, opts \\ []) do
24-
mixhome = Keyword.get(opts, :mix_home, Path.expand("~/.mix"))
24+
basedir = path(base)
25+
mixhome = Keyword.get(opts, :mix_home) || Path.join(basedir, ".mix")
2526
binpath = binpath(base)
2627

2728
unless File.exists?(binpath) do

test/next_ls/autocomplete_test.exs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ defmodule NextLS.AutocompleteTest do
7373
db: :some_db,
7474
mix_env: "dev",
7575
mix_target: "host",
76+
mix_home: Path.join(cwd, ".mix"),
7677
registry: __MODULE__.Registry}
7778
)
7879

test/next_ls/runtime_test.exs

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ defmodule NextLs.RuntimeTest do
6565
db: :some_db,
6666
mix_env: "dev",
6767
mix_target: "host",
68+
mix_home: Path.join(cwd, ".mix"),
6869
registry: RuntimeTest.Registry}
6970
)
7071

@@ -95,6 +96,7 @@ defmodule NextLs.RuntimeTest do
9596
db: :some_db,
9697
mix_env: "dev",
9798
mix_target: "host",
99+
mix_home: Path.join(cwd, ".mix"),
98100
registry: RuntimeTest.Registry}
99101
)
100102

@@ -126,6 +128,7 @@ defmodule NextLs.RuntimeTest do
126128
db: :some_db,
127129
mix_env: "dev",
128130
mix_target: "host",
131+
mix_home: Path.join(cwd, ".mix"),
129132
registry: RuntimeTest.Registry}
130133
)
131134

@@ -190,6 +193,7 @@ defmodule NextLs.RuntimeTest do
190193
db: :some_db,
191194
mix_env: "dev",
192195
mix_target: "host",
196+
mix_home: Path.join(cwd, ".mix"),
193197
registry: RuntimeTest.Registry}
194198
)
195199

0 commit comments

Comments
 (0)