Skip to content

Commit

Permalink
put test tracer under build lock
Browse files Browse the repository at this point in the history
Fixes #919
  • Loading branch information
lukaszsamson committed Jun 26, 2023
1 parent 88dd761 commit 58e2301
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions apps/language_server/lib/language_server/ex_unit_test_tracer.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule ElixirLS.LanguageServer.ExUnitTestTracer do
use GenServer
alias ElixirLS.LanguageServer.Build

@tables ~w(tests)a

Expand Down Expand Up @@ -38,32 +39,35 @@ defmodule ElixirLS.LanguageServer.ExUnitTestTracer do
@impl true
def handle_call({:get_tests, path}, _from, state) do
:ets.delete_all_objects(table_name(:tests))
tracers = Code.compiler_options()[:tracers]
# TODO build lock?
Code.put_compiler_option(:tracers, [__MODULE__])

result =
try do
# TODO parallel compiler and diagnostics?
_ = Code.compile_file(path)

result =
:ets.tab2list(table_name(:tests))
|> Enum.map(fn {{_file, module, line}, describes} ->
%{
module: inspect(module),
line: line,
describes: describes
}
end)

{:ok, result}
rescue
e ->
{:error, e}
after
Code.put_compiler_option(:tracers, tracers)
end
Build.with_build_lock(fn ->
tracers = Code.compiler_options()[:tracers]

Code.put_compiler_option(:tracers, [__MODULE__])

try do
# parallel compiler and diagnostics?
_ = Code.compile_file(path)

result =
:ets.tab2list(table_name(:tests))
|> Enum.map(fn {{_file, module, line}, describes} ->
%{
module: inspect(module),
line: line,
describes: describes
}
end)

{:ok, result}
rescue
e ->
{:error, e}
after
Code.put_compiler_option(:tracers, tracers)
end
end)

{:reply, result, state}
end
Expand Down

0 comments on commit 58e2301

Please sign in to comment.