mirror of
https://github.com/ash-project/igniter.git
synced 2024-09-20 05:22:52 +12:00
fix: properly move to arguments of Module.fun calls
improvement: add `Igniter.Code.Common.expand_literal/1`
This commit is contained in:
parent
aefb8df79a
commit
a5bdf2b7a0
2 changed files with 55 additions and 6 deletions
|
@ -85,6 +85,23 @@ defmodule Igniter.Code.Common do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Expands a literal value using the env at the cursor, if possible
|
||||||
|
"""
|
||||||
|
def expand_literal(zipper) do
|
||||||
|
if Macro.quoted_literal?(zipper.node) do
|
||||||
|
case current_env(zipper) do
|
||||||
|
{:ok, env} ->
|
||||||
|
{:ok, Macro.expand_literals(zipper.node, env)}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
:error
|
||||||
|
end
|
||||||
|
else
|
||||||
|
:error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Adds the provided code to the zipper.
|
Adds the provided code to the zipper.
|
||||||
|
|
||||||
|
@ -691,15 +708,38 @@ defmodule Igniter.Code.Common do
|
||||||
equal_vals?(l, r) || equal_modules?(l, r)
|
equal_vals?(l, r) || equal_modules?(l, r)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp equal_vals?({:__block__, _, [value]} = block, value) do
|
defp equal_vals?({:__block__, _, [value]}, value) do
|
||||||
!extendable_block?(block)
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
defp equal_vals?(value, {:__block__, _, [value]} = block) do
|
defp equal_vals?(value, {:__block__, _, [value]}) do
|
||||||
!extendable_block?(block)
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
defp equal_vals?(_, _), do: false
|
defp equal_vals?(left, right) do
|
||||||
|
cond do
|
||||||
|
extendable_block?(left) ->
|
||||||
|
case left do
|
||||||
|
{:__block__, _, [left]} ->
|
||||||
|
equal_vals?(left, right)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
extendable_block?(right) ->
|
||||||
|
case right do
|
||||||
|
{:__block__, _, [right]} ->
|
||||||
|
equal_vals?(left, right)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
true ->
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@spec expand_alias(Zipper.t()) :: Zipper.t()
|
@spec expand_alias(Zipper.t()) :: Zipper.t()
|
||||||
def expand_alias(zipper) do
|
def expand_alias(zipper) do
|
||||||
|
|
|
@ -422,6 +422,15 @@ defmodule Igniter.Code.Function do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
offset =
|
||||||
|
case zipper.node do
|
||||||
|
{{:., _, _}, _, _args} ->
|
||||||
|
1
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
0
|
||||||
|
end
|
||||||
|
|
||||||
zipper
|
zipper
|
||||||
|> Zipper.down()
|
|> Zipper.down()
|
||||||
|> case do
|
|> case do
|
||||||
|
@ -430,7 +439,7 @@ defmodule Igniter.Code.Function do
|
||||||
|
|
||||||
zipper ->
|
zipper ->
|
||||||
zipper
|
zipper
|
||||||
|> Common.nth_right(index)
|
|> Common.nth_right(index + offset)
|
||||||
|> case do
|
|> case do
|
||||||
:error ->
|
:error ->
|
||||||
:error
|
:error
|
||||||
|
|
Loading…
Reference in a new issue