Skip to content

Commit

Permalink
Set MIX_ARCHIVES everywhere MIX_HOME is set
Browse files Browse the repository at this point in the history
  • Loading branch information
soundmonster committed Jun 11, 2024
1 parent d398e59 commit eb31552
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ defmodule NextLS do
:extensions,
:registry,
:bundle_base,
:mix_home
:mix_home,
:mix_archives
])

GenLSP.start_link(__MODULE__, args, opts)
Expand All @@ -90,6 +91,7 @@ defmodule NextLS do
dynamic_supervisor = Keyword.fetch!(args, :dynamic_supervisor)
bundle_base = Keyword.get(args, :bundle_base, Path.expand("~/.cache/elixir-tools/nextls"))
mix_home = Keyword.get(args, :mix_home)
mix_archives = Keyword.get(args, :mix_archives)

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

Expand All @@ -104,6 +106,7 @@ defmodule NextLS do
auto_update: Keyword.get(args, :auto_update, false),
bundle_base: bundle_base,
mix_home: mix_home,
mix_archives: mix_archives,
exit_code: 1,
documents: %{},
refresh_refs: %{},
Expand Down Expand Up @@ -145,6 +148,11 @@ defmodule NextLS do
BundledElixir.mix_home(lsp.assigns.bundle_base)
end

mix_archives =
if init_opts.experimental.completions.enable do
BundledElixir.mix_archives(lsp.assigns.bundle_base)
end

{:reply,
%InitializeResult{
capabilities: %ServerCapabilities{
Expand Down Expand Up @@ -187,6 +195,7 @@ defmodule NextLS do
},
assign(lsp,
mix_home: mix_home,
mix_archives: mix_archives,
root_uri: root_uri,
workspace_folders: workspace_folders,
client_capabilities: caps,
Expand Down Expand Up @@ -938,6 +947,7 @@ defmodule NextLS do
mix_env: lsp.assigns.init_opts.mix_env,
mix_target: lsp.assigns.init_opts.mix_target,
mix_home: lsp.assigns.mix_home,
mix_archives: lsp.assigns.mix_archives,
elixir_bin_path: elixir_bin_path,
on_initialized: fn status ->
if status == :ready do
Expand Down Expand Up @@ -1061,6 +1071,7 @@ defmodule NextLS do
mix_env: lsp.assigns.init_opts.mix_env,
mix_target: lsp.assigns.init_opts.mix_target,
mix_home: lsp.assigns.mix_home,
mix_archives: lsp.assigns.mix_archives,
on_initialized: fn status ->
if status == :ready do
Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!")
Expand Down
6 changes: 6 additions & 0 deletions lib/next_ls/runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ defmodule NextLS.Runtime do
mix_target = Keyword.fetch!(opts, :mix_target)
elixir_bin_path = Keyword.get(opts, :elixir_bin_path)
mix_home = Keyword.get(opts, :mix_home)
mix_archives = Keyword.get(opts, :mix_archives)

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

Expand Down Expand Up @@ -159,6 +160,11 @@ defmodule NextLS.Runtime do
[{~c"MIX_HOME", ~c"#{mix_home}"}]
else
[]
end ++
if mix_archives do
[{~c"MIX_ARCHIVES", ~c"#{mix_archives}"}]
else
[]
end

args =
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 @@ -74,6 +74,7 @@ defmodule NextLS.AutocompleteTest do
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
mix_archives: Path.join(cwd, [".mix", "archives"]),
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 @@ -66,6 +66,7 @@ defmodule NextLs.RuntimeTest do
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
mix_archives: Path.join(cwd, [".mix", "archives"]),
registry: RuntimeTest.Registry}
)

Expand Down Expand Up @@ -97,6 +98,7 @@ defmodule NextLs.RuntimeTest do
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
mix_archives: Path.join(cwd, [".mix", "archives"]),
registry: RuntimeTest.Registry}
)

Expand Down Expand Up @@ -129,6 +131,7 @@ defmodule NextLs.RuntimeTest do
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
mix_archives: Path.join(cwd, [".mix", "archives"]),
registry: RuntimeTest.Registry}
)

Expand Down Expand Up @@ -194,6 +197,7 @@ defmodule NextLs.RuntimeTest do
mix_env: "dev",
mix_target: "host",
mix_home: Path.join(cwd, ".mix"),
mix_archives: Path.join(cwd, [".mix", "archives"]),
registry: RuntimeTest.Registry}
)

Expand Down
4 changes: 3 additions & 1 deletion test/support/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule NextLS.Support.Utils do

bundle_base = Path.join(tmp_dir, ".bundled")
mixhome = Path.join(tmp_dir, ".mix")
mixarchives = Path.join(mixhome, "archives")
File.mkdir_p!(bundle_base)

tvisor = start_supervised!(Supervisor.child_spec(Task.Supervisor, id: :one))
Expand Down Expand Up @@ -73,7 +74,8 @@ defmodule NextLS.Support.Utils do
extensions: extensions,
cache: cache,
bundle_base: bundle_base,
mix_home: mixhome
mix_home: mixhome,
mix_archives: mixarchives
)

Process.link(server.lsp)
Expand Down

0 comments on commit eb31552

Please sign in to comment.