@@ -45,19 +45,66 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
45
45
env ,
46
46
mods_funs ,
47
47
metadata_types ,
48
- { 1 , 1 } ,
48
+ cursor_context . cursor_position ,
49
49
not elixir_prefix
50
50
) 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
61
108
62
109
{ :cont , % { acc | result: acc . result ++ list } }
63
110
else
@@ -66,6 +113,20 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
66
113
end
67
114
end
68
115
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
+
69
130
defp options_to_suggestions ( options , original_module ) do
70
131
Enum . map ( options , fn
71
132
{ mod , name , type } ->
0 commit comments