Skip to content

Commit

Permalink
Apply the defdelegate suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming committed Mar 28, 2024
1 parent 5a47568 commit 5cecc8b
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ defmodule Lexical.RemoteControl.CodeMod.Rename do

@spec prepare(Analysis.t(), Position.t()) ::
{:ok, {atom(), String.t()}, Range.t()} | {:error, term()}
def prepare(%Analysis{} = analysis, %Position{} = position) do
Rename.Prepare.prepare(analysis, position)
end
defdelegate prepare(analysis, position), to: Rename.Prepare

@rename_mapping %{module: Rename.Module}

@spec rename(Analysis.t(), Position.t(), String.t()) ::
{:ok, %{Lexical.uri() => [Edit.t()]}} | {:error, term()}
def rename(%Analysis{} = analysis, %Position{} = position, new_name) do
with {:ok, renamable, entity, range} <- Rename.Prepare.resolve(analysis, position) do
rename_module = @rename_mapping[renamable]
{:ok, rename_module.rename(range, new_name, entity)}
with {:ok, {renamable, entity}, range} <- Rename.Prepare.resolve(analysis, position) do
rename_module = @rename_mapping[renamable]
{:ok, rename_module.rename(range, new_name, entity)}
end
end
end

0 comments on commit 5cecc8b

Please sign in to comment.