Skip to content

Commit

Permalink
return type arg list in completions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Dec 13, 2022
1 parent a3fffa7 commit 7b99c28
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
27 changes: 25 additions & 2 deletions lib/elixir_sense/providers/suggestion/reducers/type_specs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.TypeSpecs do
type: :type_spec,
name: String.t(),
arity: non_neg_integer,
origin: String.t(),
origin: String.t() | nil,
args_list: list(String.t()),
spec: String.t(),
doc: String.t(),
signature: String.t(),
Expand Down Expand Up @@ -117,7 +118,7 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.TypeSpecs do
end

defp type_info_to_suggestion(type_info, module) do
origin = if module, do: inspect(module), else: ""
origin = if module, do: inspect(module)

case type_info do
%ElixirSense.Core.State.TypeInfo{args: [args]} ->
Expand All @@ -127,6 +128,7 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.TypeSpecs do
type: :type_spec,
name: type_info.name |> Atom.to_string(),
arity: length(args),
args_list: args,
signature: "#{type_info.name}(#{args_stringified})",
origin: origin,
doc: "",
Expand All @@ -136,10 +138,31 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.TypeSpecs do
}

_ ->
args_list =
if type_info.signature do
part =
type_info.signature
|> String.split("(")
|> Enum.at(1)

if part do
part
|> String.split(")")
|> Enum.at(0)
|> String.split(",")
|> Enum.map(&String.trim/1)
else
[]
end
else
[]
end

%{
type: :type_spec,
name: type_info.name |> Atom.to_string(),
arity: type_info.arity,
args_list: args_list,
signature: type_info.signature,
origin: origin,
doc: type_info.doc,
Expand Down
9 changes: 7 additions & 2 deletions test/elixir_sense/suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,7 @@ defmodule ElixirSense.SuggestionsTest do
assert suggestion.signature == "list()"
assert suggestion.arity == 0
assert suggestion.doc == "A list"
assert suggestion.origin == ""
assert suggestion.origin == nil
end

test "builtin types - retrieve info from typespecs with params" do
Expand All @@ -3104,7 +3104,7 @@ defmodule ElixirSense.SuggestionsTest do
assert suggestion.signature == "list(t)"
assert suggestion.arity == 1
assert suggestion.doc == "Proper list ([]-terminated)"
assert suggestion.origin == ""
assert suggestion.origin == nil
end

test "erlang types" do
Expand Down Expand Up @@ -3180,6 +3180,7 @@ defmodule ElixirSense.SuggestionsTest do
origin: "MyModule",
type: :type_spec,
signature: "my_local_t()",
args_list: [],
doc: "",
spec: "",
metadata: %{}
Expand All @@ -3191,6 +3192,7 @@ defmodule ElixirSense.SuggestionsTest do
origin: "MyModule",
type: :type_spec,
signature: "my_local_arg_t(a, b)",
args_list: ["a", "b"],
doc: "",
spec: "",
metadata: %{}
Expand Down Expand Up @@ -3219,6 +3221,7 @@ defmodule ElixirSense.SuggestionsTest do
origin: "MyModule",
type: :type_spec,
signature: "my_local_t()",
args_list: [],
doc: "",
spec: "",
metadata: %{}
Expand Down Expand Up @@ -3252,6 +3255,7 @@ defmodule ElixirSense.SuggestionsTest do
origin: "SomeModule",
type: :type_spec,
signature: "my_local_pub_t(a, b)",
args_list: ["a", "b"],
doc: "",
spec: "",
metadata: %{}
Expand All @@ -3263,6 +3267,7 @@ defmodule ElixirSense.SuggestionsTest do
origin: "SomeModule",
type: :type_spec,
signature: "my_local_op_t()",
args_list: [],
doc: "",
spec: "",
metadata: %{}
Expand Down

0 comments on commit 7b99c28

Please sign in to comment.