|
1 | 1 | defmodule ElixirLS.LanguageServer.ExUnitTestTracer do |
2 | 2 | use GenServer |
| 3 | + alias ElixirLS.LanguageServer.Build |
3 | 4 |
|
4 | 5 | @tables ~w(tests)a |
5 | 6 |
|
@@ -38,32 +39,35 @@ defmodule ElixirLS.LanguageServer.ExUnitTestTracer do |
38 | 39 | @impl true |
39 | 40 | def handle_call({:get_tests, path}, _from, state) do |
40 | 41 | :ets.delete_all_objects(table_name(:tests)) |
41 | | - tracers = Code.compiler_options()[:tracers] |
42 | | - # TODO build lock? |
43 | | - Code.put_compiler_option(:tracers, [__MODULE__]) |
44 | 42 |
|
45 | 43 | result = |
46 | | - try do |
47 | | - # TODO parallel compiler and diagnostics? |
48 | | - _ = Code.compile_file(path) |
49 | | - |
50 | | - result = |
51 | | - :ets.tab2list(table_name(:tests)) |
52 | | - |> Enum.map(fn {{_file, module, line}, describes} -> |
53 | | - %{ |
54 | | - module: inspect(module), |
55 | | - line: line, |
56 | | - describes: describes |
57 | | - } |
58 | | - end) |
59 | | - |
60 | | - {:ok, result} |
61 | | - rescue |
62 | | - e -> |
63 | | - {:error, e} |
64 | | - after |
65 | | - Code.put_compiler_option(:tracers, tracers) |
66 | | - end |
| 44 | + Build.with_build_lock(fn -> |
| 45 | + tracers = Code.compiler_options()[:tracers] |
| 46 | + |
| 47 | + Code.put_compiler_option(:tracers, [__MODULE__]) |
| 48 | + |
| 49 | + try do |
| 50 | + # parallel compiler and diagnostics? |
| 51 | + _ = Code.compile_file(path) |
| 52 | + |
| 53 | + result = |
| 54 | + :ets.tab2list(table_name(:tests)) |
| 55 | + |> Enum.map(fn {{_file, module, line}, describes} -> |
| 56 | + %{ |
| 57 | + module: inspect(module), |
| 58 | + line: line, |
| 59 | + describes: describes |
| 60 | + } |
| 61 | + end) |
| 62 | + |
| 63 | + {:ok, result} |
| 64 | + rescue |
| 65 | + e -> |
| 66 | + {:error, e} |
| 67 | + after |
| 68 | + Code.put_compiler_option(:tracers, tracers) |
| 69 | + end |
| 70 | + end) |
67 | 71 |
|
68 | 72 | {:reply, result, state} |
69 | 73 | end |
|
0 commit comments