Skip to content

Commit f04f45b

Browse files
committed
wip
1 parent 390fa8e commit f04f45b

File tree

2 files changed

+88
-11
lines changed

2 files changed

+88
-11
lines changed

apps/language_server/lib/language_server/providers/completion/reducers/params.ex

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,66 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
4545
env,
4646
mods_funs,
4747
metadata_types,
48-
{1, 1},
48+
cursor_context.cursor_position,
4949
not elixir_prefix
5050
) do
51-
list =
52-
if Code.ensure_loaded?(mod) do
53-
TypeInfo.extract_param_options(mod, fun, npar)
54-
|> Kernel.++(TypeInfo.extract_param_options(mod, :"MACRO-#{fun}", npar + 1))
55-
|> options_to_suggestions(mod)
56-
|> Enum.filter(&Matcher.match?(&1.name, hint))
57-
else
58-
# TODO metadata?
59-
[]
60-
end
51+
list = for {name, type} <- ElixirSense.Core.Options.get_param_options(mod, fun, npar + 1, buffer_metadata) do
52+
%{
53+
doc: "",
54+
expanded_spec: "",
55+
name: name |> Atom.to_string(),
56+
origin: inspect(mod),
57+
type: :param_option,
58+
type_spec: Introspection.to_string_with_parens(type)
59+
}
60+
end
61+
62+
63+
# list =
64+
# if Code.ensure_loaded?(mod) do
65+
# if function_exported?(mod, fun, npar + 1) do
66+
# TypeInfo.extract_param_options(mod, fun, npar)
67+
# else
68+
# TypeInfo.extract_param_options(mod, :"MACRO-#{fun}", npar + 1)
69+
# end
70+
# |> options_to_suggestions(mod)
71+
# |> Enum.filter(&Matcher.match?(&1.name, hint))
72+
# |> dbg
73+
# else
74+
# # TODO metadata?
75+
# dbg(buffer_metadata.specs)
76+
77+
# with %ElixirSense.Core.State.SpecInfo{specs: [spec | _]} = info <-
78+
# buffer_metadata.specs[{mod, fun, npar + 1}],
79+
# {:ok,
80+
# {:@, _,
81+
# [
82+
# {:spec, _,
83+
# [
84+
# {:"::", _,
85+
# [
86+
# {^fun, _, params},
87+
# _
88+
# ]}
89+
# ]}
90+
# ]}}
91+
# when is_list(params) <- Code.string_to_quoted(spec),
92+
# {:list, _, [options]} <- List.last(params) |> dbg do
93+
# for {name, type} <- extract_options(options, []) do
94+
# %{
95+
# doc: "",
96+
# expanded_spec: "",
97+
# name: name |> Atom.to_string(),
98+
# origin: inspect(mod),
99+
# type: :param_option,
100+
# type_spec: Introspection.to_string_with_parens(type)
101+
# }
102+
# end
103+
# |> dbg
104+
# else
105+
# _ -> []
106+
# end
107+
# end
61108

62109
{:cont, %{acc | result: acc.result ++ list}}
63110
else
@@ -66,6 +113,20 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
66113
end
67114
end
68115

116+
defp extract_options({:|, _, [{atom, type}, rest]}, acc) when is_atom(atom) do
117+
extract_options(rest, [{atom, type} | acc])
118+
end
119+
120+
defp extract_options({:|, _, [_other, rest]}, acc) do
121+
extract_options(rest, acc)
122+
end
123+
124+
defp extract_options({atom, type}, acc) when is_atom(atom) do
125+
[{atom, type} | acc]
126+
end
127+
128+
defp extract_options(_other, acc), do: acc
129+
69130
defp options_to_suggestions(options, original_module) do
70131
Enum.map(options, fn
71132
{mod, name, type} ->

apps/language_server/test/providers/completion/suggestions_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,6 +4015,22 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.SuggestionTest do
40154015
atom(), node()}\
40164016
"""
40174017
end
4018+
4019+
test "metadata params" do
4020+
buffer = """
4021+
defmodule Foo do
4022+
@spec some([{:foo, integer()} | {:bar, String.t()}]) :: :ok
4023+
def some(options), do: :ok
4024+
4025+
def go do
4026+
some()
4027+
end
4028+
end
4029+
"""
4030+
4031+
list = Suggestion.suggestions(buffer, 6, 10)
4032+
assert [%{name: "remote_with_params_o"}] = list |> Enum.filter(&(&1.type == :param_option))
4033+
end
40184034
end
40194035

40204036
describe "suggestions for typespecs" do

0 commit comments

Comments
 (0)