Skip to content

Commit 6bcf66e

Browse files
committed
fix: fix autocompletion of use options
1 parent aae6ccb commit 6bcf66e

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

lib/spark/elixir_sense/plugin.ex

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ defmodule Spark.ElixirSense.Plugin do
362362
{ast, find_cursor_in_params(params, call, meta)}
363363
end
364364

365-
defp find_call_pre({atom, meta, params} = ast, _state)
366-
when is_atom(atom) and is_list(params) and atom not in [:{}, :%{}] do
367-
{ast, find_cursor_in_params(params, atom, meta)}
365+
# Special handling for use calls
366+
defp find_call_pre({:use, meta, [module_ast | params]} = ast, _state) do
367+
{ast, find_cursor_in_params([module_ast | params], [module_ast, :use], meta)}
368368
end
369369

370370
defp find_call_pre({atom, meta, params} = ast, _state)
@@ -587,29 +587,35 @@ defmodule Spark.ElixirSense.Plugin do
587587
defp cursor_at_value_type_path(_), do: nil
588588

589589
defp autocomplete_spark_options(hint, _, {module, function_call, arg_index, info}, opts) do
590-
case Code.fetch_docs(module) do
591-
{:docs_v1, _a, :elixir, _b, _c, _d, functions} ->
592-
schema =
593-
Enum.find_value(functions, fn
594-
{{_, ^function_call, _}, _, _, _, %{spark_opts: spark_opts}} ->
595-
Enum.find_value(spark_opts, fn {index, schema} ->
596-
if index == arg_index do
597-
schema
598-
end
599-
end)
590+
if (function_call == :use and arg_index > 0) && Code.ensure_loaded?(module) &&
591+
function_exported?(module, :opt_schema, 0) do
592+
schema = module.opt_schema()
593+
{:override, Enum.uniq(autocomplete_schema(schema, hint, info.value_type_path, opts))}
594+
else
595+
case Code.fetch_docs(module) do
596+
{:docs_v1, _a, :elixir, _b, _c, _d, functions} ->
597+
schema =
598+
Enum.find_value(functions, fn
599+
{{_, ^function_call, _}, _, _, _, %{spark_opts: spark_opts}} ->
600+
Enum.find_value(spark_opts, fn {index, schema} ->
601+
if index == arg_index do
602+
schema
603+
end
604+
end)
605+
606+
_ ->
607+
nil
608+
end)
600609

601-
_ ->
602-
nil
603-
end)
610+
if schema do
611+
{:override, Enum.uniq(autocomplete_schema(schema, hint, info.value_type_path, opts))}
612+
else
613+
:ignore
614+
end
604615

605-
if schema do
606-
{:override, Enum.uniq(autocomplete_schema(schema, hint, info.value_type_path, opts))}
607-
else
616+
_ ->
608617
:ignore
609-
end
610-
611-
_ ->
612-
:ignore
618+
end
613619
end
614620
end
615621

mix.exs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ defmodule Spark.MixProject do
111111
{:sobelow, ">= 0.0.0", only: [:dev, :test], runtime: false},
112112
{:git_ops, "~> 2.5", only: [:dev, :test]},
113113
{:mix_test_watch, "~> 1.0", only: [:dev, :test], runtime: false},
114-
{:elixir_sense,
115-
github: "zachdaniel/elixir_sense",
116-
only: [:dev, :test, :docs],
117-
ref: "572c81c4046e12857b734abc28aa14b7d1f6f595"},
114+
{:elixir_sense, github: "elixir-lsp/elixir_sense", only: [:dev, :test, :docs]},
118115
{:mix_audit, ">= 0.0.0", only: [:dev, :test], runtime: false}
119116
]
120117
end

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dialyxir": {:hex, :dialyxir, "1.4.6", "7cca478334bf8307e968664343cbdb432ee95b4b68a9cba95bdabb0ad5bdfd9a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "8cf5615c5cd4c2da6c501faae642839c8405b49f8aa057ad4ae401cb808ef64d"},
77
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
88
"eflame": {:hex, :eflame, "1.0.1", "0664d287e39eef3c413749254b3af5f4f8b00be71c1af67d325331c4890be0fc", [:mix], [], "hexpm", "e0b08854a66f9013129de0b008488f3411ae9b69b902187837f994d7a99cf04e"},
9-
"elixir_sense": {:git, "https://github.com/zachdaniel/elixir_sense.git", "572c81c4046e12857b734abc28aa14b7d1f6f595", [ref: "572c81c4046e12857b734abc28aa14b7d1f6f595"]},
9+
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "c1548354ed7fd50a381691e76aeab04756a9d6c7", []},
1010
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
1111
"ex_check": {:hex, :ex_check, "0.16.0", "07615bef493c5b8d12d5119de3914274277299c6483989e52b0f6b8358a26b5f", [:mix], [], "hexpm", "4d809b72a18d405514dda4809257d8e665ae7cf37a7aee3be6b74a34dec310f5"},
1212
"ex_doc": {:hex, :ex_doc, "0.38.3", "ddafe36b8e9fe101c093620879f6604f6254861a95133022101c08e75e6c759a", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "ecaa785456a67f63b4e7d7f200e8832fa108279e7eb73fd9928e7e66215a01f9"},

0 commit comments

Comments
 (0)