Skip to content

Commit

Permalink
handle no signature on callback
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Nov 14, 2023
1 parent 85a1b96 commit 22de3f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/elixir_sense/core/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ defmodule ElixirSense.Core.Introspection do
kind: kind,
arity: arity,
callback: "@#{kind} #{name}(#{args})",
signature: "",
signature: nil,
doc: doc,
metadata: metadata |> Map.put(:optional, key in optional_callbacks)
}
Expand Down
41 changes: 31 additions & 10 deletions lib/elixir_sense/providers/suggestion/reducers/callbacks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,44 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.Callbacks do
Introspection.get_callbacks_with_docs(mod),
def_prefix?(hint, spec) or Matcher.match?("#{name}", hint) do
desc = Introspection.extract_summary_from_docs(doc)
[_, args_str] = Regex.run(~r/.\(([^\)]*)\)/u, signature)

args_list =
args_str
|> String.split(",")
|> Enum.map(&String.trim/1)
{args, args_list} =
if signature do
match_res = Regex.run(~r/.\(([^\)]*)\)/u, signature)

unless match_res do
raise "unable to get arguments from #{inspect(signature)}"
end

[_, args_str] = match_res

args_list =
args_str
|> String.split(",")
|> Enum.map(&String.trim/1)

args =
args_str
|> String.replace("\n", " ")
|> String.split(",")
|> Enum.map_join(", ", &String.trim/1)

{args, args_list}
else
if arity == 0 do
{"", []}
else
args_list = for _ <- 1..arity, do: "term"
{Enum.join(args_list, ", "), args_list}
end
end

%{
type: :callback,
subtype: kind,
name: Atom.to_string(name),
arity: arity,
args:
args_str
|> String.replace("\n", " ")
|> String.split(",")
|> Enum.map_join(", ", &String.trim/1),
args: args,
args_list: args_list,
origin: mod_name,
summary: desc,
Expand Down

0 comments on commit 22de3f6

Please sign in to comment.