Skip to content

Commit a927fde

Browse files
committed
do not try to respond to cancelled requests
Fixes #1009
1 parent 286ad95 commit a927fde

File tree

1 file changed

+28
-25
lines changed
  • apps/language_server/lib/language_server

1 file changed

+28
-25
lines changed

apps/language_server/lib/language_server/server.ex

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,38 +158,41 @@ defmodule ElixirLS.LanguageServer.Server do
158158

159159
@impl GenServer
160160
def handle_call({:request_finished, id, result}, _from, state = %__MODULE__{}) do
161-
{{_pid, command, start_time}, requests} = Map.pop!(state.requests, id)
161+
# in case the request has been cancelled we silently ignore
162+
{popped_request, updated_requests} = Map.pop(state.requests, id)
163+
if popped_request do
164+
{{_pid, command, start_time}, requests} = popped_request
165+
case result do
166+
{:error, type, msg, send_telemetry} ->
167+
JsonRpc.respond_with_error(id, type, msg)
162168

163-
case result do
164-
{:error, type, msg, send_telemetry} ->
165-
JsonRpc.respond_with_error(id, type, msg)
169+
if send_telemetry do
170+
JsonRpc.telemetry(
171+
"lsp_request_error",
172+
%{
173+
"elixir_ls.lsp_command" => String.replace(command, "/", "_"),
174+
"elixir_ls.lsp_error" => type,
175+
"elixir_ls.lsp_error_message" => msg
176+
},
177+
%{}
178+
)
179+
end
180+
181+
{:ok, result} ->
182+
elapsed = System.monotonic_time(:millisecond) - start_time
183+
JsonRpc.respond(id, result)
166184

167-
if send_telemetry do
168185
JsonRpc.telemetry(
169-
"lsp_request_error",
186+
"lsp_request",
187+
%{"elixir_ls.lsp_command" => String.replace(command, "/", "_")},
170188
%{
171-
"elixir_ls.lsp_command" => String.replace(command, "/", "_"),
172-
"elixir_ls.lsp_error" => type,
173-
"elixir_ls.lsp_error_message" => msg
174-
},
175-
%{}
189+
"elixir_ls.lsp_request_time" => elapsed
190+
}
176191
)
177-
end
178-
179-
{:ok, result} ->
180-
elapsed = System.monotonic_time(:millisecond) - start_time
181-
JsonRpc.respond(id, result)
182-
183-
JsonRpc.telemetry(
184-
"lsp_request",
185-
%{"elixir_ls.lsp_command" => String.replace(command, "/", "_")},
186-
%{
187-
"elixir_ls.lsp_request_time" => elapsed
188-
}
189-
)
192+
end
190193
end
191194

192-
state = %{state | requests: requests}
195+
state = %{state | requests: updated_requests}
193196
{:reply, :ok, state}
194197
end
195198

0 commit comments

Comments
 (0)