From 58e23010d2d28ca8c687366c07428a6f697147ce Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Mon, 26 Jun 2023 23:13:21 +0200 Subject: [PATCH] put test tracer under build lock Fixes https://github.com/elixir-lsp/elixir-ls/issues/919 --- .../language_server/ex_unit_test_tracer.ex | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/apps/language_server/lib/language_server/ex_unit_test_tracer.ex b/apps/language_server/lib/language_server/ex_unit_test_tracer.ex index 6f0cf3e95..1d8a189da 100644 --- a/apps/language_server/lib/language_server/ex_unit_test_tracer.ex +++ b/apps/language_server/lib/language_server/ex_unit_test_tracer.ex @@ -1,5 +1,6 @@ defmodule ElixirLS.LanguageServer.ExUnitTestTracer do use GenServer + alias ElixirLS.LanguageServer.Build @tables ~w(tests)a @@ -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