Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suggestions when using typespecs returning a remote type #282

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/elixir_sense/core/binding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,13 @@ defmodule ElixirSense.Core.Binding do
expand_type(env, mod, atom, args, false)
end

# remote user type
defp parse_type(env, {{:., _, [{:__aliases__, _, aliases}, atom]}, _, args}, _mod, _include_private)
when is_atom(atom) do
# do not propagate include_private when expanding remote types
expand_type(env, Module.concat(aliases), atom, args, false)
end

# no_return
defp parse_type(_env, {:no_return, _, _}, _, _include_private), do: :none

Expand Down
18 changes: 18 additions & 0 deletions test/elixir_sense/suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3156,6 +3156,24 @@ defmodule ElixirSense.SuggestionsTest do
] = list
end

test "suggest struct fields when metadata function evaluates to remote type" do
buffer = """
defmodule Mod do
@spec fun() :: NaiveDateTime.t()
def fun(), do: NaiveDateTime.new(1, 2)

def some do
var = fun()
var.h
end
end
"""

list = ElixirSense.suggestions(buffer, 7, 10)

assert [%{name: "hour", origin: "NaiveDateTime"}] = list
end

test "suggest struct fields when variable is struct" do
buffer = """
defmodule Abc do
Expand Down
Loading