Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete with parens if there are remote calls #916

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
text_before_cursor: text_before_cursor,
text_after_cursor: text_after_cursor,
prefix: prefix,
remote_calls?: match?({:dot, _, _}, Code.Fragment.cursor_context(prefix)),
def_before: def_before,
pipe_before?: Regex.match?(Regex.recompile!(~r/\|>\s*#{prefix}$/), text_before_cursor),
capture_before?: Regex.match?(Regex.recompile!(~r/&#{prefix}$/), text_before_cursor),
Expand Down Expand Up @@ -1030,6 +1031,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
} = info

%{
remote_calls?: remote_calls?,
pipe_before?: pipe_before?,
capture_before?: capture_before?,
text_after_cursor: text_after_cursor
Expand All @@ -1038,7 +1040,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
locals_without_parens = Keyword.get(options, :locals_without_parens)
signature_help_supported? = Keyword.get(options, :signature_help_supported, false)
signature_after_complete? = Keyword.get(options, :signature_after_complete, true)
with_parens? = function_name_with_parens?(name, arity, locals_without_parens)
with_parens? = remote_calls? || function_name_with_parens?(name, arity, locals_without_parens)

trigger_signature? = signature_help_supported? && ((arity == 1 && !pipe_before?) || arity > 1)

Expand Down
19 changes: 19 additions & 0 deletions apps/language_server/test/providers/completion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,25 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
assert item["command"] == @signature_command
end

test "complete with parens if there are remote calls" do
text = """
defmodule MyModule do
def dummy_function() do
Map.drop
# ^
end
end
"""

{line, char} = {2, 12}
TestUtils.assert_has_cursor_char(text, line, char)

opts = Keyword.merge(@supports, locals_without_parens: MapSet.new(drop: 2))
{:ok, %{"items" => [item]}} = Completion.completion(text, line, char, opts)

assert item["insertText"] == "drop($1)$0"
end

test "function with arity 0 does not triggers signature" do
text = """
defmodule MyModule do
Expand Down
Loading