Skip to content

Commit

Permalink
reload project apps after build
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lukaszsamson committed Jan 8, 2024
1 parent 592a437 commit 9770885
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion apps/language_server/lib/language_server/build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ defmodule ElixirLS.LanguageServer.Build do
&Diagnostics.from_mix_task_compiler_diagnostic(&1, mixfile, root_path)
)

if status == :ok do
# reload apps to make sure app controller has the correct list of modules
# if we don't do that, workspace symbols and other providers relying on
# `:application.get_key(app, :modules)` would not notice newly added modules
# no need to do that on :noop and :error
# workaround for https://github.com/elixir-lang/elixir/issues/13001
unload_mix_project_apps(true)
end

Server.build_finished(
parent,
{status, mixfile_diagnostics ++ deps_diagnostics ++ compile_diagnostics}
Expand Down Expand Up @@ -569,7 +578,7 @@ defmodule ElixirLS.LanguageServer.Build do
end
end

defp unload_mix_project_apps() do
defp unload_mix_project_apps(reload? \\ false) do
# note that this will unload config so we need to call loadconfig afterwards
mix_project_apps =
if Mix.Project.umbrella?() do
Expand All @@ -588,6 +597,13 @@ defmodule ElixirLS.LanguageServer.Build do
# see https://github.com/elixir-lang/elixir/issues/13001
for app <- mix_project_apps do
purge_app(app, false)
if reload? do
case Application.load(app) do
:ok -> :ok
{:error, reason} ->
Logger.warning("Application #{app} failed to load: #{inspect(reason)}")
end
end
end
end

Expand Down

0 comments on commit 9770885

Please sign in to comment.