@@ -31,8 +31,6 @@ defmodule ElixirLS.LanguageServer.Build do
3131 fetch_deps ( current_deps )
3232 end
3333
34- # if we won't do it elixir >= 1.11 warns that protocols have already been consolidated
35- purge_consolidated_protocols ( )
3634 { status , diagnostics } = run_mix_compile ( )
3735
3836 diagnostics = Diagnostics . normalize ( diagnostics , root_path )
@@ -78,6 +76,19 @@ defmodule ElixirLS.LanguageServer.Build do
7876
7977 if File . exists? ( mixfile ) do
8078 if module = Mix.Project . get ( ) do
79+ build_path = Mix.Project . config ( ) [ :build_path ]
80+
81+ for { app , path } <- Mix.Project . deps_paths ( ) do
82+ child_module =
83+ Mix.Project . in_project ( app , path , [ build_path: build_path ] , fn mix_project ->
84+ mix_project
85+ end )
86+
87+ if child_module do
88+ purge_module ( child_module )
89+ end
90+ end
91+
8192 # FIXME: Private API
8293 Mix.Project . pop ( )
8394 purge_module ( module )
@@ -102,6 +113,18 @@ defmodule ElixirLS.LanguageServer.Build do
102113 # FIXME: Private API
103114 Mix.ProjectStack . post_config ( build_path: ".elixir_ls/build" )
104115
116+ # TODO elixir 1.15 calls
117+ # Mix.ProjectStack.post_config(state_loader: {:cli, List.first(args)})
118+ # added in https://github.com/elixir-lang/elixir/commit/9e07da862784ac7d18a1884141c49ab049e61691
119+ # def cli
120+ # do we need that?
121+
122+ # since elixir 1.10 mix disables undefined warnings for mix.exs
123+ # see discussion in https://github.com/elixir-lang/elixir/issues/9676
124+ # https://github.com/elixir-lang/elixir/blob/6f96693b355a9b670f2630fd8e6217b69e325c5a/lib/mix/lib/mix/cli.ex#L41
125+ old_undefined = Code . get_compiler_option ( :no_warn_undefined )
126+ Code . put_compiler_option ( :no_warn_undefined , :all )
127+
105128 # We can get diagnostics if Mixfile fails to load
106129 { status , diagnostics } =
107130 case Kernel.ParallelCompiler . compile ( [ mixfile ] ) do
@@ -116,6 +139,9 @@ defmodule ElixirLS.LanguageServer.Build do
116139 }
117140 end
118141
142+ # restore warnings
143+ Code . put_compiler_option ( :no_warn_undefined , old_undefined )
144+
119145 if status == :ok do
120146 # The project may override our logger config, so we reset it after loading their config
121147 logger_config = Application . get_all_env ( :logger )
@@ -136,15 +162,21 @@ defmodule ElixirLS.LanguageServer.Build do
136162 end
137163
138164 defp run_mix_compile do
139- # TODO consider adding --no-compile
140- case Mix.Task . run ( "compile" , [ "--return-errors" , "--ignore-module-conflict" ] ) do
165+ # TODO --all-warnings not needed on 1.15
166+ case Mix.Task . run ( "compile" , [
167+ "--return-errors" ,
168+ "--ignore-module-conflict" ,
169+ "--all-warnings" ,
170+ "--no-protocol-consolidation"
171+ ] ) do
141172 { status , diagnostics } when status in [ :ok , :error , :noop ] and is_list ( diagnostics ) ->
142173 { status , diagnostics }
143174
144175 status when status in [ :ok , :noop ] ->
145176 { status , [ ] }
146177
147- _ ->
178+ other ->
179+ Logger . debug ( "mix compile returned #{ inspect ( other ) } " )
148180 { :ok , [ ] }
149181 end
150182 end
@@ -169,26 +201,6 @@ defmodule ElixirLS.LanguageServer.Build do
169201 end
170202 end
171203
172- defp purge_consolidated_protocols do
173- config = Mix.Project . config ( )
174- path = Mix.Project . consolidation_path ( config )
175-
176- with { :ok , beams } <- File . ls ( path ) do
177- Enum . map ( beams , & ( & 1 |> Path . rootname ( ".beam" ) |> String . to_atom ( ) |> purge_module ( ) ) )
178- else
179- { :error , :enoent } ->
180- # consolidation_path does not exist
181- :ok
182-
183- { :error , reason } ->
184- Logger . warn ( "Unable to purge consolidated protocols from #{ path } : #{ inspect ( reason ) } " )
185- end
186-
187- # NOTE this implementation is based on https://github.com/phoenixframework/phoenix/commit/b5580e9
188- # calling `Code.delete_path(path)` may be unnecessary in our case
189- Code . delete_path ( path )
190- end
191-
192204 defp purge_module ( module ) do
193205 :code . purge ( module )
194206 :code . delete ( module )
@@ -334,19 +346,29 @@ defmodule ElixirLS.LanguageServer.Build do
334346
335347 def set_compiler_options ( options \\ [ ] , parser_options \\ [ ] ) do
336348 parser_options =
337- parser_options
338- |> Keyword . merge (
349+ Keyword . merge ( parser_options ,
339350 columns: true ,
340351 token_metadata: true
341352 )
342353
343354 options =
344- options
345- |> Keyword . merge (
355+ Keyword . merge ( options ,
346356 tracers: [ Tracer ] ,
347357 parser_options: parser_options
348358 )
349359
360+ options =
361+ if Version . match? ( System . version ( ) , ">= 1.14.0" ) do
362+ Keyword . merge ( options ,
363+ # we are running the server with consolidated protocols
364+ # this disables warnings `X has already been consolidated`
365+ # when running `compile` task
366+ ignore_already_consolidated: true
367+ )
368+ else
369+ options
370+ end
371+
350372 Code . compiler_options ( options )
351373 end
352374
0 commit comments