diff --git a/apps/language_server/lib/language_server/server.ex b/apps/language_server/lib/language_server/server.ex index a65bb57c4..c031d3f2f 100644 --- a/apps/language_server/lib/language_server/server.ex +++ b/apps/language_server/lib/language_server/server.ex @@ -1467,7 +1467,11 @@ defmodule ElixirLS.LanguageServer.Server do response = JsonRpc.get_configuration_request(state.root_uri, "elixirLS") case response do - {:ok, [result]} when is_map(result) -> + {:ok, [result]} when is_map(result) or is_nil(result) -> + # result type is LSPAny, we need to handle at least map and nil + # https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#workspace_configuration + result = result || %{} + Logger.info( "Received client configuration via workspace/configuration\n#{inspect(result)}" ) diff --git a/apps/language_server/test/server_test.exs b/apps/language_server/test/server_test.exs index f622e4cbc..44d7de51f 100644 --- a/apps/language_server/test/server_test.exs +++ b/apps/language_server/test/server_test.exs @@ -111,6 +111,39 @@ defmodule ElixirLS.LanguageServer.ServerTest do end) end + test "handles nil configuration", %{ + server: server + } do + in_fixture(__DIR__, "clean", fn -> + Server.receive_packet( + server, + initialize_req(1, root_uri(), %{ + "workspace" => %{ + "configuration" => true + } + }) + ) + + assert_receive(%{"id" => 1, "result" => %{"capabilities" => %{}}}, 1000) + Server.receive_packet(server, notification("initialized")) + uri = root_uri() + + assert_receive( + %{ + "id" => 1, + "method" => "workspace/configuration", + "params" => %{"items" => [%{"scopeUri" => ^uri, "section" => "elixirLS"}]} + }, + 1000 + ) + + JsonRpc.receive_packet(response(1, [nil])) + + assert :sys.get_state(server).mix_env == "test" + wait_until_compiled(server) + end) + end + test "gets configuration after workspace/didChangeConfiguration notification if client supports it", %{ server: server