Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using system elixir if 1.17 #518

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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