Skip to content

Commit

Permalink
* fixed crash in the handling of the shutdown request with missing pa…
Browse files Browse the repository at this point in the history
…rams (#142)

* WIP

* * fixed crash in the handling of the shutdown request with missing params
  • Loading branch information
nickysn authored Jan 27, 2024
1 parent c55a266 commit 0976b96
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions nimlangserver.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import macros, strformat, faststreams/async_backend,
faststreams/asynctools_adapters, faststreams/inputs, faststreams/outputs,
json_rpc/streamconnection, os, sugar, sequtils, hashes, osproc,
json_rpc/streamconnection, json_rpc/server, os, sugar, sequtils, hashes, osproc,
suggestapi, protocol/enums, protocol/types, with, tables, strutils, sets,
./utils, ./pipes, chronicles, std/re, uri, "$nim/compiler/pathutils",
procmonitor, std/strscans, json_serialization, serialization/formats
procmonitor, std/strscans, json_serialization, serialization/formats,
std/json, std/parseutils


const
Expand Down Expand Up @@ -1063,14 +1064,22 @@ proc documentHighlight(ls: LanguageServer, params: TextDocumentPositionParams, i
.orCancelled(ls, id)
result = suggestLocations.map(toDocumentHighlight);

proc shutdown(ls: LanguageServer, params: JsonNode):
Future[JsonNode] {.async.} =
proc extractId (id: JsonNode): int =
if id.kind == JInt:
result = id.getInt
if id.kind == JString:
discard parseInt(id.getStr, result)

proc shutdown(ls: LanguageServer, input: JsonNode): Future[RpcResult] {.async, gcsafe, raises: [Defect, CatchableError, Exception].} =
debug "Shutting down"
for ns in ls.projectFiles.values:
let ns = await ns
ns.stop()
ls.isShutdown = true
result = newJNull()
let id = input{"id"}.extractId
result = some( StringOfJson(
"""{"jsonrpc":"2.0","result":null,"id":$1}""" % [$id] & "\r\n")
)
trace "Shutdown complete"

proc exit(pipeInput: AsyncInputStream, _: JsonNode):
Expand Down

0 comments on commit 0976b96

Please sign in to comment.