Skip to content

Commit

Permalink
Merge pull request #840 from lexical-lsp/issue-832
Browse files Browse the repository at this point in the history
Show syntax macro completions when `Kernel.` is prefixed to the cursor.
  • Loading branch information
Moosieus authored Nov 22, 2024
2 parents 6b245c2 + a75bf2f commit bc36cc4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Callable do

@syntax_macros ~w(= == == === =~ .. ..// ! != !== &&)

def completion(%_callable_module{name: name}, _env)
def completion(%_callable_module{name: name} = callable, %Env{} = env)
when name in @syntax_macros do
:skip
if String.ends_with?(env.prefix, "Kernel.") do
do_completion(callable, env)
else
:skip
end
end

def completion(%callable_module{arity: 0} = callable, %Env{} = env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,23 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.MacroTest do
inside_exunit_context("describe \"${1:message}\" do\n $0\nend")
end

test "syntax macros", %{project: project} do
assert [] = complete(project, "a =|")
assert [] = complete(project, "a ==|")
assert [] = complete(project, "a ..|")
assert [] = complete(project, "a !|")
assert [] = complete(project, "a !=|")
assert [] = complete(project, "a !==|")
assert [] = complete(project, "a &&|")
describe "syntax macros" do
test "completions are skipped for syntax macros", %{project: project} do
assert [] = complete(project, "a =|")
assert [] = complete(project, "a ==|")
assert [] = complete(project, "a ..|")
assert [] = complete(project, "a !|")
assert [] = complete(project, "a !=|")
assert [] = complete(project, "a !==|")
assert [] = complete(project, "a &&|")
end

test "completions are shown for syntax macros when `Kernel.|` is prefixed.", %{
project: project
} do
completions = complete(project, ":some_expression && Kernel.|")
assert length(completions) > 0
end
end

defp inside_exunit_context(text) do
Expand Down

0 comments on commit bc36cc4

Please sign in to comment.