Skip to content

Commit a265fda

Browse files
committed
extract handle_compile_phase
1 parent dfb5bef commit a265fda

File tree

1 file changed

+46
-33
lines changed
  • apps/language_server/lib/language_server

1 file changed

+46
-33
lines changed

apps/language_server/lib/language_server/build.ex

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,14 @@ defmodule ElixirLS.LanguageServer.Build do
6868

6969
case deps_result do
7070
:ok ->
71-
if Keyword.get(opts, :compile?) do
72-
{status, compile_diagnostics} =
73-
run_mix_compile(Keyword.get(opts, :force?, false))
74-
75-
compile_diagnostics =
76-
compile_diagnostics
77-
|> Enum.map(
78-
&Diagnostics.from_mix_task_compiler_diagnostic(&1, mixfile, root_path)
79-
)
80-
81-
if status == :ok do
82-
# reload apps to make sure app controller has the correct list of modules
83-
# if we don't do that, workspace symbols and other providers relying on
84-
# `:application.get_key(app, :modules)` would not notice newly added modules
85-
# no need to do that on :noop and :error
86-
# workaround for https://github.com/elixir-lang/elixir/issues/13001
87-
unload_mix_project_apps(true)
88-
end
89-
90-
Server.build_finished(
91-
parent,
92-
{status, mixfile_diagnostics ++ deps_diagnostics ++ compile_diagnostics}
93-
)
94-
95-
:"mix_compile_#{status}"
96-
else
97-
Server.build_finished(
98-
parent,
99-
{:ok, mixfile_diagnostics ++ deps_diagnostics}
100-
)
101-
102-
:mix_compile_disabled
103-
end
71+
handle_compile_phase(
72+
parent,
73+
mixfile,
74+
root_path,
75+
mixfile_diagnostics,
76+
deps_diagnostics,
77+
opts
78+
)
10479

10580
{:error, kind, err, stacktrace} ->
10681
Server.build_finished(
@@ -180,6 +155,44 @@ defmodule ElixirLS.LanguageServer.Build do
180155
:global.trans({__MODULE__, self()}, func)
181156
end
182157

158+
# If compilation is enabled, run mix compile and report diagnostics;
159+
# otherwise, simply report the project load diagnostics.
160+
defp handle_compile_phase(
161+
parent,
162+
mixfile,
163+
root_path,
164+
mixfile_diagnostics,
165+
deps_diagnostics,
166+
opts
167+
) do
168+
if Keyword.get(opts, :compile?) do
169+
{status, compile_raw_diagnostics} = run_mix_compile(Keyword.get(opts, :force?, false))
170+
171+
compile_diagnostics =
172+
Enum.map(compile_raw_diagnostics, fn diag ->
173+
Diagnostics.from_mix_task_compiler_diagnostic(diag, mixfile, root_path)
174+
end)
175+
176+
if status == :ok do
177+
# reload apps to make sure app controller has the correct list of modules
178+
# if we don't do that, workspace symbols and other providers relying on
179+
# `:application.get_key(app, :modules)` would not notice newly added modules
180+
# no need to do that on :noop and :error
181+
# workaround for https://github.com/elixir-lang/elixir/issues/13001
182+
unload_mix_project_apps(true)
183+
end
184+
185+
diagnostics = mixfile_diagnostics ++ deps_diagnostics ++ compile_diagnostics
186+
187+
Server.build_finished(parent, {status, diagnostics})
188+
:"mix_compile_#{status}"
189+
else
190+
diagnostics = mixfile_diagnostics ++ deps_diagnostics
191+
Server.build_finished(parent, {:ok, diagnostics})
192+
:mix_compile_disabled
193+
end
194+
end
195+
183196
## Mix Project Reloading
184197

185198
# Make sure we store the list of applications required by the language server.

0 commit comments

Comments
 (0)