Skip to content

Commit 5e6c586

Browse files
authored
feat: allow using system elixir if 1.17 (#518)
1 parent c34bfe4 commit 5e6c586

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

Diff for: lib/next_ls.ex

+24-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ defmodule NextLS do
4343
mix_home = Keyword.get(args, :mix_home)
4444
mix_archives = Keyword.get(args, :mix_archives)
4545

46+
is_1_17 =
47+
with {version, 0} <- System.cmd("elixir", ["--short-version"]),
48+
{:ok, version} <- version |> String.trim() |> Version.parse() do
49+
Version.compare(version, "1.17.0") in [:gt, :eq]
50+
else
51+
_ ->
52+
false
53+
end
54+
4655
registry = Keyword.fetch!(args, :registry)
4756

4857
extensions =
@@ -57,6 +66,7 @@ defmodule NextLS do
5766
bundle_base: bundle_base,
5867
mix_home: mix_home,
5968
mix_archives: mix_archives,
69+
is_1_17: is_1_17,
6070
exit_code: 1,
6171
documents: %{},
6272
refresh_refs: %{},
@@ -93,14 +103,17 @@ defmodule NextLS do
93103

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

96-
mix_home =
97-
if init_opts.experimental.completions.enable do
98-
BundledElixir.mix_home(lsp.assigns.bundle_base)
99-
end
100-
101-
mix_archives =
102-
if init_opts.experimental.completions.enable do
103-
BundledElixir.mix_archives(lsp.assigns.bundle_base)
106+
# if we are on 1.17, we will not bundle
107+
{mix_home, mix_archives} =
108+
if lsp.assigns.is_1_17 do
109+
{nil, nil}
110+
else
111+
# if we are not on 1.17, we bundle if completions are enabled
112+
if init_opts.experimental.completions.enable do
113+
{BundledElixir.mix_home(lsp.assigns.bundle_base), BundledElixir.mix_archives(lsp.assigns.bundle_base)}
114+
else
115+
{nil, nil}
116+
end
104117
end
105118

106119
{:reply,
@@ -865,6 +878,9 @@ defmodule NextLS do
865878

866879
elixir_bin_path =
867880
cond do
881+
lsp.assigns.is_1_17 ->
882+
"elixir" |> System.find_executable() |> Path.dirname()
883+
868884
lsp.assigns.init_opts.elixir_bin_path != nil ->
869885
lsp.assigns.init_opts.elixir_bin_path
870886

Diff for: priv/monkey/_next_ls_private_compiler.ex

+3
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,9 @@ if Version.match?(System.version(), ">= 1.17.0-dev") do
13631363

13641364
:error ->
13651365
expand_local(meta, fun, args, state, env)
1366+
1367+
{:error, _} ->
1368+
expand_local(meta, fun, args, state, env)
13661369
end
13671370
end
13681371

0 commit comments

Comments
 (0)