From 2a07798ed01e99012da2401e8ce4d1ce5e4539fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Mon, 25 Oct 2021 19:15:03 +0200 Subject: [PATCH] Don't show signatures on module attributes --- .../intellisense/signature_matcher.ex | 4 +++ test/livebook/intellisense_test.exs | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/livebook/intellisense/signature_matcher.ex b/lib/livebook/intellisense/signature_matcher.ex index fd4550e7004c..9623a31356ff 100644 --- a/lib/livebook/intellisense/signature_matcher.ex +++ b/lib/livebook/intellisense/signature_matcher.ex @@ -168,6 +168,10 @@ defmodule Livebook.Intellisense.SignatureMatcher do find_cursor_call(right, {nil, :pipe}) end + defp find_cursor_call({:@, _, [{attr, _, [arg]}]}, _acc) when is_atom(attr) do + find_cursor_call(arg, {nil, :none}) + end + defp find_cursor_call({left, _, right} = node, {_, pipe_info} = acc) when is_list(right) do if is_atom(left) and (Macro.operator?(left, length(right)) or diff --git a/test/livebook/intellisense_test.exs b/test/livebook/intellisense_test.exs index e4dc4592fb6f..7720d0df4550 100644 --- a/test/livebook/intellisense_test.exs +++ b/test/livebook/intellisense_test.exs @@ -1464,5 +1464,34 @@ defmodule Livebook.IntellisenseTest do ] } = Intellisense.get_signature_items("Enum.concat([1, 2], ", binding, env) end + + test "does not return any signatures for module attributes" do + {binding, env} = eval(do: nil) + + assert nil == Intellisense.get_signature_items("@length(", binding, env) + end + + test "does not returns signatures for calls in attribute value" do + {binding, env} = eval(do: nil) + + assert %{ + active_argument: 0, + signature_items: [ + %{ + arguments: ["list"], + documentation: """ + Returns the length of `list`. + + --- + + ``` + @spec length(list()) :: non_neg_integer() + ```\ + """, + signature: "length(list)" + } + ] + } = Intellisense.get_signature_items("@attr length(", binding, env) + end end end