Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Loosen find_references #831

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading