Skip to content

Commit

Permalink
do not complete @@
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Jul 7, 2023
1 parent b134c70 commit 3aea5e2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
55 changes: 30 additions & 25 deletions lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions test/elixir_sense/suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3aea5e2

Please sign in to comment.