@@ -3,13 +3,6 @@ defmodule ElixirLS.LanguageServer.Build do
3
3
alias ElixirLS.Utils.MixfileHelpers
4
4
require Logger
5
5
6
- defp store_required_apps ( ) do
7
- unless :persistent_term . get ( :language_server_required_apps , false ) do
8
- apps = Application . loaded_applications ( ) |> Enum . map ( & elem ( & 1 , 0 ) )
9
- :persistent_term . put ( :language_server_required_apps , apps )
10
- end
11
- end
12
-
13
6
def build ( parent , root_path , opts ) when is_binary ( root_path ) do
14
7
Application . loaded_applications ( ) |> Enum . map ( & elem ( & 1 , 0 ) )
15
8
@@ -187,6 +180,19 @@ defmodule ElixirLS.LanguageServer.Build do
187
180
:global . trans ( { __MODULE__ , self ( ) } , func )
188
181
end
189
182
183
+ ## Mix Project Reloading
184
+
185
+ # Make sure we store the list of applications required by the language server.
186
+ defp store_required_apps ( ) do
187
+ unless :persistent_term . get ( :language_server_required_apps , false ) do
188
+ apps = Application . loaded_applications ( ) |> Enum . map ( & elem ( & 1 , 0 ) )
189
+ :persistent_term . put ( :language_server_required_apps , apps )
190
+ end
191
+ end
192
+
193
+ # Reloads the Mix project. This function prunes existing project modules,
194
+ # clears Mix caches, resets logger and compiler options, and finally
195
+ # compiles the mixfile (collecting any diagnostics).
190
196
defp reload_project ( mixfile , root_path ) do
191
197
store_required_apps ( )
192
198
@@ -436,6 +442,8 @@ defmodule ElixirLS.LanguageServer.Build do
436
442
end
437
443
end
438
444
445
+ ## Compilation and Cleaning
446
+
439
447
defp run_mix_compile ( force? ) do
440
448
opts = [
441
449
"--return-errors" ,
@@ -497,6 +505,8 @@ defmodule ElixirLS.LanguageServer.Build do
497
505
end
498
506
end
499
507
508
+ ## Dependency Purging
509
+
500
510
defp purge_module ( module ) do
501
511
:code . purge ( module )
502
512
:code . delete ( module )
@@ -673,6 +683,8 @@ defmodule ElixirLS.LanguageServer.Build do
673
683
:ok
674
684
end
675
685
686
+ ## Compiler Options and Diagnostics
687
+
676
688
def set_compiler_options ( options \\ [ ] , parser_options \\ [ ] ) do
677
689
parser_options =
678
690
Keyword . merge ( parser_options ,
@@ -716,6 +728,8 @@ defmodule ElixirLS.LanguageServer.Build do
716
728
end
717
729
end
718
730
731
+ # Wraps the given function in a diagnostics context (using Code.with_diagnostics
732
+ # on newer Elixir versions).
719
733
def with_diagnostics ( opts \\ [ ] , fun ) do
720
734
# Code.with_diagnostics is broken on elixir < 1.15.3
721
735
if Version . match? ( System . version ( ) , ">= 1.15.3" ) do
0 commit comments