diff --git a/apps/remote_control/lib/lexical/remote_control/code_intelligence/references.ex b/apps/remote_control/lib/lexical/remote_control/code_intelligence/references.ex index 3deb5b6af..878c6b37a 100644 --- a/apps/remote_control/lib/lexical/remote_control/code_intelligence/references.ex +++ b/apps/remote_control/lib/lexical/remote_control/code_intelligence/references.ex @@ -35,15 +35,18 @@ defmodule Lexical.RemoteControl.CodeIntelligence.References do end defp find_references( - {:call, module, function_name, arity}, + {:call, module, function_name, _arity}, _analysis, _position, include_definitions? ) do - subject = Subject.mfa(module, function_name, arity) + subject = Subject.mfa(module, function_name, "") subtype = subtype(include_definitions?) - query(subject, type: {:function, :_}, subtype: subtype) + case Store.prefix(subject, type: {:function, :_}, subtype: subtype) do + {:ok, entries} -> Enum.map(entries, &to_location/1) + _ -> [] + end end defp find_references( diff --git a/apps/remote_control/test/lexical/remote_control/code_intelligence/references_test.exs b/apps/remote_control/test/lexical/remote_control/code_intelligence/references_test.exs index 1d73db782..06932111d 100644 --- a/apps/remote_control/test/lexical/remote_control/code_intelligence/references_test.exs +++ b/apps/remote_control/test/lexical/remote_control/code_intelligence/references_test.exs @@ -107,6 +107,23 @@ defmodule Lexical.RemoteControl.CodeIntelligence.ReferencesTest do assert [%Location{} = location] = references(project, "Functions.do_map|(a, b)", code) assert decorate(code, location.range) =~ "def func(x), do: «do_map(x, & &1 + 1)»" end + + test "are found in function definitions with optional arguments", %{project: project} do + referenced = ~q/ + defmodule Functions do + def do_map|(a, b, c \\ 3), do: {a, b, c} + def func(x), do: do_map(x, 3, 5) + def func2(x), do: do_map(x, 3) + end + / + + {_, code} = pop_cursor(referenced) + + references = references(project, referenced, code) + assert [first, second] = Enum.sort_by(references, & &1.range.start.line) + assert decorate(code, first.range) =~ " def func(x), do: «do_map(x, 3, 5)»" + assert decorate(code, second.range) =~ " def func2(x), do: «do_map(x, 3)»" + end end describe "module references" do