Skip to content

Commit

Permalink
Workaround a VSCode bug that precludes the server from exiting (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
artempyanykh committed May 8, 2022
1 parent ca6d7c9 commit 37ab624
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/LanguageServerProtocol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,24 @@ module Server =
let mutable quitReceived = false
use quitSemaphore = new SemaphoreSlim(0, 1)

let onShutdown () = shutdownReceived <- true
let onShutdown () =
logger.trace (Log.setMessage "Shutdown received")
shutdownReceived <- true
// VSCode Language Client has a bug that causes it to NOT send an `exit` notification when stopping a server:
// https://github.com/microsoft/vscode-languageserver-node/pull/776 This may result in a bunch of zombie language
// servers just hanging around after a few reloads/restarts. Although the fix was merged a while ago, the new
// client is yet to be released. As a workaround let's forcefully exit after 10s after receiving a `shutdown`
// request.
task {
do! Task.Delay(10_000)
logger.trace (Log.setMessage "No `exit` notification within 10s after `shutdown` request. Exiting now.")
quitSemaphore.Release() |> ignore
} |> ignore

jsonRpc.AddLocalRpcMethod("shutdown", Action(onShutdown))

let onExit () =
logger.trace (Log.setMessage "Exit received")
quitReceived <- true
quitSemaphore.Release() |> ignore

Expand Down

0 comments on commit 37ab624

Please sign in to comment.