diff --git a/apps/common/lib/lexical/ast/module.ex b/apps/common/lib/lexical/ast/module.ex index 639bb8fcc..a7804ad09 100644 --- a/apps/common/lib/lexical/ast/module.ex +++ b/apps/common/lib/lexical/ast/module.ex @@ -29,13 +29,21 @@ defmodule Lexical.Ast.Module do |> name() end - def local_module_name(entity) when is_atom(entity) do + @doc """ + local module name is the last part of a module name + + ## Examples: + + iex> local_name("Lexical.Ast.Module") + "Module" + """ + def local_name(entity) when is_atom(entity) do entity |> inspect() - |> local_module_name() + |> local_name() end - def local_module_name(entity) when is_binary(entity) do + def local_name(entity) when is_binary(entity) do entity |> String.split(".") |> List.last() diff --git a/apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex b/apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex index ea6b68357..e0b53483d 100644 --- a/apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex +++ b/apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex @@ -123,7 +123,7 @@ defmodule Lexical.RemoteControl.CodeIntelligence.Rename.Module do if result == entity do {:ok, range} else - last_part_length = result |> Ast.Module.local_module_name() |> String.length() + last_part_length = result |> Ast.Module.local_name() |> String.length() # Move the cursor to the next part: # `|Parent.Next.Target.Child` -> 'Parent.|Next.Target.Child' -> 'Parent.Next.|Target.Child' character = position.character + last_part_length + 1 @@ -159,6 +159,6 @@ defmodule Lexical.RemoteControl.CodeIntelligence.Rename.Module do end defp local_module_name(%Range{} = range) do - range |> range_text() |> Ast.Module.local_module_name() + range |> range_text() |> Ast.Module.local_name() end end