diff --git a/apps/server/lib/lexical/server/code_intelligence/completion/translations/macro.ex b/apps/server/lib/lexical/server/code_intelligence/completion/translations/macro.ex index f962c5ed7..cf8ae36db 100644 --- a/apps/server/lib/lexical/server/code_intelligence/completion/translations/macro.ex +++ b/apps/server/lib/lexical/server/code_intelligence/completion/translations/macro.ex @@ -7,7 +7,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do use Translatable.Impl, for: Candidate.Macro - @snippet_macros ~w(def defp defmacro defmacrop defimpl defmodule defprotocol defguard defguardp defexception test) + @snippet_macros ~w(def defp defmacro defmacrop defimpl defmodule defprotocol defguard defguardp defexception test use) def translate(%Candidate.Macro{name: name}, _builder, _env) when name in ["__before_compile__", "__using__", "__after_compile__"] do @@ -248,6 +248,18 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do |> builder.boost() end + def translate(%Candidate.Macro{name: "use", arity: 1}, builder, env) do + label = "use (invoke another module's __using__ macro)" + snippet = "use $0" + + env + |> builder.snippet(snippet, + kind: :class, + label: label + ) + |> builder.boost() + end + def translate(%Candidate.Macro{name: "require" <> _, arity: 2} = macro, builder, env) do label = "#{macro.name} (require a module's macros)" diff --git a/apps/server/test/lexical/server/code_intelligence/completion/translations/macro_test.exs b/apps/server/test/lexical/server/code_intelligence/completion/translations/macro_test.exs index f5e9f46c9..b1ee0f0c1 100644 --- a/apps/server/test/lexical/server/code_intelligence/completion/translations/macro_test.exs +++ b/apps/server/test/lexical/server/code_intelligence/completion/translations/macro_test.exs @@ -277,6 +277,17 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.MacroTest do assert completion.insert_text == "alias $0" end + test "use returns a snippet", %{project: project} do + assert {:ok, completion} = + project + |> complete("us|") + |> fetch_completion("use ") + + assert completion.label == "use (invoke another module's __using__ macro)" + assert completion.insert_text_format == :snippet + assert completion.insert_text == "use $0" + end + test "import returns a snippet", %{project: project} do assert {:ok, completion} = project