Skip to content

Commit f862785

Browse files
committed
improve handling of nodes wrapped in cursor
1 parent 73ce7e0 commit f862785

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

lib/elixir_sense/core/compiler.ex

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,25 @@ defmodule ElixirSense.Core.Compiler do
855855
|> Enum.reduce(state, fn fun, state ->
856856
state_orig = state
857857

858+
{fun, state} =
859+
case fun do
860+
{:__cursor__, _, list} when is_list(list) ->
861+
fa =
862+
case list do
863+
[{f, _, a} | _] ->
864+
{f, length(a || [])}
865+
866+
_ ->
867+
{:__unknown__, 0}
868+
end
869+
870+
{expanded_fun, state, _} = expand(fun, state, %{env | function: fa})
871+
{expanded_fun, state}
872+
873+
_ ->
874+
{fun, state}
875+
end
876+
858877
{fun, state, has_unquotes} =
859878
if __MODULE__.Quote.has_unquotes(fun) do
860879
state = State.new_vars_scope(state)
@@ -1682,14 +1701,23 @@ defmodule ElixirSense.Core.Compiler do
16821701
)
16831702
when module != nil and
16841703
def_kind in [:def, :defp, :defmacro, :defmacrop, :defguard, :defguardp] do
1685-
state =
1704+
{call, state} =
16861705
case call do
16871706
{:__cursor__, _, list} when is_list(list) ->
1688-
{_, state, _} = expand(call, state, %{env | function: {:__unknown__, 0}})
1689-
state
1707+
fa =
1708+
case list do
1709+
[{f, _, a} | _] ->
1710+
{f, length(a || [])}
1711+
1712+
_ ->
1713+
{:__unknown__, 0}
1714+
end
1715+
1716+
{expanded_call, state, _} = expand(call, state, %{env | function: fa})
1717+
{expanded_call, state}
16901718

16911719
_ ->
1692-
state
1720+
{call, state}
16931721
end
16941722

16951723
state_orig = state

lib/elixir_sense/core/compiler/typespec.ex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ defmodule ElixirSense.Core.Compiler.Typespec do
1111

1212
def type_to_signature({:"::", _, [{:__cursor__, _, args}, _]})
1313
when is_list(args) do
14-
# type name replaced by cursor
15-
{:__unknown__, []}
14+
case args do
15+
[{n, _, a} | _] ->
16+
{n, a || []}
17+
18+
_ ->
19+
# type name replaced by cursor
20+
{:__unknown__, []}
21+
end
1622
end
1723

1824
def type_to_signature({:"::", _, [{name, _, args}, _]})
1925
when is_atom(name) and name != :"::",
2026
do: {name, args}
2127

2228
def type_to_signature({:__cursor__, _, args}) when is_list(args) do
23-
# type name replaced by cursor
24-
{:__unknown__, []}
29+
case args do
30+
[{n, _, a} | _] ->
31+
{n, a || []}
32+
33+
_ ->
34+
# type name replaced by cursor
35+
{:__unknown__, []}
36+
end
2537
end
2638

2739
def type_to_signature({name, _, args}) when is_atom(name) and name != :"::" do

lib/elixir_sense/core/source.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ defmodule ElixirSense.Core.Source do
504504

505505
defp find_cursor_in_params(params, call, meta) do
506506
case Enum.reverse(params) do
507-
[{:__cursor__, _, []} | rest] ->
507+
[{:__cursor__, _, list} | rest] when is_list(list) ->
508508
{:ok,
509509
%{
510510
call: call,
@@ -518,7 +518,7 @@ defmodule ElixirSense.Core.Source do
518518

519519
[keyword_list | rest] when is_list(keyword_list) ->
520520
case Enum.reverse(keyword_list) do
521-
[{:__cursor__, _, []} | kl_rest] ->
521+
[{:__cursor__, _, list} | kl_rest] when is_list(list) ->
522522
{:ok,
523523
%{
524524
call: call,
@@ -530,7 +530,7 @@ defmodule ElixirSense.Core.Source do
530530
option: nil
531531
}}
532532

533-
[{atom, {:__cursor__, _, []}} | kl_rest] when is_atom(atom) ->
533+
[{atom, {:__cursor__, _, list}} | kl_rest] when is_atom(atom) and is_list(list) ->
534534
{:ok,
535535
%{
536536
call: call,

lib/elixir_sense/providers/plugins/phoenix/scope.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule ElixirSense.Providers.Plugins.Phoenix.Scope do
1616
end
1717

1818
defp get_scopes(ast) do
19-
path = Macro.path(ast, &match?({:__cursor__, _, _}, &1))
19+
path = Macro.path(ast, &match?({:__cursor__, _, list} when is_list(list), &1))
2020

2121
scopes =
2222
path

0 commit comments

Comments
 (0)