Skip to content

Commit

Permalink
rescue error in posb build scope closing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 24, 2023
1 parent 4641993 commit 901e18d
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,30 @@ defmodule ElixirSense.Core.MetadataBuilder do
{_ast, [state]} =
Macro.traverse(ast, [%State{}], &safe_call_pre/2, &safe_call_post/2)

state
|> remove_attributes_scope
|> remove_behaviours_scope
|> remove_alias_scope
|> remove_import_scope
|> remove_require_scope
|> remove_vars_scope
|> remove_namespace
|> remove_protocol_implementation
try do
state
|> remove_attributes_scope
|> remove_behaviours_scope
|> remove_alias_scope
|> remove_import_scope
|> remove_require_scope
|> remove_vars_scope
|> remove_namespace
|> remove_protocol_implementation
rescue
exception ->
warn(
Exception.format(
:error,
"#{inspect(exception.__struct__)} during metadata build scope closing:\n" <>
"#{Exception.message(exception)}\n" <>
"ast node: #{inspect(ast, limit: :infinity)}",
__STACKTRACE__
)
)

state
end
end

defp safe_call_pre(ast, [state = %State{} | _] = states) do
Expand Down Expand Up @@ -587,7 +602,7 @@ defmodule ElixirSense.Core.MetadataBuilder do
{def_name, meta, [{:when, _, [{name, meta2, params}, guards]}, body]},
state
)
when def_name in @defs do
when def_name in @defs and is_atom(name) do
ast_without_params = {def_name, meta, [{name, add_no_call(meta2), []}, guards, body]}
pre_func(ast_without_params, state, meta, name, params)
end
Expand All @@ -609,7 +624,7 @@ defmodule ElixirSense.Core.MetadataBuilder do
]},
state
)
when def_name in @defs do
when def_name in @defs and is_atom(name) do
ast_without_params = {def_name, meta, [{name, add_no_call(meta2), []}, body]}
pre_func(ast_without_params, state, meta, name, params)
end
Expand Down

0 comments on commit 901e18d

Please sign in to comment.