From 877ab913c8825b4696f87a0cbb04a3e35a14bb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Sun, 12 Dec 2021 21:34:16 +0100 Subject: [PATCH] Display full module name in hover docs (#798) * Display full module name in hover docs * Use inspect * Return atom names from identifier matcher --- lib/livebook/intellisense.ex | 31 +++++++------------ .../intellisense/identifier_matcher.ex | 6 ++-- test/livebook/intellisense_test.exs | 7 +++++ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/livebook/intellisense.ex b/lib/livebook/intellisense.ex index eb6857897..2e4af977d 100644 --- a/lib/livebook/intellisense.ex +++ b/lib/livebook/intellisense.ex @@ -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 diff --git a/lib/livebook/intellisense/identifier_matcher.ex b/lib/livebook/intellisense/identifier_matcher.ex index b10d58139..0fc9fe970 100644 --- a/lib/livebook/intellisense/identifier_matcher.ex +++ b/lib/livebook/intellisense/identifier_matcher.ex @@ -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 # --- diff --git a/test/livebook/intellisense_test.exs b/test/livebook/intellisense_test.exs index 8a334c7af..b3145a419 100644 --- a/test/livebook/intellisense_test.exs +++ b/test/livebook/intellisense_test.exs @@ -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