@@ -296,7 +296,7 @@ defmodule ElixirLS.LanguageServer.Build do
296296 :code . delete ( module )
297297 end
298298
299- defp purge_app ( app ) do
299+ defp purge_app ( app , purge_modules? \\ true ) do
300300 Logger . debug ( "Stopping #{ app } " )
301301
302302 case Application . stop ( app ) do
@@ -305,15 +305,17 @@ defmodule ElixirLS.LanguageServer.Build do
305305 { :error , error } -> Logger . warning ( "Application.stop failed for #{ app } : #{ inspect ( error ) } " )
306306 end
307307
308- modules =
309- case :application . get_key ( app , :modules ) do
310- { :ok , modules } -> modules
311- _ -> [ ]
312- end
308+ if purge_modules? do
309+ modules =
310+ case :application . get_key ( app , :modules ) do
311+ { :ok , modules } -> modules
312+ _ -> [ ]
313+ end
313314
314- if modules != [ ] do
315- Logger . debug ( "Purging #{ length ( modules ) } modules from #{ app } " )
316- for module <- modules , do: purge_module ( module )
315+ if modules != [ ] do
316+ Logger . debug ( "Purging #{ length ( modules ) } modules from #{ app } " )
317+ for module <- modules , do: purge_module ( module )
318+ end
317319 end
318320
319321 Logger . debug ( "Unloading #{ app } " )
@@ -409,20 +411,14 @@ defmodule ElixirLS.LanguageServer.Build do
409411 [ Mix.Project . config ( ) [ :app ] ]
410412 end
411413
412- mix_project_apps_deps =
413- current_deps_by_app
414- |> Map . take ( mix_project_apps )
415- |> Enum . flat_map ( & elem ( & 1 , 1 ) )
416- |> Enum . uniq ( )
417-
418414 # purge mix project apps
419415 # elixir compiler loads apps only on initial compilation
420416 # on subsequent ones it does not update application controller state
421- # if we don't purge the apps we end up with invalid state
417+ # if we don't unload the apps we end up with invalid state
422418 # e.g. :application.get_key(app, :modules) returns outdated module list
423419 # see https://github.com/elixir-lang/elixir/issues/13001
424- for dep <- mix_project_apps_deps do
425- purge_dep ( dep )
420+ for app <- mix_project_apps do
421+ purge_app ( app , false )
426422 end
427423 end
428424
0 commit comments