Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost callable completions that are not double underscore/default #195

Merged
merged 5 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Callable do

defp sort_text(%_{name: name, arity: arity}) do
normalized = String.replace(name, "__", "")
"#{normalized}/#{arity}"
fun = "#{normalized}/#{arity}"

if String.starts_with?(name, "__") or name in ["module_info"] do
fun
else
Env.boost(fun)
end
scottming marked this conversation as resolved.
Show resolved Hide resolved
end

defp label(%_{name: name, argument_names: argument_names}) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.FunctionTest d
[capture, args_capture] =
project
|> complete(source)
|> Enum.filter(&(&1.sort_text == "&is_map/1"))
|> Enum.filter(&String.ends_with?(&1.sort_text, "is_map/1"))

assert capture.detail == "(Capture)"
assert capture.insert_text == "is_map/1"
Expand Down Expand Up @@ -200,5 +200,33 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.FunctionTest d

assert completion.sort_text == "info/1"
end

test "dunder and default functions have lower completion priority", %{project: project} do
completions = complete(project, "GenServer.|")

defaults = ["module_info/0", "module_info/1"]

low_priority_completion? = fn fun ->
String.starts_with?(fun.label, "__") or fun.sort_text in defaults
end

{low_priority_completions, normal_completions} =
Enum.split_with(completions, low_priority_completion?)

for completion <- low_priority_completions do
refute boosted?(completion.sort_text)
end

for completion <- normal_completions do
assert boosted?(completion.sort_text)
end
end
end

@boost_characters ?!..?*

defp boosted?(sort_text) do
<<first_char, _::binary>> = sort_text
first_char in @boost_characters
end
end