Skip to content

Commit

Permalink
Add doc for local_module_name
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming committed Mar 16, 2024
1 parent 6ecdd0d commit af600cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions apps/common/lib/lexical/ast/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit af600cc

Please sign in to comment.