@@ -2,92 +2,15 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Function do
2
2
alias Lexical.RemoteControl.Completion.Result
3
3
alias Lexical.Server.CodeIntelligence.Completion.Env
4
4
alias Lexical.Server.CodeIntelligence.Completion.Translatable
5
+ alias Lexical.Server.CodeIntelligence.Completion.Translations.Callable
5
6
6
7
use Translatable.Impl , for: Result.Function
7
8
8
9
def translate ( % Result.Function { } = function , _builder , % Env { } = env ) do
9
10
if Env . function_capture? ( env ) do
10
- function_capture_completions ( function , env )
11
+ Callable . capture_completions ( function , env )
11
12
else
12
- function_call_completion ( function , env )
13
+ Callable . completion ( function , env )
13
14
end
14
15
end
15
-
16
- defp function_capture_completions ( % Result.Function { } = function , % Env { } = env ) do
17
- name_and_arity = name_and_arity ( function )
18
-
19
- complete_capture =
20
- Env . plain_text ( env , name_and_arity ,
21
- detail: "(Capture)" ,
22
- kind: :function ,
23
- label: name_and_arity ,
24
- sort_text: "&" <> sort_text ( function )
25
- )
26
-
27
- call_capture =
28
- Env . snippet ( env , function_snippet ( function , env ) ,
29
- detail: "(Capture with arguments)" ,
30
- kind: :function ,
31
- label: function_label ( function ) ,
32
- sort_text: "&" <> sort_text ( function )
33
- )
34
-
35
- [ complete_capture , call_capture ]
36
- end
37
-
38
- defp function_call_completion ( % Result.Function { } = function , % Env { } = env ) do
39
- add_args? = not String . contains? ( env . suffix , "(" )
40
-
41
- insert_text =
42
- if add_args? do
43
- function_snippet ( function , env )
44
- else
45
- function . name
46
- end
47
-
48
- tags =
49
- if Map . get ( function . metadata , :deprecated ) do
50
- [ :deprecated ]
51
- end
52
-
53
- Env . snippet ( env , insert_text ,
54
- kind: :function ,
55
- label: function_label ( function ) ,
56
- sort_text: sort_text ( function ) ,
57
- tags: tags
58
- )
59
- end
60
-
61
- defp function_snippet ( % Result.Function { } = function , % Env { } = env ) do
62
- argument_names =
63
- if Env . pipe? ( env ) do
64
- tl ( function . argument_names )
65
- else
66
- function . argument_names
67
- end
68
-
69
- argument_templates =
70
- argument_names
71
- |> Enum . with_index ( )
72
- |> Enum . map_join ( ", " , fn { name , index } ->
73
- escaped_name = String . replace ( name , "\\ " , "\\ \\ " )
74
- "${#{ index + 1 } :#{ escaped_name } }"
75
- end )
76
-
77
- "#{ function . name } (#{ argument_templates } )"
78
- end
79
-
80
- defp sort_text ( % Result.Function { } = function ) do
81
- normalized = String . replace ( function . name , "__" , "" )
82
- "#{ normalized } /#{ function . arity } "
83
- end
84
-
85
- defp function_label ( % Result.Function { } = function ) do
86
- arg_detail = Enum . join ( function . argument_names , ", " )
87
- "#{ function . name } (#{ arg_detail } )"
88
- end
89
-
90
- defp name_and_arity ( % Result.Function { } = function ) do
91
- "#{ function . name } /#{ function . arity } "
92
- end
93
16
end
0 commit comments