Skip to content

Commit

Permalink
Add support for struct
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming committed Dec 3, 2023
1 parent fcdbaf0 commit 43deb94
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Lexical.RemoteControl.CodeIntelligence.Rename do

defp resolve_module(analysis, position) do
case Entity.resolve(analysis, position) do
{:ok, {:module, module}, range} ->
{:ok, {module_or_struct, module}, range} when module_or_struct in [:struct, :module] ->
{:ok, module, range}

{:ok, other, _} ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,45 @@ defmodule Lexical.RemoteControl.CodeIntelligence.RenameTest do
end
end

describe "rename struct" do
test "succeeds when the cursor on the definition" do
{:ok, result} =
~q[
defmodule |Foo do
defstruct bar: 1
end
defmodule Bar do
def foo do
%Foo{}
end
end
] |> rename("Renamed")

assert result =~ ~S[defmodule Renamed do]
assert result =~ ~S[%Renamed{}]
end

test "succeeds when the cursor on the reference" do
{:ok, result} =
~q[
defmodule Foo do
defstruct bar: 1
end
defmodule Bar do
def foo do
%Fo|o{}
end
end
] |> rename("Renamed")

assert result =~ ~S[defmodule Renamed do]
assert result =~ ~S[defmodule Bar do]
assert result =~ ~S[%Renamed{}]
end
end

describe "unsupported" do
test "rename a function" do
assert {:error, {:unsupported, {:local_or_var, ~c"bar"}}} ==
Expand Down

0 comments on commit 43deb94

Please sign in to comment.