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

Use a runtime check for Macro.classify_atom/1 #294

Merged
merged 1 commit into from
Aug 3, 2024
Merged
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
25 changes: 12 additions & 13 deletions lib/elixir_sense/providers/completion/completion_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -850,19 +850,18 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do

## Helpers

# Version.match? is slow, we need to avoid it in a hot loop
if Version.match?(System.version(), ">= 1.14.0-dev") do
defp usable_as_unquoted_module?(name) do
# Conversion to atom is not a problem because
# it is only called with existing modules names.
# credo:disable-for-lines:7
Macro.classify_atom(String.to_atom(name)) in [:identifier, :unquoted] and
not String.starts_with?(name, "Elixir.")
end
else
defp usable_as_unquoted_module?(name) do
Code.Identifier.classify(String.to_atom(name)) != :other and
not String.starts_with?(name, "Elixir.")
defp usable_as_unquoted_module?(name) do
unquoted_atom_or_identifier?(String.to_atom(name)) and
not String.starts_with?(name, "Elixir.")
end

defp unquoted_atom_or_identifier?(atom) when is_atom(atom) do
# Macro.classify_atom/1 was introduced in 1.14.0. If it's not available,
# assume we're on an older version and fall back to a private API.
if function_exported?(Macro, :classify_atom, 1) do
apply(Macro, :classify_atom, [atom]) in [:identifier, :unquoted]
else
apply(Code.Identifier, :classify, [atom]) != :other
end
end

Expand Down
Loading