Skip to content

Commit

Permalink
improvement: rename env_at_cursor to current_env
Browse files Browse the repository at this point in the history
closes #45
  • Loading branch information
zachdaniel committed Jun 19, 2024
1 parent 680526c commit 601f9b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
14 changes: 5 additions & 9 deletions lib/code/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ defmodule Igniter.Code.Common do
```elixir
\"\"\"
IO.inspect("Hello, world!")
IO.inspect("Goodbye, world!")
IO.inspect("Goodbye, world!")
\"\"\"
```
"""
Expand Down Expand Up @@ -220,7 +220,7 @@ defmodule Igniter.Code.Common do
end

def use_aliases(new_code, current_code) do
case env_at_cursor(current_code) do
case current_env(current_code) do
{:ok, env} ->
Macro.prewalk(new_code, fn
{:__aliases__, _, parts} = node ->
Expand Down Expand Up @@ -558,7 +558,7 @@ defmodule Igniter.Code.Common do
Expands the environment at the current zipper position and returns the
expanded environment. Currently used for properly working with aliases.
"""
def env_at_cursor(zipper) do
def current_env(zipper) do
zipper
|> do_add_code({:__cursor__, [], []}, :after, false)
|> Zipper.topmost_root()
Expand All @@ -575,11 +575,7 @@ defmodule Igniter.Code.Common do
end)
rescue
e ->
# if Application.get_env(:igniter, :testing) do
reraise e, __STACKTRACE__
# else
# {:error, e}
# end
{:error, e}
end

@doc """
Expand Down Expand Up @@ -625,7 +621,7 @@ defmodule Igniter.Code.Common do

@spec expand_aliases(Zipper.t()) :: Zipper.t()
def expand_aliases(zipper) do
case env_at_cursor(zipper) do
case current_env(zipper) do
{:ok, env} ->
Zipper.traverse(zipper, fn x ->
x
Expand Down
2 changes: 0 additions & 2 deletions lib/code/keyword.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ defmodule Igniter.Code.Keyword do
|> Sourceror.to_string()
|> Sourceror.parse_string!()

Common.env_at_cursor(zipper) |> IO.inspect()

value = Common.use_aliases(value, zipper)

if meta[:format] do
Expand Down
2 changes: 1 addition & 1 deletion test/code/common_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Igniter.Code.CommonTest do
end
end

describe "env_at_cursor/2" do
describe "current_env/2" do
test "knows about aliases" do
zipper =
"""
Expand Down

0 comments on commit 601f9b6

Please sign in to comment.