mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-07 13:34:55 +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
|
end
|
||||||
|
|
||||||
defp build_md(iodata, [{:ul, [{:class, "types"} | _], content} | ast]) do
|
defp build_md(iodata, [{:ul, [{:class, "types"} | _], content} | ast]) do
|
||||||
lines = Enum.map(content, fn {:li, _, line} -> line end)
|
render_types_list(content) |> append_block(iodata) |> build_md(ast)
|
||||||
render_code_block(lines, "erlang") |> append_block(iodata) |> build_md(ast)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_md(iodata, [{:ul, _, content} | ast]) do
|
defp build_md(iodata, [{:ul, _, content} | ast]) do
|
||||||
|
@ -735,4 +734,23 @@ defmodule Livebook.Intellisense do
|
||||||
end)
|
end)
|
||||||
|> render_unordered_list()
|
|> render_unordered_list()
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -68,6 +68,9 @@ defmodule Livebook.Intellisense.SignatureMatcher do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fix_erlang_signature(signature, specs) do
|
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
|
case parse_erlang_signature(signature) do
|
||||||
{:ok, fun, arity} ->
|
{:ok, fun, arity} ->
|
||||||
args =
|
args =
|
||||||
|
|
|
@ -1224,6 +1224,14 @@ defmodule Livebook.IntellisenseTest do
|
||||||
assert file_read =~ "Typical error reasons:"
|
assert file_read =~ "Typical error reasons:"
|
||||||
end
|
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
|
test "properly parses unicode" do
|
||||||
context = eval(do: nil)
|
context = eval(do: nil)
|
||||||
|
|
||||||
|
@ -1429,6 +1437,22 @@ defmodule Livebook.IntellisenseTest do
|
||||||
} = Intellisense.get_signature_items(":lists.map(", context)
|
} = Intellisense.get_signature_items(":lists.map(", context)
|
||||||
end
|
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
|
test "returns call active argument" do
|
||||||
context = eval(do: nil)
|
context = eval(do: nil)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue