Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
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
11 changes: 9 additions & 2 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ 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: mix_home)

{:ok,
assign(lsp,
auto_update: Keyword.get(args, :auto_update, false),
Expand Down Expand Up @@ -132,6 +130,13 @@ defmodule NextLS do

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

mix_home =
if init_opts.experimental.completions.enable do
NextLS.Runtime.BundledElixir.mix_home(lsp.assigns.bundle_base)
else
nil
end

{:reply,
%InitializeResult{
capabilities: %ServerCapabilities{
Expand Down Expand Up @@ -175,6 +180,7 @@ defmodule NextLS do
server_info: %{name: "Next LS"}
},
assign(lsp,
mix_home: mix_home,
root_uri: root_uri,
workspace_folders: workspace_folders,
client_capabilities: caps,
Expand Down Expand Up @@ -868,6 +874,7 @@ defmodule NextLS do
})
end

NextLS.Runtime.BundledElixir.install(lsp.assigns.bundle_base, lsp.assigns.logger)
GenLSP.log(lsp, "[Next LS] Booting runtimes...")

parent = self()
Expand Down
31 changes: 18 additions & 13 deletions lib/next_ls/runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,24 @@ defmodule NextLS.Runtime do
|> Path.join("cmd")
|> Path.absname()

env = [
{~c"LSP", ~c"nextls"},
{~c"NEXTLS_PARENT_PID", parent},
{~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},
{~c"RELEASE_SYS_CONFIG", false},
{~c"PATH", String.to_charlist(new_path)}
]
env =
[
{~c"LSP", ~c"nextls"},
{~c"NEXTLS_PARENT_PID", parent},
{~c"MIX_ENV", ~c"#{mix_env}"},
{~c"MIX_TARGET", ~c"#{mix_target}"},
{~c"MIX_BUILD_ROOT", ~c".elixir-tools/_build"},
{~c"ROOTDIR", false},
{~c"BINDIR", false},
{~c"RELEASE_ROOT", false},
{~c"RELEASE_SYS_CONFIG", false},
{~c"PATH", String.to_charlist(new_path)}
] ++
if mix_home do
[{~c"MIX_HOME", ~c"#{mix_home}"}]
else
[]
end

args =
[elixir_exe] ++
Expand Down
24 changes: 14 additions & 10 deletions lib/next_ls/runtime/bundled_elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ defmodule NextLS.Runtime.BundledElixir do
Path.join([base, @dir])
end

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

def install(base, logger) do
mixhome = mix_home(base)
File.mkdir_p!(mixhome)
binpath = binpath(base)

unless File.exists?(binpath) do
Expand All @@ -37,16 +41,16 @@ defmodule NextLS.Runtime.BundledElixir do
for bin <- Path.wildcard(Path.join(binpath, "*")) do
File.chmod(bin, 0o755)
end
end

new_path = "#{binpath}:#{System.get_env("PATH")}"
mixbin = mixpath(base)
new_path = "#{binpath}:#{System.get_env("PATH")}"
mixbin = mixpath(base)

{_, 0} =
System.cmd(mixbin, ["local.rebar", "--force"], env: [{"PATH", new_path}, {"MIX_HOME", mixhome}])
{_, 0} =
System.cmd(mixbin, ["local.rebar", "--force"], env: [{"PATH", new_path}, {"MIX_HOME", mixhome}])

{_, 0} =
System.cmd(mixbin, ["local.hex", "--force"], env: [{"PATH", new_path}, {"MIX_HOME", mixhome}])
end
{_, 0} =
System.cmd(mixbin, ["local.hex", "--force"], env: [{"PATH", new_path}, {"MIX_HOME", mixhome}])

:ok
rescue
Expand Down