From 601f9b6aaa6a802da069005915db7e0a10d32a1d Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Wed, 19 Jun 2024 15:51:31 -0400 Subject: [PATCH] improvement: rename `env_at_cursor` to `current_env` closes #45 --- lib/code/common.ex | 14 +++++--------- lib/code/keyword.ex | 2 -- test/code/common_test.exs | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/code/common.ex b/lib/code/common.ex index e8a844d..1d586d4 100644 --- a/lib/code/common.ex +++ b/lib/code/common.ex @@ -99,7 +99,7 @@ defmodule Igniter.Code.Common do ```elixir \"\"\" IO.inspect("Hello, world!") - IO.inspect("Goodbye, world!") + IO.inspect("Goodbye, world!") \"\"\" ``` """ @@ -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 -> @@ -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() @@ -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 """ @@ -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 diff --git a/lib/code/keyword.ex b/lib/code/keyword.ex index 0491d97..c99cf3c 100644 --- a/lib/code/keyword.ex +++ b/lib/code/keyword.ex @@ -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 diff --git a/test/code/common_test.exs b/test/code/common_test.exs index 7827761..7dc3c3c 100644 --- a/test/code/common_test.exs +++ b/test/code/common_test.exs @@ -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 = """