~sbaildon/next-ls

03db965289c0e7127b92b5136f71dbd9492533cf — Mitchell Hanberg a month ago 287968b
fix(runtime): correctly set MIX_HOME in runtime (#452)

Closes #451
M lib/next_ls.ex => lib/next_ls.ex +5 -2
@@ 79,7 79,7 @@ defmodule NextLS do
    runtime_task_supervisor = Keyword.fetch!(args, :runtime_task_supervisor)
    dynamic_supervisor = Keyword.fetch!(args, :dynamic_supervisor)
    bundle_base = Keyword.get(args, :bundle_base, Path.expand("~/.cache/elixir-tools/nextls"))
    mixhome = Keyword.get(args, :mix_home, Path.expand("~/.mix"))
    mix_home = Keyword.get(args, :mix_home)

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



@@ 89,12 89,13 @@ 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: mixhome)
    NextLS.Runtime.BundledElixir.install(bundle_base, logger, mix_home: mix_home)

    {:ok,
     assign(lsp,
       auto_update: Keyword.get(args, :auto_update, false),
       bundle_base: bundle_base,
       mix_home: mix_home,
       exit_code: 1,
       documents: %{},
       refresh_refs: %{},


@@ 904,6 905,7 @@ defmodule NextLS do
             uri: uri,
             mix_env: lsp.assigns.init_opts.mix_env,
             mix_target: lsp.assigns.init_opts.mix_target,
             mix_home: lsp.assigns.mix_home,
             elixir_bin_path: elixir_bin_path,
             on_initialized: fn status ->
               if status == :ready do


@@ 1026,6 1028,7 @@ defmodule NextLS do
              uri: uri,
              mix_env: lsp.assigns.init_opts.mix_env,
              mix_target: lsp.assigns.init_opts.mix_target,
              mix_home: lsp.assigns.mix_home,
              on_initialized: fn status ->
                if status == :ready do
                  Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!")

M lib/next_ls/runtime.ex => lib/next_ls/runtime.ex +2 -0
@@ 111,6 111,7 @@ defmodule NextLS.Runtime do
    mix_env = Keyword.fetch!(opts, :mix_env)
    mix_target = Keyword.fetch!(opts, :mix_target)
    elixir_bin_path = Keyword.get(opts, :elixir_bin_path)
    mix_home = Keyword.get(opts, :mix_home)

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



@@ 145,6 146,7 @@ defmodule NextLS.Runtime do
        {~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},

M lib/next_ls/runtime/bundled_elixir.ex => lib/next_ls/runtime/bundled_elixir.ex +2 -1
@@ 21,7 21,8 @@ defmodule NextLS.Runtime.BundledElixir do
  end

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

    unless File.exists?(binpath) do

M test/next_ls/autocomplete_test.exs => test/next_ls/autocomplete_test.exs +1 -0
@@ 73,6 73,7 @@ defmodule NextLS.AutocompleteTest do
         db: :some_db,
         mix_env: "dev",
         mix_target: "host",
         mix_home: Path.join(cwd, ".mix"),
         registry: __MODULE__.Registry}
      )


M test/next_ls/runtime_test.exs => test/next_ls/runtime_test.exs +4 -0
@@ 65,6 65,7 @@ defmodule NextLs.RuntimeTest do
           db: :some_db,
           mix_env: "dev",
           mix_target: "host",
           mix_home: Path.join(cwd, ".mix"),
           registry: RuntimeTest.Registry}
        )



@@ 95,6 96,7 @@ defmodule NextLs.RuntimeTest do
           db: :some_db,
           mix_env: "dev",
           mix_target: "host",
           mix_home: Path.join(cwd, ".mix"),
           registry: RuntimeTest.Registry}
        )



@@ 126,6 128,7 @@ defmodule NextLs.RuntimeTest do
           db: :some_db,
           mix_env: "dev",
           mix_target: "host",
           mix_home: Path.join(cwd, ".mix"),
           registry: RuntimeTest.Registry}
        )



@@ 190,6 193,7 @@ defmodule NextLs.RuntimeTest do
           db: :some_db,
           mix_env: "dev",
           mix_target: "host",
           mix_home: Path.join(cwd, ".mix"),
           registry: RuntimeTest.Registry}
        )