@@ -284,7 +284,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
284
284
% {
285
285
type: :callback ,
286
286
subtype: subtype ,
287
- args: args ,
287
+ args_list: args_list ,
288
288
name: name ,
289
289
summary: summary ,
290
290
arity: arity ,
@@ -308,7 +308,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
308
308
end
309
309
310
310
opts = Keyword . put ( options , :with_parens? , true )
311
- insert_text = def_snippet ( def_str , name , args , arity , opts )
311
+ insert_text = def_snippet ( def_str , name , args_list , arity , opts )
312
312
label = "#{ def_str } #{ name } /#{ arity } "
313
313
314
314
filter_text =
@@ -334,7 +334,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
334
334
defp from_completion_item (
335
335
% {
336
336
type: :protocol_function ,
337
- args: args ,
337
+ args_list: args_list ,
338
338
spec: _spec ,
339
339
name: name ,
340
340
summary: summary ,
@@ -349,7 +349,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
349
349
def_str = if ( context [ :def_before ] == nil , do: "def " )
350
350
351
351
opts = Keyword . put ( options , :with_parens? , true )
352
- insert_text = def_snippet ( def_str , name , args , arity , opts )
352
+ insert_text = def_snippet ( def_str , name , args_list , arity , opts )
353
353
label = "#{ def_str } #{ name } /#{ arity } "
354
354
355
355
% __MODULE__ {
@@ -501,7 +501,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
501
501
end
502
502
end
503
503
504
- defp function_snippet ( name , args , arity , opts ) do
504
+ def function_snippet ( name , args , arity , opts ) do
505
505
snippets_supported? = Keyword . get ( opts , :snippets_supported , false )
506
506
trigger_signature? = Keyword . get ( opts , :trigger_signature? , false )
507
507
capture_before? = Keyword . get ( opts , :capture_before? , false )
@@ -537,17 +537,15 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
537
537
end
538
538
end
539
539
540
- defp function_snippet_with_args ( name , arity , args , pipe_before? , with_parens? ) do
540
+ defp function_snippet_with_args ( name , arity , args_list , pipe_before? , with_parens? ) do
541
541
args_list =
542
- if args && args != "" do
543
- split_args_for_snippet ( args , arity )
544
- else
545
- for i <- Enum . slice ( 0 .. arity , 1 .. - 1 ) , do: "arg#{ i } "
546
- end
542
+ args_list
543
+ |> Enum . map ( & format_arg_for_snippet / 1 )
544
+ |> remove_unused_default_args ( arity )
547
545
548
546
args_list =
549
547
if pipe_before? do
550
- Enum . slice ( args_list , 1 .. - 1 )
548
+ tl ( args_list )
551
549
else
552
550
args_list
553
551
end
@@ -651,13 +649,11 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
651
649
end
652
650
end
653
651
654
- defp split_args_for_snippet ( args , arity ) do
655
- args
652
+ defp format_arg_for_snippet ( arg ) do
653
+ arg
656
654
|> String . replace ( "\\ " , "\\ \\ " )
657
655
|> String . replace ( "$" , "\\ $" )
658
656
|> String . replace ( "}" , "\\ }" )
659
- |> String . split ( "," )
660
- |> remove_unused_default_args ( arity )
661
657
end
662
658
663
659
defp remove_unused_default_args ( args , arity ) do
@@ -684,6 +680,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
684
680
% {
685
681
type: type ,
686
682
args: args ,
683
+ args_list: args_list ,
687
684
name: name ,
688
685
summary: summary ,
689
686
arity: arity ,
@@ -725,13 +722,12 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
725
722
insert_text =
726
723
function_snippet (
727
724
name ,
728
- args ,
725
+ args_list ,
729
726
arity ,
730
727
Keyword . merge (
731
728
options ,
732
729
pipe_before?: pipe_before? ,
733
730
capture_before?: capture_before? ,
734
- pipe_before?: pipe_before? ,
735
731
trigger_signature?: trigger_signature? ,
736
732
locals_without_parens: locals_without_parens ,
737
733
text_after_cursor: text_after_cursor ,
0 commit comments