diff --git a/lib/elixir_sense/core/metadata_builder.ex b/lib/elixir_sense/core/metadata_builder.ex index 2ea8abf1..683bb6e4 100644 --- a/lib/elixir_sense/core/metadata_builder.ex +++ b/lib/elixir_sense/core/metadata_builder.ex @@ -733,37 +733,42 @@ defmodule ElixirSense.Core.MetadataBuilder do ) end - defp pre({:@, meta_attr, [{name, meta, params}]}, state) do - line = Keyword.fetch!(meta_attr, :line) - column = Keyword.fetch!(meta_attr, :column) + defp pre({:@, meta_attr, [{name, meta, params}]}, state) when is_atom(name) do + if String.match?(Atom.to_string(name), ~r/^[a-zA-Z_].*/) do + line = Keyword.fetch!(meta_attr, :line) + column = Keyword.fetch!(meta_attr, :column) - binding = - case List.wrap(params) do - [] -> - {nil, false} + binding = + case List.wrap(params) do + [] -> + {nil, false} - [param] -> - {get_binding_type(state, param), true} + [param] -> + {get_binding_type(state, param), true} - _ -> - :error - end + _ -> + :error + end - case binding do - {type, is_definition} -> - state = - add_moduledoc_positions( - state, - [line: line, column: column], - [{name, meta, params}], - line - ) + case binding do + {type, is_definition} -> + state = + add_moduledoc_positions( + state, + [line: line, column: column], + [{name, meta, params}], + line + ) - new_ast = {:@, meta_attr, [{name, add_no_call(meta), params}]} - pre_module_attribute(new_ast, state, {line, column}, name, type, is_definition) + new_ast = {:@, meta_attr, [{name, add_no_call(meta), params}]} + pre_module_attribute(new_ast, state, {line, column}, name, type, is_definition) - _ -> - {[], state} + _ -> + {[], state} + end + else + # most likely not an attribute + {[], state} end end diff --git a/test/elixir_sense/suggestions_test.exs b/test/elixir_sense/suggestions_test.exs index 70533225..4ba82522 100644 --- a/test/elixir_sense/suggestions_test.exs +++ b/test/elixir_sense/suggestions_test.exs @@ -1628,6 +1628,22 @@ defmodule ElixirSense.SuggestionsTest do assert Enum.any?(list, &(&1.name == "@spec")) end + test "do not suggest @@" do + buffer = """ + defmodule MyModule do + @ + @my_attribute1 true + end + """ + + list = + ElixirSense.suggestions(buffer, 2, 4) + |> Enum.filter(fn s -> s.type == :attribute end) + |> Enum.map(fn %{name: name} -> name end) + + refute "@@" in list + end + test "lists doc snippets in module body" do buffer = """ defmodule MyModule do