1
1
defmodule ElixirLS.LanguageServer.Fixtures.LspProtocol do
2
- def build ( type , opts \\ [ ] ) do
3
- true = Code . ensure_loaded? ( type )
2
+ def build ( module_to_build , opts \\ [ ] ) do
3
+ true = Code . ensure_loaded? ( module_to_build )
4
4
5
- if function_exported? ( type , :__meta__ , 1 ) do
6
- params = Map . take ( type . __meta__ ( :types ) , type . __meta__ ( :param_names ) )
5
+ if function_exported? ( module_to_build , :__meta__ , 1 ) do
6
+ protocol_module = ensure_protocol_module ( module_to_build )
7
+ params = Map . take ( protocol_module . __meta__ ( :types ) , protocol_module . __meta__ ( :param_names ) )
7
8
8
9
result =
9
10
Enum . reduce_while ( params , [ ] , fn { field_name , field_type } , acc ->
@@ -16,26 +17,26 @@ defmodule ElixirLS.LanguageServer.Fixtures.LspProtocol do
16
17
case result do
17
18
args when is_list ( args ) ->
18
19
args =
19
- case type . __meta__ ( :type ) do
20
+ case module_to_build . __meta__ ( :type ) do
20
21
{ :notification , _ } ->
21
- Keyword . put ( args , :method , type . __meta__ ( :method_name ) )
22
+ Keyword . put ( args , :method , module_to_build . __meta__ ( :method_name ) )
22
23
23
24
{ :request , _ } ->
24
25
args
25
26
|> Keyword . put ( :id , Keyword . get ( opts , :id , next_int ( ) ) )
26
- |> Keyword . put ( :method , type . __meta__ ( :method_name ) )
27
+ |> Keyword . put ( :method , module_to_build . __meta__ ( :method_name ) )
27
28
28
29
_ ->
29
30
args
30
31
end
31
32
32
- { :ok , type . new ( args ) }
33
+ { :ok , module_to_build . new ( args ) }
33
34
34
35
{ :error , _ } = err ->
35
36
err
36
37
end
37
38
else
38
- { :error , { :invalid_module , type } }
39
+ { :error , { :invalid_module , module_to_build } }
39
40
end
40
41
end
41
42
@@ -50,6 +51,19 @@ defmodule ElixirLS.LanguageServer.Fixtures.LspProtocol do
50
51
end
51
52
end
52
53
54
+ defp ensure_protocol_module ( module_to_build ) do
55
+ case module_to_build . __meta__ ( :type ) do
56
+ { message_type , :lsp } when message_type in [ :notification , :request ] ->
57
+ module_to_build
58
+
59
+ { message_type , :elixir } when message_type in [ :notification , :request ] ->
60
+ Module . concat ( module_to_build , LSP )
61
+
62
+ _ ->
63
+ module_to_build
64
+ end
65
+ end
66
+
53
67
defp maybe_wrap_with_json_rpc ( % proto_module { } = proto , opts ) do
54
68
proto_struct =
55
69
case proto_module . __meta__ ( :type ) do
0 commit comments