mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-08 20:46:16 +08:00
Show more details in type completion items (#1975)
This commit is contained in:
parent
7691324a4e
commit
b4e4c64820
3 changed files with 71 additions and 20 deletions
|
@ -254,16 +254,26 @@ defmodule Livebook.Intellisense do
|
||||||
|
|
||||||
defp format_completion_item(%{
|
defp format_completion_item(%{
|
||||||
kind: :type,
|
kind: :type,
|
||||||
|
module: module,
|
||||||
name: name,
|
name: name,
|
||||||
arity: arity,
|
arity: arity,
|
||||||
documentation: documentation
|
documentation: documentation,
|
||||||
|
type_spec: type_spec
|
||||||
}),
|
}),
|
||||||
do: %{
|
do: %{
|
||||||
label: "#{name}/#{arity}",
|
label: "#{name}/#{arity}",
|
||||||
kind: :type,
|
kind: :type,
|
||||||
detail: "typespec",
|
detail: format_type_signature(type_spec, module),
|
||||||
documentation: format_documentation(documentation, :short),
|
documentation:
|
||||||
insert_text: Atom.to_string(name)
|
join_with_newlines([
|
||||||
|
format_documentation(documentation, :short),
|
||||||
|
format_type_spec(type_spec, @line_length) |> code()
|
||||||
|
]),
|
||||||
|
insert_text:
|
||||||
|
cond do
|
||||||
|
arity == 0 -> "#{Atom.to_string(name)}()"
|
||||||
|
true -> "#{Atom.to_string(name)}($0)"
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
defp format_completion_item(%{kind: :module_attribute, name: name, documentation: documentation}),
|
defp format_completion_item(%{kind: :module_attribute, name: name, documentation: documentation}),
|
||||||
|
|
|
@ -53,7 +53,8 @@ defmodule Livebook.Intellisense.SignatureMatcher do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp signature_infos_for_members(mod, funs, active_argument) do
|
defp signature_infos_for_members(mod, funs, active_argument) do
|
||||||
infos = Livebook.Intellisense.Docs.lookup_module_members(mod, funs, kind: [:function, :macro])
|
infos =
|
||||||
|
Livebook.Intellisense.Docs.lookup_module_members(mod, funs, kinds: [:function, :macro])
|
||||||
|
|
||||||
for info <- infos,
|
for info <- infos,
|
||||||
info.arity >= active_argument + 1 do
|
info.arity >= active_argument + 1 do
|
||||||
|
|
|
@ -142,6 +142,41 @@ defmodule Livebook.IntellisenseTest do
|
||||||
] = Intellisense.get_completion_items(":erlang.open_por", context)
|
] = Intellisense.get_completion_items(":erlang.open_por", context)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@tag :erl_docs
|
||||||
|
test "Erlang type completion" do
|
||||||
|
context = eval(do: nil)
|
||||||
|
|
||||||
|
items = Intellisense.get_completion_items(":maps.iterator", context)
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
label: "iterator/0",
|
||||||
|
kind: :type,
|
||||||
|
detail: ":maps.iterator()",
|
||||||
|
documentation: """
|
||||||
|
No documentation available
|
||||||
|
|
||||||
|
```
|
||||||
|
@type iterator() :: iterator(term(), term())
|
||||||
|
```\
|
||||||
|
""",
|
||||||
|
insert_text: "iterator()"
|
||||||
|
} in items
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
label: "iterator/2",
|
||||||
|
kind: :type,
|
||||||
|
detail: ":maps.iterator(key, value)",
|
||||||
|
documentation: """
|
||||||
|
An iterator representing the associations in a map with keys of type `Key` and values of type `Value`.
|
||||||
|
|
||||||
|
```
|
||||||
|
@opaque iterator(key, value)
|
||||||
|
```\
|
||||||
|
""",
|
||||||
|
insert_text: "iterator($0)"
|
||||||
|
} in items
|
||||||
|
end
|
||||||
|
|
||||||
test "Elixir proxy" do
|
test "Elixir proxy" do
|
||||||
context = eval(do: nil)
|
context = eval(do: nil)
|
||||||
|
|
||||||
|
@ -214,28 +249,33 @@ defmodule Livebook.IntellisenseTest do
|
||||||
%{
|
%{
|
||||||
label: "from/0",
|
label: "from/0",
|
||||||
kind: :type,
|
kind: :type,
|
||||||
detail: "typespec",
|
detail: "GenServer.from()",
|
||||||
documentation: "Tuple describing the client of a call request.",
|
documentation: """
|
||||||
insert_text: "from"
|
Tuple describing the client of a call request.
|
||||||
|
|
||||||
|
```
|
||||||
|
@type from() :: {pid(), tag :: term()}
|
||||||
|
```\
|
||||||
|
""",
|
||||||
|
insert_text: "from()"
|
||||||
}
|
}
|
||||||
] = Intellisense.get_completion_items("GenServer.fr", context)
|
] = Intellisense.get_completion_items("GenServer.fr", context)
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
%{
|
%{
|
||||||
label: "name/0",
|
label: "internal/1",
|
||||||
kind: :type,
|
kind: :type,
|
||||||
detail: "typespec",
|
detail: "MapSet.internal(value)",
|
||||||
documentation: _name_doc,
|
documentation: """
|
||||||
insert_text: "name"
|
No documentation available
|
||||||
},
|
|
||||||
%{
|
```
|
||||||
label: "name_all/0",
|
@opaque internal(value)
|
||||||
kind: :type,
|
```\
|
||||||
detail: "typespec",
|
""",
|
||||||
documentation: _name_all_doc,
|
insert_text: "internal($0)"
|
||||||
insert_text: "name_all"
|
|
||||||
}
|
}
|
||||||
] = Intellisense.get_completion_items(":file.nam", context)
|
] = Intellisense.get_completion_items("MapSet.intern", context)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Elixir module completion with self" do
|
test "Elixir module completion with self" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue