Skip to content

Commit fed32bf

Browse files
committed
fix from elixir_sense
1 parent 7062107 commit fed32bf

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

apps/elixir_ls_utils/lib/completion_engine.ex

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -856,19 +856,20 @@ defmodule ElixirLS.Utils.CompletionEngine do
856856

857857
## Helpers
858858

859-
# Version.match? is slow, we need to avoid it in a hot loop
860-
if Version.match?(System.version(), ">= 1.14.0-dev") do
861-
defp usable_as_unquoted_module?(name) do
862-
# Conversion to atom is not a problem because
863-
# it is only called with existing modules names.
864-
# credo:disable-for-lines:7
865-
Macro.classify_atom(String.to_atom(name)) in [:identifier, :unquoted] and
866-
not String.starts_with?(name, "Elixir.")
867-
end
868-
else
869-
defp usable_as_unquoted_module?(name) do
870-
Code.Identifier.classify(String.to_atom(name)) != :other and
871-
not String.starts_with?(name, "Elixir.")
859+
defp usable_as_unquoted_module?(name) do
860+
unquoted_atom_or_identifier?(String.to_atom(name)) and
861+
not String.starts_with?(name, "Elixir.")
862+
end
863+
864+
defp unquoted_atom_or_identifier?(atom) when is_atom(atom) do
865+
# Version.match? is slow, we need to avoid it in a hot loop
866+
# TODO remove this when we require elixir 1.14
867+
# Macro.classify_atom/1 was introduced in 1.14.0. If it's not available,
868+
# assume we're on an older version and fall back to a private API.
869+
if function_exported?(Macro, :classify_atom, 1) do
870+
apply(Macro, :classify_atom, [atom]) in [:identifier, :unquoted]
871+
else
872+
apply(Code.Identifier, :classify, [atom]) != :other
872873
end
873874
end
874875

0 commit comments

Comments
 (0)