From 4e625ba84f817968f64ed6b31760aaddf987a4cb Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 14 Oct 2023 14:54:25 +0200 Subject: [PATCH] Add OTP 25 and 25 builtin types Fixes https://github.com/elixir-lsp/elixir_sense/issues/212 Fixes https://github.com/elixir-lsp/elixir_sense/issues/190 --- lib/elixir_sense/core/builtin_types.ex | 34 +++++++++++++++++--------- test/elixir_sense/docs_test.exs | 4 +-- test/elixir_sense/suggestions_test.exs | 6 ++--- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/elixir_sense/core/builtin_types.ex b/lib/elixir_sense/core/builtin_types.ex index e312763d..faea9966 100644 --- a/lib/elixir_sense/core/builtin_types.ex +++ b/lib/elixir_sense/core/builtin_types.ex @@ -10,6 +10,10 @@ defmodule ElixirSense.Core.BuiltinTypes do params: [], doc: "The bottom type, contains no terms" }, + "dynamic" => %{ + params: [], + doc: "A type compatible with every type" + }, "atom" => %{ params: [], doc: @@ -32,10 +36,6 @@ defmodule ElixirSense.Core.BuiltinTypes do doc: "A reference is a term that is unique in an Erlang runtime system, created by calling `make_ref/0`" }, - "struct" => %{ - params: [], - doc: "Any struct" - }, "tuple" => %{ params: [], doc: "Tuple of any size" @@ -63,22 +63,22 @@ defmodule ElixirSense.Core.BuiltinTypes do "list/1" => %{ params: [:t], doc: "Proper list ([]-terminated)", - signature: "list(t)" + signature: "list(t())" }, "nonempty_list/1" => %{ params: [:t], doc: "Non-empty proper list", - signature: "nonempty_list(t)" + signature: "nonempty_list(t())" }, "maybe_improper_list/2" => %{ params: [:type1, :type2], doc: "Proper or improper list (type1=contents, type2=termination)", - signature: "maybe_improper_list(type1, type2)" + signature: "maybe_improper_list(type1(), type2())" }, "nonempty_improper_list/2" => %{ params: [:type1, :type2], doc: "Improper list (type1=contents, type2=termination)", - signature: "nonempty_improper_list(type1, type2)" + signature: "nonempty_improper_list(type1(), type2())" }, "nonempty_maybe_improper_list/2" => %{ params: [:type1, :type2], @@ -105,14 +105,24 @@ defmodule ElixirSense.Core.BuiltinTypes do }, "binary" => %{ params: [], - spec: quote(do: binary() :: <<_::size(8)>>), + spec: quote(do: binary() :: <<_::_*8>>), doc: "A blob of binary data" }, + "nonempty_binary" => %{ + params: [], + spec: quote(do: nonempty_binary() :: <<_::8, _::_*8>>), + doc: "A `binary()` that contains some data" + }, "bitstring" => %{ params: [], - spec: quote(do: bitstring() :: <<_::size(1)>>), + spec: quote(do: bitstring() :: <<_::_*1>>), doc: "A bunch of bits" }, + "nonempty_bitstring" => %{ + params: [], + spec: quote(do: nonempty_bitstring() :: <<_::1, _::_*1>>), + doc: "A `bitstring()` that contains some data" + }, "boolean" => %{ params: [], spec: quote(do: boolean() :: false | true), @@ -140,7 +150,7 @@ defmodule ElixirSense.Core.BuiltinTypes do }, "fun" => %{ params: [], - spec: quote(do: fun() :: (... -> any)), + spec: quote(do: fun() :: (... -> any())), doc: "A function" }, "function" => %{ @@ -171,7 +181,7 @@ defmodule ElixirSense.Core.BuiltinTypes do }, "keyword/1" => %{ params: [:t], - spec: quote(do: keyword(t) :: [{atom(), t}]), + spec: quote(do: keyword(t()) :: [{atom(), t()}]), doc: "A keyword list with values of type `t`" }, "list" => %{ diff --git a/test/elixir_sense/docs_test.exs b/test/elixir_sense/docs_test.exs index d24ac464..b1d0a02c 100644 --- a/test/elixir_sense/docs_test.exs +++ b/test/elixir_sense/docs_test.exs @@ -1664,7 +1664,7 @@ defmodule ElixirSense.DocsTest do arity: 1, module: nil, metadata: %{builtin: true}, - spec: "@type keyword(t) :: [{atom(), t}]", + spec: "@type keyword(t()) :: [{atom(), t()}]", docs: "A keyword list with values of type `t`", kind: :type } @@ -1728,7 +1728,7 @@ defmodule ElixirSense.DocsTest do type: :list, arity: 1, module: nil, - spec: "@type list(t)", + spec: "@type list(t())", metadata: %{builtin: true}, docs: "Proper list ([]-terminated)", kind: :type diff --git a/test/elixir_sense/suggestions_test.exs b/test/elixir_sense/suggestions_test.exs index a33da46a..a2a5f2e8 100644 --- a/test/elixir_sense/suggestions_test.exs +++ b/test/elixir_sense/suggestions_test.exs @@ -3454,7 +3454,7 @@ defmodule ElixirSense.SuggestionsTest do assert suggestion.type_spec == "keyword(term())" assert suggestion.origin == "" - assert suggestion.expanded_spec =~ "@type keyword(t) ::" + assert suggestion.expanded_spec =~ "@type keyword(t()) ::" assert suggestion.doc == "A keyword list with values of type `t`" end @@ -3835,8 +3835,8 @@ defmodule ElixirSense.SuggestionsTest do [_, suggestion | _] = suggestions_by_type(:type_spec, buffer) - assert suggestion.spec == "@type list(t)" - assert suggestion.signature == "list(t)" + assert suggestion.spec == "@type list(t())" + assert suggestion.signature == "list(t())" assert suggestion.arity == 1 assert suggestion.doc == "Proper list ([]-terminated)" assert suggestion.origin == nil