Skip to content

Commit 18f362d

Browse files
committed
avoid Code.ensure_compiled as it is prone to locking
1 parent a36d47e commit 18f362d

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

apps/elixir_ls_utils/lib/completion_engine.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ defmodule ElixirLS.Utils.CompletionEngine do
10441044
metadata.mods_funs_to_positions |> Map.has_key?({mod, nil, nil}) ->
10451045
get_metadata_module_funs(mod, include_builtin, env, metadata, cursor_position)
10461046

1047-
match?({:module, _}, ensure_loaded(mod)) ->
1047+
ensure_loaded?(mod) ->
10481048
get_module_funs(mod, include_builtin)
10491049

10501050
true ->
@@ -1380,8 +1380,8 @@ defmodule ElixirLS.Utils.CompletionEngine do
13801380
do: {{fun_name, new_arity}, arity}
13811381
end
13821382

1383-
defp ensure_loaded(Elixir), do: {:error, :nofile}
1384-
defp ensure_loaded(mod), do: Code.ensure_compiled(mod)
1383+
defp ensure_loaded?(Elixir), do: false
1384+
defp ensure_loaded?(mod), do: Code.ensure_loaded?(mod)
13851385

13861386
defp get_struct_info({:atom, module}, metadata) when is_atom(module) do
13871387
case metadata.structs[module] do

apps/language_server/lib/language_server/providers/execute_command/llm_type_info.ex

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,25 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmTypeInfo do
4949
end
5050

5151
defp extract_type_info_for_symbol(:module, module, state) do
52-
case Code.ensure_compiled(module) do
53-
{:module, actual_module} ->
54-
type_info = extract_type_info(actual_module, state)
55-
{:ok, type_info}
56-
57-
{:error, reason} ->
58-
{:error, "Module not found or not compiled: #{inspect(reason)}"}
52+
if Code.ensure_loaded?(module) do
53+
type_info = extract_type_info(module, state)
54+
{:ok, type_info}
55+
else
56+
{:error, "Module not found or not compiled"}
5957
end
6058
end
6159

6260
defp extract_type_info_for_symbol(:remote_call, {module, function, arity}, state) do
63-
case Code.ensure_compiled(module) do
64-
{:module, actual_module} ->
65-
# Extract all type info from the module (same as for :module case)
66-
# then filter to only include the relevant function
67-
full_type_info = extract_type_info(actual_module, state)
68-
69-
# Filter the results to only include the specific function/type/callback
70-
filtered_type_info = filter_type_info_by_function(full_type_info, function, arity)
71-
{:ok, filtered_type_info}
72-
73-
{:error, reason} ->
74-
{:error, "Module not found or not compiled: #{inspect(reason)}"}
61+
if Code.ensure_loaded?(module) do
62+
# Extract all type info from the module (same as for :module case)
63+
# then filter to only include the relevant function
64+
full_type_info = extract_type_info(module, state)
65+
66+
# Filter the results to only include the specific function/type/callback
67+
filtered_type_info = filter_type_info_by_function(full_type_info, function, arity)
68+
{:ok, filtered_type_info}
69+
else
70+
{:error, "Module not found or not compiled"}
7571
end
7672
end
7773

apps/language_server/lib/language_server/providers/plugins/module_store.ex

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ defmodule ElixirLS.LanguageServer.Plugins.ModuleStore do
8686
defp all_loaded do
8787
Applications.get_modules_from_applications()
8888
|> Enum.filter(fn module ->
89-
try do
90-
_ = Code.ensure_compiled(module)
91-
function_exported?(module, :module_info, 0)
92-
rescue
93-
_ ->
94-
false
95-
end
89+
function_exported?(module, :module_info, 0)
9690
end)
9791
end
9892

0 commit comments

Comments
 (0)