Skip to content

Commit 5ae6425

Browse files
authored
complete with parens if there are remote calls (#916)
* complete with parens if there are remote calls * move to context and using Code.Fragment.cursor_context/1
1 parent 58e2301 commit 5ae6425

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

apps/language_server/lib/language_server/providers/completion.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
138138
text_before_cursor: text_before_cursor,
139139
text_after_cursor: text_after_cursor,
140140
prefix: prefix,
141+
remote_calls?: match?({:dot, _, _}, Code.Fragment.cursor_context(prefix)),
141142
def_before: def_before,
142143
pipe_before?: Regex.match?(Regex.recompile!(~r/\|>\s*#{prefix}$/), text_before_cursor),
143144
capture_before?: Regex.match?(Regex.recompile!(~r/&#{prefix}$/), text_before_cursor),
@@ -1030,6 +1031,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
10301031
} = info
10311032

10321033
%{
1034+
remote_calls?: remote_calls?,
10331035
pipe_before?: pipe_before?,
10341036
capture_before?: capture_before?,
10351037
text_after_cursor: text_after_cursor
@@ -1038,7 +1040,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
10381040
locals_without_parens = Keyword.get(options, :locals_without_parens)
10391041
signature_help_supported? = Keyword.get(options, :signature_help_supported, false)
10401042
signature_after_complete? = Keyword.get(options, :signature_after_complete, true)
1041-
with_parens? = function_name_with_parens?(name, arity, locals_without_parens)
1043+
with_parens? = remote_calls? || function_name_with_parens?(name, arity, locals_without_parens)
10421044

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

apps/language_server/test/providers/completion_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,25 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
829829
assert item["command"] == @signature_command
830830
end
831831

832+
test "complete with parens if there are remote calls" do
833+
text = """
834+
defmodule MyModule do
835+
def dummy_function() do
836+
Map.drop
837+
# ^
838+
end
839+
end
840+
"""
841+
842+
{line, char} = {2, 12}
843+
TestUtils.assert_has_cursor_char(text, line, char)
844+
845+
opts = Keyword.merge(@supports, locals_without_parens: MapSet.new(drop: 2))
846+
{:ok, %{"items" => [item]}} = Completion.completion(text, line, char, opts)
847+
848+
assert item["insertText"] == "drop($1)$0"
849+
end
850+
832851
test "function with arity 0 does not triggers signature" do
833852
text = """
834853
defmodule MyModule do

0 commit comments

Comments
 (0)