Skip to content

Commit a8cbec2

Browse files
committed
cleanup
1 parent e409542 commit a8cbec2

File tree

2 files changed

+68
-85
lines changed

2 files changed

+68
-85
lines changed

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,14 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
745745
end
746746

747747
defp from_completion_item(%{type: :param_option} = suggestion, context, _options) do
748-
%{name: name, origin: _origin, doc: doc, type_spec: type_spec, expanded_spec: expanded_spec, subtype: subtype} =
748+
%{
749+
name: name,
750+
origin: _origin,
751+
doc: doc,
752+
type_spec: type_spec,
753+
expanded_spec: expanded_spec,
754+
subtype: subtype
755+
} =
749756
suggestion
750757

751758
formatted_spec =
@@ -755,26 +762,30 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
755762
""
756763
end
757764

758-
{insert_text, text_edit} = cond do
759-
subtype == :keyword and not String.ends_with?(context.prefix, ":") ->
760-
{"#{name}: ", nil}
761-
subtype == :keyword ->
762-
{"", %{
763-
"range" => %{
764-
"start" => %{
765-
"line" => context.line,
766-
"character" =>
767-
context.character - String.length(context.prefix)
768-
},
769-
"end" => %{"line" => context.line, "character" => context.character}
770-
},
771-
"newText" => "#{name}: "
772-
}}
773-
match?(":" <> _, context.prefix) ->
774-
{name, nil}
775-
true ->
776-
{":#{name}", nil}
777-
end
765+
{insert_text, text_edit} =
766+
cond do
767+
subtype == :keyword and not String.ends_with?(context.prefix, ":") ->
768+
{"#{name}: ", nil}
769+
770+
subtype == :keyword ->
771+
{"",
772+
%{
773+
"range" => %{
774+
"start" => %{
775+
"line" => context.line,
776+
"character" => context.character - String.length(context.prefix)
777+
},
778+
"end" => %{"line" => context.line, "character" => context.character}
779+
},
780+
"newText" => "#{name}: "
781+
}}
782+
783+
match?(":" <> _, context.prefix) ->
784+
{name, nil}
785+
786+
true ->
787+
{":#{name}", nil}
788+
end
778789

779790
%__MODULE__{
780791
label: to_string(name),

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

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
1111
alias ElixirSense.Core.Introspection
1212
alias ElixirSense.Core.Metadata
1313
alias ElixirSense.Core.Source
14-
alias ElixirSense.Core.TypeInfo
1514
alias ElixirLS.Utils.Matcher
1615

1716
@type param_option :: %{
@@ -51,75 +50,48 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
5150
cursor_context.cursor_position,
5251
not elixir_prefix
5352
) do
54-
list = for opt <- ElixirSense.Core.Options.get_param_options(mod, fun, npar + 1, env, buffer_metadata) do
55-
case opt do
56-
{name, type} ->
57-
# match on atom:
58-
if Matcher.match?(to_string(name) <> ":", hint) do
59-
expanded_spec = Introspection.to_string_with_parens(type)
60-
%{
61-
doc: "",
62-
expanded_spec: expanded_spec,
63-
name: name |> Atom.to_string(),
64-
origin: inspect(mod),
65-
type: :param_option,
66-
subtype: :keyword,
67-
type_spec: expanded_spec
68-
}
69-
end
70-
name ->
71-
# match on :atom
72-
if options_so_far == [] and cursor_at_option == true and Matcher.match?(inspect(name), hint) do
73-
%{
74-
doc: "",
75-
expanded_spec: "",
76-
name: name |> Atom.to_string(),
77-
origin: inspect(mod),
78-
type: :param_option,
79-
subtype: :atom,
80-
type_spec: ""
81-
}
82-
end
53+
list =
54+
for opt <-
55+
ElixirSense.Core.Options.get_param_options(mod, fun, npar + 1, env, buffer_metadata) do
56+
case opt do
57+
{name, type} ->
58+
# match on atom:
59+
if Matcher.match?(to_string(name) <> ":", hint) do
60+
expanded_spec = Introspection.to_string_with_parens(type)
61+
62+
%{
63+
doc: "",
64+
expanded_spec: expanded_spec,
65+
name: name |> Atom.to_string(),
66+
origin: inspect(mod),
67+
type: :param_option,
68+
subtype: :keyword,
69+
type_spec: expanded_spec
70+
}
71+
end
72+
73+
name ->
74+
# match on :atom
75+
if options_so_far == [] and cursor_at_option == true and
76+
Matcher.match?(inspect(name), hint) do
77+
%{
78+
doc: "",
79+
expanded_spec: "",
80+
name: name |> Atom.to_string(),
81+
origin: inspect(mod),
82+
type: :param_option,
83+
subtype: :atom,
84+
type_spec: ""
85+
}
86+
end
87+
end
8388
end
84-
end
85-
|> Enum.reject(&is_nil/1)
89+
|> Enum.reject(&is_nil/1)
8690

8791
{:cont, %{acc | result: acc.result ++ list}}
8892
else
8993
_ ->
9094
{:cont, acc}
9195
end
9296
end
93-
94-
defp extract_options({:|, _, [{atom, type}, rest]}, acc) when is_atom(atom) do
95-
extract_options(rest, [{atom, type} | acc])
96-
end
97-
98-
defp extract_options({:|, _, [_other, rest]}, acc) do
99-
extract_options(rest, acc)
100-
end
101-
102-
defp extract_options({atom, type}, acc) when is_atom(atom) do
103-
[{atom, type} | acc]
104-
end
105-
106-
defp extract_options(_other, acc), do: acc
107-
108-
defp options_to_suggestions(options, original_module) do
109-
Enum.map(options, fn
110-
{mod, name, type} ->
111-
TypeInfo.get_type_info(mod, type, original_module)
112-
|> Map.merge(%{type: :param_option, name: name |> Atom.to_string()})
113-
114-
{mod, name} ->
115-
%{
116-
doc: "",
117-
expanded_spec: "",
118-
name: name |> Atom.to_string(),
119-
origin: inspect(mod),
120-
type: :param_option,
121-
type_spec: ""
122-
}
123-
end)
124-
end
12597
end

0 commit comments

Comments
 (0)