forked from lexical-lsp/lexical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest behavior callbacks (lexical-lsp#206)
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
apps/server/lib/lexical/server/code_intelligence/completion/translations/callback.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Callback do | ||
alias Lexical.RemoteControl.Completion.Result | ||
alias Lexical.Server.CodeIntelligence.Completion.Env | ||
alias Lexical.Server.CodeIntelligence.Completion.Translatable | ||
alias Lexical.Server.CodeIntelligence.Completion.Translations.Callable | ||
|
||
use Translatable.Impl, for: Result.Callback | ||
|
||
def translate(%Result.Callback{} = callback, _builder, %Env{} = env) do | ||
Callable.completion(callback, env) | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
apps/server/test/lexical/server/code_intelligence/completion/translations/callback_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule Lexical.Server.CodeIntelligence.Completion.Translations.CallbackTest do | ||
use Lexical.Test.Server.CompletionCase | ||
|
||
describe "callback completions" do | ||
test "suggest callbacks", %{project: project} do | ||
source = ~q[ | ||
defmodule MyServer do | ||
use GenServer | ||
def handle_inf| | ||
end | ||
] | ||
|
||
{:ok, completion} = | ||
project | ||
|> complete(source) | ||
|> fetch_completion(kind: :function) | ||
|
||
assert completion.insert_text == "handle_info(${1:msg}, ${2:state})" | ||
end | ||
|
||
test "do not add parens if they're already present", %{project: project} do | ||
source = ~q[ | ||
defmodule MyServer do | ||
use GenServer | ||
def handle_inf|(msg, state) | ||
end | ||
] | ||
|
||
{:ok, completion} = | ||
project | ||
|> complete(source) | ||
|> fetch_completion(kind: :function) | ||
|
||
assert completion.insert_text == "handle_info" | ||
end | ||
end | ||
end |