Skip to content

Commit

Permalink
remove old way of gather variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed May 7, 2024
1 parent 7f3dd04 commit 269b65a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 469 deletions.
106 changes: 0 additions & 106 deletions lib/next_ls/helpers/ast_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,112 +204,6 @@ defmodule NextLS.ASTHelpers do
end
end

def find_cursor(ast, position) do
ast = {:__block__, [], [ast]}

{tree, cursor_tree} =
ast
|> Zipper.zip()
|> Zipper.traverse_while(nil, fn tree, acc ->
node = Zipper.node(tree)
node_range = Sourceror.get_range(node)

is_inside =
with nil <- node_range do
false
else
_ -> sourceror_inside?(node_range, position)
end

cond do
is_inside ->
{:cont, tree, tree}

true ->
{:skip, tree, acc}
end
end)

if cursor_tree do
left = Zipper.left(cursor_tree)
up = Zipper.up(cursor_tree)

cond_result =
cond do
match?({:->, _, _}, Zipper.node(cursor_tree)) ->
Zipper.update(cursor_tree, fn n ->
case n do
{:->, meta, [params, block]} ->
new_block =
case block do
{:__block__, bm, exprs} ->
{:__block__, bm, exprs ++ [{:__cursor__, [], []}]}

_ ->
{:__block__, [], [block, {:__cursor__, [], []}]}
end

{:->, meta, [params, new_block]}
end
end)

match?({:->, _, _}, Zipper.node(up)) ->
Zipper.update(up, fn n ->
case n do
{:->, meta, [params, block]} ->
new_block =
case block do
{:__block__, bm, exprs} ->
{:__block__, bm, exprs ++ [{:__cursor__, [], []}]}

_ ->
{:__block__, [], [block, {:__cursor__, [], []}]}
end

{:->, meta, [params, new_block]}
end
end)

up && match?({:"::", _, _}, Zipper.node(up)) ->
up
|> Zipper.up()
|> Zipper.update(fn n ->
{:__block__, [],
[
{:__cursor__, [], []},
n
]}
end)

up && match?({:<-, _, _}, Zipper.node(up)) ->
up |> Zipper.insert_left({:__cursor__, [], []}) |> Zipper.down() |> Zipper.rightmost()

up && match?([{{:__block__, _dom, [:do]}, _children} | _], Zipper.node(up)) ->
Zipper.update(up, fn [{{:__block__, dom, [:do]}, children} | rest] ->
case children do
{:__block__, bom, children} ->
[{{:__block__, dom, [:do]}, {:__block__, bom, children ++ [{:__cursor__, [], []}]}} | rest]

child ->
[{{:__block__, dom, [:do]}, {:__block__, [], [child, {:__cursor__, [], []}]}}]
end
end)

left && match?({:__block__, _, [:do]}, Zipper.node(left)) ->
Zipper.update(cursor_tree, fn n ->
{:__block__, [], [n, {:__cursor__, [], []}]}
end)

true ->
Zipper.insert_right(cursor_tree, {:__cursor__, [], []})
end

Zipper.top(cond_result)
else
tree
end
end

def top(nil, acc, _callback), do: acc

def top(%Zipper{path: nil} = zipper, acc, callback), do: callback.(Zipper.node(zipper), zipper, acc)
Expand Down
145 changes: 0 additions & 145 deletions lib/next_ls/helpers/ast_helpers/env.ex

This file was deleted.

Loading

0 comments on commit 269b65a

Please sign in to comment.