Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Nov 27, 2023
1 parent 876f166 commit cb4ca6d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/elixir_sense/core/binding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,14 @@ defmodule ElixirSense.Core.Binding do
end

# remote user type
defp parse_type(env, {{:., _, [{:__aliases__, _, aliases}, atom]}, _, args}, _mod, _include_private)
defp parse_type(
env,
{{:., _, [{:__aliases__, _, aliases}, atom]}, _, args},
_mod,
_include_private
)
when is_atom(atom) do
dbg(aliases)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.12.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.12.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.12.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 25.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 25.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:1202: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check warning on line 1202 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / static analysis (Elixir 1.15.x | Erlang/OTP 26.x)

There should be no calls to dbg.
# do not propagate include_private when expanding remote types
expand_type(env, Module.concat(aliases), atom, args, false)
end
Expand Down
61 changes: 61 additions & 0 deletions test/elixir_sense/suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3191,6 +3191,67 @@ defmodule ElixirSense.SuggestionsTest do
assert [%{name: "hour", origin: "NaiveDateTime"}] = list
end

test "suggest struct fields when metadata function evaluates to remote type aliased" do
buffer = """
defmodule Mod do
alias NaiveDateTime, as: MyType
@spec fun() :: MyType.t()
def fun(), do: MyType.new(1, 2)
def some do
var = fun()
var.h
end
end
"""

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

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

test "suggest struct fields when metadata function evaluates to remote type __MODULE__" do
buffer = """
defmodule Mod do
@type t :: NaiveDateTime.t()
@spec fun() :: __MODULE__.t()
def fun(), do: nil
def some do
var = fun()
var.h
end
end
"""

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

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

test "suggest struct fields when metadata function evaluates to remote type __MODULE__.Submodule" do
buffer = """
defmodule Mod do
defmodule Sub do
@type t :: NaiveDateTime.t()
end
@spec fun() :: __MODULE__.Sub.t()
def fun(), do: nil
def some do
var = fun()
var.h
end
end
"""

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

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

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

0 comments on commit cb4ca6d

Please sign in to comment.