Skip to content

Commit

Permalink
feat: allow using system elixir if 1.17 (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Jun 13, 2024
1 parent c34bfe4 commit 5e6c586
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ defmodule NextLS do
mix_home = Keyword.get(args, :mix_home)
mix_archives = Keyword.get(args, :mix_archives)

is_1_17 =
with {version, 0} <- System.cmd("elixir", ["--short-version"]),
{:ok, version} <- version |> String.trim() |> Version.parse() do
Version.compare(version, "1.17.0") in [:gt, :eq]
else
_ ->
false
end

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

extensions =
Expand All @@ -57,6 +66,7 @@ defmodule NextLS do
bundle_base: bundle_base,
mix_home: mix_home,
mix_archives: mix_archives,
is_1_17: is_1_17,
exit_code: 1,
documents: %{},
refresh_refs: %{},
Expand Down Expand Up @@ -93,14 +103,17 @@ defmodule NextLS do

{:ok, init_opts} = __MODULE__.InitOpts.validate(init_opts)

mix_home =
if init_opts.experimental.completions.enable 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)
# if we are on 1.17, we will not bundle
{mix_home, mix_archives} =
if lsp.assigns.is_1_17 do
{nil, nil}
else
# if we are not on 1.17, we bundle if completions are enabled
if init_opts.experimental.completions.enable do
{BundledElixir.mix_home(lsp.assigns.bundle_base), BundledElixir.mix_archives(lsp.assigns.bundle_base)}
else
{nil, nil}
end
end

{:reply,
Expand Down Expand Up @@ -865,6 +878,9 @@ defmodule NextLS do

elixir_bin_path =
cond do
lsp.assigns.is_1_17 ->
"elixir" |> System.find_executable() |> Path.dirname()

lsp.assigns.init_opts.elixir_bin_path != nil ->
lsp.assigns.init_opts.elixir_bin_path

Expand Down
3 changes: 3 additions & 0 deletions priv/monkey/_next_ls_private_compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,9 @@ if Version.match?(System.version(), ">= 1.17.0-dev") do

:error ->
expand_local(meta, fun, args, state, env)

{:error, _} ->
expand_local(meta, fun, args, state, env)
end
end

Expand Down

0 comments on commit 5e6c586

Please sign in to comment.