Skip to content

Commit 33c4f2f

Browse files
committed
handle nil configuration returned by workspace/configuration
the type is LSPAny in https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#workspace_configuration Fixes #1001
1 parent b61dc56 commit 33c4f2f

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

apps/language_server/lib/language_server/server.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,11 @@ defmodule ElixirLS.LanguageServer.Server do
14671467
response = JsonRpc.get_configuration_request(state.root_uri, "elixirLS")
14681468

14691469
case response do
1470-
{:ok, [result]} when is_map(result) ->
1470+
{:ok, [result]} when is_map(result) or is_nil(result) ->
1471+
# result type is LSPAny, we need to handle at least map and nil
1472+
# https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#workspace_configuration
1473+
result = result || %{}
1474+
14711475
Logger.info(
14721476
"Received client configuration via workspace/configuration\n#{inspect(result)}"
14731477
)

apps/language_server/test/server_test.exs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,39 @@ defmodule ElixirLS.LanguageServer.ServerTest do
111111
end)
112112
end
113113

114+
test "handles nil configuration", %{
115+
server: server
116+
} do
117+
in_fixture(__DIR__, "clean", fn ->
118+
Server.receive_packet(
119+
server,
120+
initialize_req(1, root_uri(), %{
121+
"workspace" => %{
122+
"configuration" => true
123+
}
124+
})
125+
)
126+
127+
assert_receive(%{"id" => 1, "result" => %{"capabilities" => %{}}}, 1000)
128+
Server.receive_packet(server, notification("initialized"))
129+
uri = root_uri()
130+
131+
assert_receive(
132+
%{
133+
"id" => 1,
134+
"method" => "workspace/configuration",
135+
"params" => %{"items" => [%{"scopeUri" => ^uri, "section" => "elixirLS"}]}
136+
},
137+
1000
138+
)
139+
140+
JsonRpc.receive_packet(response(1, [nil]))
141+
142+
assert :sys.get_state(server).mix_env == "test"
143+
wait_until_compiled(server)
144+
end)
145+
end
146+
114147
test "gets configuration after workspace/didChangeConfiguration notification if client supports it",
115148
%{
116149
server: server

0 commit comments

Comments
 (0)