mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-04 20:14:57 +08:00
Fix signature completion and signature types in older Erlang docs (#1318)
This commit is contained in:
parent
fece6f49f2
commit
36ce11c211
3 changed files with 47 additions and 2 deletions
|
@ -625,8 +625,7 @@ defmodule Livebook.Intellisense do
|
|||
end
|
||||
|
||||
defp build_md(iodata, [{:ul, [{:class, "types"} | _], content} | ast]) do
|
||||
lines = Enum.map(content, fn {:li, _, line} -> line end)
|
||||
render_code_block(lines, "erlang") |> append_block(iodata) |> build_md(ast)
|
||||
render_types_list(content) |> append_block(iodata) |> build_md(ast)
|
||||
end
|
||||
|
||||
defp build_md(iodata, [{:ul, _, content} | ast]) do
|
||||
|
@ -735,4 +734,23 @@ defmodule Livebook.Intellisense do
|
|||
end)
|
||||
|> render_unordered_list()
|
||||
end
|
||||
|
||||
defp render_types_list(content) do
|
||||
content
|
||||
|> group_type_list_items([])
|
||||
|> render_unordered_list()
|
||||
end
|
||||
|
||||
defp group_type_list_items([], acc), do: Enum.reverse(acc)
|
||||
|
||||
defp group_type_list_items([{:li, [{:class, "type"}], content} | items], acc) do
|
||||
group_type_list_items(items, [{:li, [], [{:code, [], content}]} | acc])
|
||||
end
|
||||
|
||||
defp group_type_list_items(
|
||||
[{:li, [{:class, "description"}], content} | items],
|
||||
[{:li, [], prev_content} | acc]
|
||||
) do
|
||||
group_type_list_items(items, [{:li, [], prev_content ++ [{:p, [], content}]} | acc])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,6 +68,9 @@ defmodule Livebook.Intellisense.SignatureMatcher do
|
|||
end
|
||||
|
||||
defp fix_erlang_signature(signature, specs) do
|
||||
# Erlang signatures may include "->" followed by return type
|
||||
signature = signature |> String.split("->") |> hd() |> String.trim()
|
||||
|
||||
case parse_erlang_signature(signature) do
|
||||
{:ok, fun, arity} ->
|
||||
args =
|
||||
|
|
|
@ -1224,6 +1224,14 @@ defmodule Livebook.IntellisenseTest do
|
|||
assert file_read =~ "Typical error reasons:"
|
||||
end
|
||||
|
||||
@tag :erl_docs
|
||||
test "properly renders Erlang signature types list" do
|
||||
context = eval(do: nil)
|
||||
|
||||
assert %{contents: [file_read]} = Intellisense.get_details(":odbc.connect()", 8, context)
|
||||
assert file_read =~ "Ref = connection_reference()"
|
||||
end
|
||||
|
||||
test "properly parses unicode" do
|
||||
context = eval(do: nil)
|
||||
|
||||
|
@ -1429,6 +1437,22 @@ defmodule Livebook.IntellisenseTest do
|
|||
} = Intellisense.get_signature_items(":lists.map(", context)
|
||||
end
|
||||
|
||||
@tag :erl_docs
|
||||
test "shows signature with arguments for erlang modules with arrow signature" do
|
||||
context = eval(do: nil)
|
||||
|
||||
assert %{
|
||||
active_argument: 0,
|
||||
signature_items: [
|
||||
%{
|
||||
signature: "connect(ConnectStr, Options)",
|
||||
arguments: ["ConnectStr", "Options"],
|
||||
documentation: _connect_doc
|
||||
}
|
||||
]
|
||||
} = Intellisense.get_signature_items(":odbc.connect(", context)
|
||||
end
|
||||
|
||||
test "returns call active argument" do
|
||||
context = eval(do: nil)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue