Skip to content

Commit 9770885

Browse files
committed
reload project apps after build
fixes an issue when workspace symbols would not see a newly added module due to app controller keeping old module list Workaround for elixir-lang/elixir#13001
1 parent 592a437 commit 9770885

File tree

1 file changed

+17
-1
lines changed
  • apps/language_server/lib/language_server

1 file changed

+17
-1
lines changed

apps/language_server/lib/language_server/build.ex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ defmodule ElixirLS.LanguageServer.Build do
7676
&Diagnostics.from_mix_task_compiler_diagnostic(&1, mixfile, root_path)
7777
)
7878

79+
if status == :ok do
80+
# reload apps to make sure app controller has the correct list of modules
81+
# if we don't do that, workspace symbols and other providers relying on
82+
# `:application.get_key(app, :modules)` would not notice newly added modules
83+
# no need to do that on :noop and :error
84+
# workaround for https://github.com/elixir-lang/elixir/issues/13001
85+
unload_mix_project_apps(true)
86+
end
87+
7988
Server.build_finished(
8089
parent,
8190
{status, mixfile_diagnostics ++ deps_diagnostics ++ compile_diagnostics}
@@ -569,7 +578,7 @@ defmodule ElixirLS.LanguageServer.Build do
569578
end
570579
end
571580

572-
defp unload_mix_project_apps() do
581+
defp unload_mix_project_apps(reload? \\ false) do
573582
# note that this will unload config so we need to call loadconfig afterwards
574583
mix_project_apps =
575584
if Mix.Project.umbrella?() do
@@ -588,6 +597,13 @@ defmodule ElixirLS.LanguageServer.Build do
588597
# see https://github.com/elixir-lang/elixir/issues/13001
589598
for app <- mix_project_apps do
590599
purge_app(app, false)
600+
if reload? do
601+
case Application.load(app) do
602+
:ok -> :ok
603+
{:error, reason} ->
604+
Logger.warning("Application #{app} failed to load: #{inspect(reason)}")
605+
end
606+
end
591607
end
592608
end
593609

0 commit comments

Comments
 (0)