Skip to content

Commit

Permalink
handle nil configuration returned by workspace/configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 8, 2023
1 parent b61dc56 commit 33c4f2f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
)
Expand Down
33 changes: 33 additions & 0 deletions apps/language_server/test/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33c4f2f

Please sign in to comment.