Skip to content

Commit

Permalink
Handle @opaque types
Browse files Browse the repository at this point in the history
Shown without the internal definition
  • Loading branch information
awerment committed Jun 10, 2023
1 parent 5c1c328 commit c3a7afd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/livebook/intellisense.ex
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,21 @@ defmodule Livebook.Intellisense do
end
end

defp format_type_spec({type_kind, type}, line_length) do
defp format_type_spec({type_kind, type}, line_length) when type_kind in [:type, :opaque] do
type_string = Code.Typespec.type_to_quoted(type) |> Macro.to_string()

type =
case type_kind do
:type ->
type_string

:opaque ->
[name_and_vars, _def] = String.split(type_string, " :: ")
name_and_vars
end

type_spec_code =
["@#{type_kind} ", Code.Typespec.type_to_quoted(type) |> Macro.to_string()]
["@#{type_kind} ", type]
|> IO.iodata_to_binary()

try do
Expand All @@ -622,6 +634,8 @@ defmodule Livebook.Intellisense do
end
end

defp format_type_spec(_, _line_length), do: nil

defp format_documentation(doc, variant)

defp format_documentation(nil, _variant) do
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook/intellisense/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ defmodule Livebook.Intellisense.Docs do
type_specs =
with true <- :type in kinds,
{:ok, types} <- Code.Typespec.fetch_types(module) do
Enum.filter(types, fn {type_kind, _} -> :type == type_kind end)
Enum.filter(types, fn {type_kind, _} -> type_kind in [:type, :opaque] end)
|> Enum.map(fn {_type_kind, {name, _defs, vars}} = type ->
{{name, Enum.count(vars)}, type}
end)
Expand Down

0 comments on commit c3a7afd

Please sign in to comment.