Skip to content

Commit f8b537a

Browse files
committed
Ensured that you can build a request with the elixir module
1 parent cd4fd33 commit f8b537a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

apps/language_server/test/support/fixtures/lsp_protocol.ex

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
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)
44

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))
78

89
result =
910
Enum.reduce_while(params, [], fn {field_name, field_type}, acc ->
@@ -16,26 +17,26 @@ defmodule ElixirLS.LanguageServer.Fixtures.LspProtocol do
1617
case result do
1718
args when is_list(args) ->
1819
args =
19-
case type.__meta__(:type) do
20+
case module_to_build.__meta__(:type) do
2021
{:notification, _} ->
21-
Keyword.put(args, :method, type.__meta__(:method_name))
22+
Keyword.put(args, :method, module_to_build.__meta__(:method_name))
2223

2324
{:request, _} ->
2425
args
2526
|> 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))
2728

2829
_ ->
2930
args
3031
end
3132

32-
{:ok, type.new(args)}
33+
{:ok, module_to_build.new(args)}
3334

3435
{:error, _} = err ->
3536
err
3637
end
3738
else
38-
{:error, {:invalid_module, type}}
39+
{:error, {:invalid_module, module_to_build}}
3940
end
4041
end
4142

@@ -50,6 +51,19 @@ defmodule ElixirLS.LanguageServer.Fixtures.LspProtocol do
5051
end
5152
end
5253

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+
5367
defp maybe_wrap_with_json_rpc(%proto_module{} = proto, opts) do
5468
proto_struct =
5569
case proto_module.__meta__(:type) do

0 commit comments

Comments
 (0)