Skip to content

Commit 031bd0a

Browse files
committed
Properly clean mix internal state so dep loading does not fail
Fixes #120
1 parent d77087a commit 031bd0a

File tree

1 file changed

+16
-13
lines changed
  • apps/language_server/lib/language_server

1 file changed

+16
-13
lines changed

apps/language_server/lib/language_server/build.ex

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,31 @@ defmodule ElixirLS.LanguageServer.Build do
6262
mixfile = Path.absname(MixfileHelpers.mix_exs())
6363

6464
if File.exists?(mixfile) do
65-
# FIXME: Private API
66-
case Mix.ProjectStack.peek() do
67-
%{file: ^mixfile, name: module} ->
68-
# FIXME: Private API
69-
Mix.Project.pop()
70-
purge_module(module)
71-
72-
_ ->
73-
:ok
65+
if module = Mix.Project.get() do
66+
# FIXME: Private API
67+
Mix.Project.pop()
68+
purge_module(module)
7469
end
7570

76-
Mix.Task.clear()
77-
78-
# Override build directory to avoid interfering with other dev tools
71+
# We need to clear persistent cache, otherwise `deps.loadpaths` task fails with
72+
# (Mix.Error) Can't continue due to errors on dependencies
73+
# see https://github.com/elixir-lsp/elixir-ls/issues/120
74+
# originally reported in https://github.com/JakeBecker/elixir-ls/issues/71
75+
# Note that `Mix.State.clear_cache()` is not enough (at least on elixir 1.14)
7976
# FIXME: Private API
80-
Mix.ProjectStack.post_config(build_path: ".elixir_ls/build")
77+
Mix.Dep.clear_cached()
78+
79+
Mix.Task.clear()
8180

8281
# we need to reset compiler options
8382
# project may leave tracers after previous compilation and we don't woant them interfeering
8483
# see https://github.com/elixir-lsp/elixir-ls/issues/717
8584
set_compiler_options()
8685

86+
# Override build directory to avoid interfering with other dev tools
87+
# FIXME: Private API
88+
Mix.ProjectStack.post_config(build_path: ".elixir_ls/build")
89+
8790
# We can get diagnostics if Mixfile fails to load
8891
{status, diagnostics} =
8992
case Kernel.ParallelCompiler.compile([mixfile]) do

0 commit comments

Comments
 (0)