Completion adjustments (#740)

* Show exceptions at the end of completion list

* Don't complete hidden functions
This commit is contained in:
Jonatan Kłosko 2021-12-03 23:28:34 +01:00 committed by GitHub
parent 18d8eccc9e
commit ab0a237ab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View file

@ -118,6 +118,12 @@ defmodule Livebook.Intellisense do
end
defp include_in_completion?({:module, _module, _display_name, :hidden}), do: false
defp include_in_completion?(
{:function, _module, _name, _arity, _display_name, :hidden, _signatures, _specs}
),
do: false
defp include_in_completion?(_), do: true
defp format_completion_item({:variable, name, value}),
@ -201,12 +207,16 @@ defmodule Livebook.Intellisense do
insert_text: name
}
@ordered_kinds [:field, :variable, :module, :struct, :interface, :function, :type]
defp completion_item_priority(%{kind: :struct, detail: "exception"} = completion_item) do
{length(@ordered_kinds), completion_item.label}
end
defp completion_item_priority(completion_item) do
{completion_item_kind_priority(completion_item.kind), completion_item.label}
end
@ordered_kinds [:field, :variable, :module, :struct, :interface, :function, :type]
defp completion_item_kind_priority(kind) when kind in @ordered_kinds do
Enum.find_index(@ordered_kinds, &(&1 == kind))
end

View file

@ -273,13 +273,6 @@ defmodule Livebook.IntellisenseTest do
{binding, env} = eval(do: nil)
assert [
%{
detail: "Livebook.TestModules.Hidden.hidden()",
documentation: "This is a private API",
insert_text: "hidden()",
kind: :function,
label: "hidden/0"
},
%{
detail: "Livebook.TestModules.Hidden.visible()",
documentation: "No documentation available",
@ -287,12 +280,7 @@ defmodule Livebook.IntellisenseTest do
kind: :function,
label: "visible/0"
}
] =
Intellisense.get_completion_items(
"Livebook.TestModules.Hidden.",
binding,
env
)
] = Intellisense.get_completion_items("Livebook.TestModules.Hidden.", binding, env)
end
test "Elixir root submodule completion" do