Skip to content

Commit

Permalink
Reimplement typespec expansion and keyword param provider (#298)
Browse files Browse the repository at this point in the history
* wip

* nest steps

* wip

* multiple specs and default args

* callbacks

* make callbacks params work

remove not needed drop_macro_env

* handle multiple matching defs

* drop not needed and broken typespec expansion code

* fix tests
  • Loading branch information
lukaszsamson authored Dec 10, 2024
1 parent 67f6974 commit 710b449
Show file tree
Hide file tree
Showing 11 changed files with 1,024 additions and 772 deletions.
22 changes: 4 additions & 18 deletions lib/elixir_sense/core/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ defmodule ElixirSense.Core.Introspection do
case get_callbacks_and_docs(mod) do
{callbacks, []} ->
Enum.map(callbacks, fn {{name, arity}, [spec | _]} ->
spec_ast =
Typespec.spec_to_quoted(name, spec)
|> Macro.prewalk(&drop_macro_env/1)
spec_ast = Typespec.spec_to_quoted(name, spec)

signature = get_typespec_signature(spec_ast, arity)
definition = format_spec_ast(spec_ast)
Expand Down Expand Up @@ -315,7 +313,6 @@ defmodule ElixirSense.Core.Introspection do
def format_spec_ast(spec_ast) do
parts =
spec_ast
|> Macro.prewalk(&drop_macro_env/1)
|> extract_spec_ast_parts

name_str = Macro.to_string(parts.name)
Expand Down Expand Up @@ -359,9 +356,7 @@ defmodule ElixirSense.Core.Introspection do

case found do
{{name, _}, [spec | _]} ->
ast =
Typespec.spec_to_quoted(name, spec)
|> Macro.prewalk(&drop_macro_env/1)
ast = Typespec.spec_to_quoted(name, spec)

get_returns_from_spec_ast(ast)

Expand Down Expand Up @@ -444,9 +439,7 @@ defmodule ElixirSense.Core.Introspection do
}

{_, [spec | _]} ->
spec_ast =
Typespec.spec_to_quoted(spec_name, spec)
|> Macro.prewalk(&drop_macro_env/1)
spec_ast = Typespec.spec_to_quoted(spec_name, spec)

spec_ast =
if kind == :macrocallback do
Expand Down Expand Up @@ -477,11 +470,6 @@ defmodule ElixirSense.Core.Introspection do
{callbacks, docs || []}
end

defp drop_macro_env({name, meta, [{:"::", _, [_, {{:., _, [Macro.Env, :t]}, _, _}]} | args]}),
do: {name, meta, args}

defp drop_macro_env(other), do: other

defp get_typespec_signature({:when, _, [{:"::", _, [{name, meta, args}, _]}, _]}, arity) do
to_string_with_parens({name, meta, strip_types(args, arity)})
end
Expand Down Expand Up @@ -787,9 +775,7 @@ defmodule ElixirSense.Core.Introspection do

specs
|> Enum.map_join("\n", fn spec ->
quoted =
Typespec.spec_to_quoted(name, spec)
|> Macro.prewalk(&drop_macro_env/1)
quoted = Typespec.spec_to_quoted(name, spec)

quoted =
if is_macro do
Expand Down
Loading

0 comments on commit 710b449

Please sign in to comment.