@@ -349,15 +349,15 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
349
349
& ( "alias " <> & 1 )
350
350
)
351
351
352
- struct ( completion_without_additional_text_edit ,
352
+ % __MODULE__ { completion_without_additional_text_edit |
353
353
additional_text_edit: % TextEdit {
354
354
range: range ( line_to_insert_alias , 0 , line_to_insert_alias , 0 ) ,
355
355
newText: alias_edit
356
356
} ,
357
357
documentation: name <> "\n " <> summary ,
358
358
label_details: label_details ,
359
359
priority: 24
360
- )
360
+ }
361
361
end
362
362
363
363
defp from_completion_item (
@@ -673,6 +673,14 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
673
673
) ,
674
674
do: nil
675
675
676
+ # import with only or except was used and the completion would need to change it
677
+ # this is not trivial to implement and most likely not wanted so let's skip that
678
+ defp from_completion_item (
679
+ % { needed_import: needed_import } ,
680
+ _context ,
681
+ _options
682
+ ) when needed_import != nil , do: nil
683
+
676
684
defp from_completion_item (
677
685
% { name: name , origin: origin } = item ,
678
686
% { def_before: nil } = context ,
@@ -682,15 +690,39 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
682
690
683
691
completion =
684
692
if origin == "Kernel" || origin == "Kernel.SpecialForms" do
685
- % { completion | kind: :keyword , priority: 18 }
693
+ % __MODULE__ { completion | kind: :keyword , priority: 18 }
686
694
else
687
695
completion
688
696
end
689
697
698
+ completion = if item . needed_require do
699
+ { line_to_insert_require , column_to_insert_require } = context . position_to_insert_alias
700
+ indentation =
701
+ if column_to_insert_require >= 1 ,
702
+ do: 1 .. column_to_insert_require |> Enum . map_join ( fn _ -> " " end ) ,
703
+ else: ""
704
+ require_edit = indentation <> "require " <> item . needed_require <> "\n "
705
+ label_details =
706
+ Map . update! (
707
+ completion . label_details ,
708
+ "description" ,
709
+ & ( "require " <> & 1 )
710
+ )
711
+ % __MODULE__ { completion |
712
+ additional_text_edit: % TextEdit {
713
+ range: range ( line_to_insert_require , 0 , line_to_insert_require , 0 ) ,
714
+ newText: require_edit
715
+ } ,
716
+ label_details: label_details
717
+ }
718
+ else
719
+ completion
720
+ end
721
+
690
722
file_path = Keyword . get ( options , :file_path )
691
723
692
724
if snippet = snippet_for ( { origin , name } , Map . put ( context , :file_path , file_path ) ) do
693
- % { completion | insert_text: snippet , kind: :snippet , label: name }
725
+ % __MODULE__ { completion | insert_text: snippet , kind: :snippet , label: name }
694
726
else
695
727
completion
696
728
end
@@ -977,7 +1009,6 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
977
1009
defp function_completion ( info , context , options ) do
978
1010
% {
979
1011
type: type ,
980
- args: args ,
981
1012
args_list: args_list ,
982
1013
name: name ,
983
1014
summary: summary ,
@@ -986,15 +1017,10 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
986
1017
origin: origin ,
987
1018
metadata: metadata
988
1019
} = info
989
-
990
- # ElixirSense now returns types as an atom
991
- type = to_string ( type )
992
-
993
1020
% {
994
1021
pipe_before?: pipe_before? ,
995
1022
capture_before?: capture_before? ,
996
1023
text_after_cursor: text_after_cursor ,
997
- module: module
998
1024
} = context
999
1025
1000
1026
locals_without_parens = Keyword . get ( options , :locals_without_parens )
@@ -1036,15 +1062,6 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
1036
1062
{ label , insert_text }
1037
1063
end
1038
1064
1039
- detail_prefix =
1040
- if inspect ( module ) == origin do
1041
- "(#{ type } ) "
1042
- else
1043
- "(#{ type } ) #{ origin } ."
1044
- end
1045
-
1046
- detail = Enum . join ( [ detail_prefix , name , "(" , args , ")" ] )
1047
-
1048
1065
footer = SourceFile . format_spec ( spec , line_length: 30 )
1049
1066
1050
1067
command =
@@ -1058,7 +1075,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
1058
1075
% __MODULE__ {
1059
1076
label: label ,
1060
1077
kind: :function ,
1061
- detail: detail ,
1078
+ detail: to_string ( type ) ,
1062
1079
label_details: % {
1063
1080
"detail" => "(#{ Enum . join ( args_list , ", " ) } )" ,
1064
1081
"description" => "#{ origin } .#{ name } /#{ arity } "
0 commit comments