Display full module name in hover docs (#798)

* Display full module name in hover docs

* Use inspect

* Return atom names from identifier matcher
This commit is contained in:
Jonatan Kłosko 2021-12-12 21:34:16 +01:00 committed by GitHub
parent 4aa5447e9d
commit 877ab913c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 22 deletions

View file

@ -129,25 +129,25 @@ defmodule Livebook.Intellisense do
defp format_completion_item({:variable, name, _value}),
do: %{
label: name,
label: Atom.to_string(name),
kind: :variable,
detail: "variable",
documentation: nil,
insert_text: name
insert_text: Atom.to_string(name)
}
defp format_completion_item({:map_field, name, _value}),
do: %{
label: "#{name}",
label: Atom.to_string(name),
kind: :field,
detail: "field",
documentation: nil,
insert_text: "#{name}"
insert_text: Atom.to_string(name)
}
defp format_completion_item({:in_struct_field, struct, name, default}),
do: %{
label: "#{name}",
label: Atom.to_string(name),
kind: :field,
detail: "#{inspect(struct)} struct field",
documentation:
@ -228,16 +228,16 @@ defmodule Livebook.Intellisense do
kind: :type,
detail: "typespec",
documentation: format_documentation(documentation, :short),
insert_text: name
insert_text: Atom.to_string(name)
}
defp format_completion_item({:module_attribute, name, documentation}),
do: %{
label: name,
label: Atom.to_string(name),
kind: :variable,
detail: "module attribute",
documentation: format_documentation(documentation, :short),
insert_text: name
insert_text: Atom.to_string(name)
}
defp keyword_macro?(name) do
@ -372,9 +372,9 @@ defmodule Livebook.Intellisense do
])
end
defp format_details_item({:module, _module, display_name, documentation}) do
defp format_details_item({:module, module, _display_name, documentation}) do
join_with_divider([
code(display_name),
code(inspect(module)),
format_documentation(documentation, :all)
])
end
@ -398,7 +398,7 @@ defmodule Livebook.Intellisense do
defp format_details_item({:module_attribute, name, documentation}) do
join_with_divider([
code("@" <> name),
code("@#{name}"),
format_documentation(documentation, :all)
])
end
@ -433,19 +433,12 @@ defmodule Livebook.Intellisense do
# Don't add module prefix to operator signatures
if :binary.match(signatures_string, ["(", "/"]) != :nomatch do
module_to_prefix(module) <> signatures_string
inspect(module) <> "." <> signatures_string
else
signatures_string
end
end
defp module_to_prefix(mod) do
case Atom.to_string(mod) do
"Elixir." <> name -> name <> "."
name -> ":" <> name <> "."
end
end
defp format_specs([], _name, _line_length), do: nil
defp format_specs(specs, name, line_length) do

View file

@ -302,7 +302,7 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
is_atom(key),
name = Atom.to_string(key),
ctx.matcher.(name, hint),
do: {:variable, name, value}
do: {:variable, key, value}
end
defp match_map_field(map, hint, ctx) do
@ -512,7 +512,7 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
doc_item.name == name && doc_item.arity == arity
end)
{:type, mod, Atom.to_string(name), arity, doc_item.documentation}
{:type, mod, name, arity, doc_item.documentation}
end)
end
@ -555,7 +555,7 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
for {attribute, info} <- Module.reserved_attributes(),
name = Atom.to_string(attribute),
ctx.matcher.(name, hint),
do: {:module_attribute, name, {"text/markdown", info.doc}}
do: {:module_attribute, attribute, {"text/markdown", info.doc}}
end
# ---

View file

@ -1248,6 +1248,13 @@ defmodule Livebook.IntellisenseTest do
assert to_string_fn =~ "Converts the argument to a string"
end
test "includes full module name in the docs" do
{binding, env} = eval(do: nil)
assert %{contents: [date_range]} = Intellisense.get_details("Date.Range", 8, binding, env)
assert date_range =~ "Date.Range"
end
end
describe "get_signature_items/3" do