@@ -6,89 +6,59 @@ defmodule NextLS.SignatureHelp do
6
6
alias GenLSP.Structures.ParameterInformation
7
7
alias GenLSP.Structures.SignatureHelp
8
8
alias GenLSP.Structures.SignatureInformation
9
- alias Sourceror.Zipper
9
+ alias NextLS.ASTHelpers
10
10
11
11
def fetch_mod_and_name ( uri , position ) do
12
12
with { :ok , text } <- File . read ( URI . parse ( uri ) . path ) ,
13
13
ast =
14
14
text
15
- |> Spitfire . parse ( )
15
+ |> Spitfire . parse ( literal_encoder: & { :ok , { :__literal__ , & 2 , [ & 1 ] } } )
16
16
|> then ( fn
17
17
{ :ok , ast } -> ast
18
18
{ :error , ast , _ } -> ast
19
19
end ) ,
20
- { :ok , result } <- find_node ( ast , position ) do
20
+ { :ok , result } <- ASTHelpers.Function . find_aliased_function_call_within ( ast , position ) do
21
21
case result do
22
22
{ { :. , _ , [ { :__aliases__ , _ , modules } , name ] } , _ , _ } -> { :ok , { Module . concat ( modules ) , name } }
23
23
end
24
24
end
25
25
end
26
26
27
- def format ( { :ok , { :docs_v1 , _ , :elixir , _ , _ , _ , docs } } , func_name ) do
28
- docs
29
- |> Enum . filter ( fn
30
- { { _ , name , _arity } , _ , _ , _ , _ } -> name == func_name
31
- end )
32
- |> Enum . map ( fn
33
- { { _ , _name , _arity } , _ , [ signature ] , _ , _ } ->
34
- params_info =
35
- signature
36
- |> Spitfire . parse! ( )
37
- |> then ( fn { _ , _ , args } ->
38
- Enum . map ( args , fn { name , _ , _ } -> name end )
39
- end )
40
- |> Enum . map ( fn name ->
27
+ def format ( { :ok , { :docs_v1 , _ , _lang , content_type , _ , _ , docs } } , func_name ) do
28
+ for { { _ , name , _arity } , _ , [ signature ] , fdoc , _ } <- docs , name == func_name do
29
+ params_info =
30
+ signature
31
+ |> Spitfire . parse! ( )
32
+ |> then ( fn { _ , _ , args } ->
33
+ Enum . map ( args , fn { name , _ , _ } ->
41
34
% ParameterInformation {
42
35
label: Atom . to_string ( name )
43
36
}
44
37
end )
38
+ end )
45
39
46
- % SignatureHelp {
47
- signatures: [
48
- % SignatureInformation {
49
- label: signature ,
50
- parameters: params_info ,
51
- documentation: % MarkupContent {
52
- kind: MarkupKind . markdown ( ) ,
53
- value: ""
54
- }
55
- }
56
- ]
57
- }
58
-
59
- # {{_, _name, _arity}, _, [], _, _} ->
60
- # []
61
-
62
- _otherwise ->
63
- [ ]
64
- end )
40
+ % SignatureHelp {
41
+ signatures: [
42
+ % SignatureInformation {
43
+ label: signature ,
44
+ parameters: params_info ,
45
+ documentation: maybe_doc ( content_type , fdoc )
46
+ }
47
+ ]
48
+ }
49
+ end
65
50
end
66
51
67
52
def format ( { :ok , { :error , :module_not_found } } , _func_name ) do
68
53
[ ]
69
54
end
70
55
71
- defp find_node ( ast , { line , column } ) do
72
- position = [ line: line , column: column ]
73
-
74
- result =
75
- ast
76
- |> Zipper . zip ( )
77
- |> Zipper . find ( fn
78
- { { :. , _ , _ } , _metadata , _ } = node ->
79
- range = Sourceror . get_range ( node )
80
-
81
- Sourceror . compare_positions ( range . start , position ) == :lt &&
82
- Sourceror . compare_positions ( range . end , position ) == :gt
83
-
84
- _ ->
85
- false
86
- end )
87
-
88
- if result do
89
- { :ok , Zipper . node ( result ) }
90
- else
91
- { :error , :not_found }
92
- end
56
+ defp maybe_doc ( content_type , % { "en" => fdoc } ) do
57
+ % MarkupContent {
58
+ kind: MarkupKind . markdown ( ) ,
59
+ value: NextLS.DocsHelpers . to_markdown ( content_type , fdoc )
60
+ }
93
61
end
62
+
63
+ defp maybe_doc ( _content_type , _fdoc ) , do: nil
94
64
end
0 commit comments