Skip to content

Commit b904fb4

Browse files
committed
fix signature provider crash on protocol callbacks
1 parent 3223c02 commit b904fb4

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

apps/language_server/lib/language_server/providers/signature_help/signature.ex

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,23 @@ defmodule ElixirLS.LanguageServer.Providers.SignatureHelp.Signature do
138138
}
139139

140140
nil ->
141-
fun_info = Map.fetch!(metadata.mods_funs_to_positions, {mod, fun, arity})
142-
143-
{spec, doc, _} =
144-
Metadata.get_doc_spec_from_behaviour(
145-
behaviour,
146-
fun,
147-
arity,
141+
category = case metadata.mods_funs_to_positions[{mod, fun, arity}] do
142+
nil ->
143+
if Code.ensure_loaded?(mod) and macro_exported?(mod, fun, arity) do
144+
:macro
145+
else
146+
:function
147+
end
148+
%State.ModFunInfo{} = fun_info ->
148149
State.ModFunInfo.get_category(fun_info)
149-
)
150+
end
151+
152+
{spec, doc, _} = Metadata.get_doc_spec_from_behaviour(
153+
behaviour,
154+
fun,
155+
arity,
156+
category
157+
)
150158

151159
%{
152160
signature

apps/language_server/test/providers/signature_help/signature_test.exs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,32 @@ defmodule ElixirLS.LanguageServer.Providers.SignatureHelp.SignatureTest do
12921292
end
12931293
end
12941294

1295+
test "retrieve metadata function signature - fallback to remote protocol callback" do
1296+
code = """
1297+
defimpl Enumerable, for: Date do
1298+
def count(a) do
1299+
:ok
1300+
end
1301+
end
1302+
1303+
Enumerable.impl_for()
1304+
"""
1305+
1306+
res = Signature.signature(code, 7, 21)
1307+
1308+
assert %{
1309+
active_param: 0,
1310+
signatures: [
1311+
%{
1312+
documentation: "A function available in all protocol definitions" <> _,
1313+
name: "impl_for",
1314+
params: ["data"],
1315+
spec: "@callback impl_for(term()) :: module() | nil"
1316+
}
1317+
]
1318+
} = res
1319+
end
1320+
12951321
test "retrieve metadata macro signature - fallback to macrocallback" do
12961322
code = """
12971323
defmodule MyLocalModule do

0 commit comments

Comments
 (0)