Skip to content

Commit

Permalink
fix(runtime): correctly set MIX_HOME in runtime (#452)
Browse files Browse the repository at this point in the history
Closes #451
  • Loading branch information
mhanberg committed May 9, 2024
1 parent 287968b commit 03db965
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule NextLS do
runtime_task_supervisor = Keyword.fetch!(args, :runtime_task_supervisor)
dynamic_supervisor = Keyword.fetch!(args, :dynamic_supervisor)
bundle_base = Keyword.get(args, :bundle_base, Path.expand("~/.cache/elixir-tools/nextls"))
mixhome = Keyword.get(args, :mix_home, Path.expand("~/.mix"))
mix_home = Keyword.get(args, :mix_home)

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

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

NextLS.Runtime.BundledElixir.install(bundle_base, logger, mix_home: mixhome)
NextLS.Runtime.BundledElixir.install(bundle_base, logger, mix_home: mix_home)

{:ok,
assign(lsp,
auto_update: Keyword.get(args, :auto_update, false),
bundle_base: bundle_base,
mix_home: mix_home,
exit_code: 1,
documents: %{},
refresh_refs: %{},
Expand Down Expand Up @@ -904,6 +905,7 @@ defmodule NextLS do
uri: uri,
mix_env: lsp.assigns.init_opts.mix_env,
mix_target: lsp.assigns.init_opts.mix_target,
mix_home: lsp.assigns.mix_home,
elixir_bin_path: elixir_bin_path,
on_initialized: fn status ->
if status == :ready do
Expand Down Expand Up @@ -1026,6 +1028,7 @@ defmodule NextLS do
uri: uri,
mix_env: lsp.assigns.init_opts.mix_env,
mix_target: lsp.assigns.init_opts.mix_target,
mix_home: lsp.assigns.mix_home,
on_initialized: fn status ->
if status == :ready do
Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!")
Expand Down
2 changes: 2 additions & 0 deletions lib/next_ls/runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ defmodule NextLS.Runtime do
mix_env = Keyword.fetch!(opts, :mix_env)
mix_target = Keyword.fetch!(opts, :mix_target)
elixir_bin_path = Keyword.get(opts, :elixir_bin_path)
mix_home = Keyword.get(opts, :mix_home)

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

Expand Down Expand Up @@ -145,6 +146,7 @@ defmodule NextLS.Runtime do
{~c"MIX_ENV", ~c"#{mix_env}"},
{~c"MIX_TARGET", ~c"#{mix_target}"},
{~c"MIX_BUILD_ROOT", ~c".elixir-tools/_build"},
{~c"MIX_HOME", ~c"#{mix_home}"},
{~c"ROOTDIR", false},
{~c"BINDIR", false},
{~c"RELEASE_ROOT", false},
Expand Down
3 changes: 2 additions & 1 deletion lib/next_ls/runtime/bundled_elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmodule NextLS.Runtime.BundledElixir do
end

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

unless File.exists?(binpath) do
Expand Down
1 change: 1 addition & 0 deletions test/next_ls/autocomplete_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ defmodule NextLS.AutocompleteTest do
db: :some_db,
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
registry: __MODULE__.Registry}
)

Expand Down
4 changes: 4 additions & 0 deletions test/next_ls/runtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule NextLs.RuntimeTest do
db: :some_db,
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
registry: RuntimeTest.Registry}
)

Expand Down Expand Up @@ -95,6 +96,7 @@ defmodule NextLs.RuntimeTest do
db: :some_db,
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
registry: RuntimeTest.Registry}
)

Expand Down Expand Up @@ -126,6 +128,7 @@ defmodule NextLs.RuntimeTest do
db: :some_db,
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
registry: RuntimeTest.Registry}
)

Expand Down Expand Up @@ -190,6 +193,7 @@ defmodule NextLs.RuntimeTest do
db: :some_db,
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
registry: RuntimeTest.Registry}
)

Expand Down

0 comments on commit 03db965

Please sign in to comment.