Skip to content

Commit bb17c90

Browse files
committed
handle cursor in more places
1 parent 51db16b commit bb17c90

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lib/elixir_sense/core/compiler.ex

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,19 @@ defmodule ElixirSense.Core.Compiler do
871871
{expanded_fun, state, _} = expand(fun, state, %{env | function: fa})
872872
{expanded_fun, state}
873873

874+
# sometimes cursor turns the AST around and transforms function head node into a 2-tuple
875+
{{:__cursor__, cursor_meta, [{fun, _, context}]}, meta, args}
876+
when (is_atom(fun) and is_atom(context) and is_list(args)) or is_atom(args) ->
877+
fa = {fun, if(is_list(args), do: length(args), else: 0)}
878+
879+
{expanded_fun, state, _} =
880+
expand({:__cursor__, cursor_meta, [{fun, meta, args}]}, state, %{
881+
env
882+
| function: fa
883+
})
884+
885+
{expanded_fun, state}
886+
874887
_ ->
875888
{fun, state}
876889
end
@@ -1065,11 +1078,12 @@ defmodule ElixirSense.Core.Compiler do
10651078

10661079
{arg, state, env} = expand(arg, state, env)
10671080

1068-
state = if Keyword.keyword?(arg) do
1069-
State.register_optional_callbacks(state, arg)
1070-
else
1071-
state
1072-
end
1081+
state =
1082+
if Keyword.keyword?(arg) do
1083+
State.register_optional_callbacks(state, arg)
1084+
else
1085+
state
1086+
end
10731087

10741088
{{:@, meta, [{:optional_callbacks, doc_meta, [arg]}]}, state, env}
10751089
end
@@ -1719,6 +1733,19 @@ defmodule ElixirSense.Core.Compiler do
17191733
{expanded_call, state, _} = expand(call, state, %{env | function: fa})
17201734
{expanded_call, state}
17211735

1736+
# sometimes cursor turns the AST around and transforms function head node into a 2-tuple
1737+
{{:__cursor__, cursor_meta, [{fun, _, context}]}, meta, args}
1738+
when (is_atom(fun) and is_atom(context) and is_list(args)) or is_atom(args) ->
1739+
fa = {fun, if(is_list(args), do: length(args), else: 0)}
1740+
1741+
{expanded_call, state, _} =
1742+
expand({:__cursor__, cursor_meta, [{fun, meta, args}]}, state, %{
1743+
env
1744+
| function: fa
1745+
})
1746+
1747+
{expanded_call, state}
1748+
17221749
_ ->
17231750
{call, state}
17241751
end

lib/elixir_sense/core/compiler/typespec.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ defmodule ElixirSense.Core.Compiler.Typespec do
2121
end
2222
end
2323

24+
def type_to_signature({:"::", _, [{{:__cursor__, _, [{n, _, context}]}, _, a}, _]})
25+
when (is_atom(n) and is_atom(context) and is_list(a)) or is_atom(a) do
26+
{n, if(is_list(a), do: a, else: [])}
27+
end
28+
2429
def type_to_signature({:"::", _, [{name, _, args}, _]})
2530
when is_atom(name) and name != :"::",
2631
do: {name, args}
2732

33+
# this may not be needed
2834
def type_to_signature({:__cursor__, _, args}) when is_list(args) do
2935
case args do
3036
[{n, _, a} | _] ->
@@ -36,6 +42,12 @@ defmodule ElixirSense.Core.Compiler.Typespec do
3642
end
3743
end
3844

45+
# this may not be needed
46+
def type_to_signature({{:__cursor__, _, [{n, _, context}]}, _, a})
47+
when (is_atom(n) and is_atom(context) and is_list(a)) or is_atom(a) do
48+
{n, if(is_list(a), do: a, else: [])}
49+
end
50+
3951
def type_to_signature({name, _, args}) when is_atom(name) and name != :"::" do
4052
# elixir returns :error here, we handle incomplete signatures
4153
{name, args}

0 commit comments

Comments
 (0)