Skip to content

Commit

Permalink
remove comments and extra lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Sep 9, 2024
1 parent 108bca6 commit 17ce6a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
22 changes: 11 additions & 11 deletions lstransports.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import std/[syncio, os, json, strutils, strformat, streams, oids, sequtils]
import ls, utils
import protocol/types, chronos/threadsync

type LspClientResponse* = object
jsonrpc*: JsonRPC2
id*: string
result*: JsonNode
type
LspClientResponse* = object
jsonrpc*: JsonRPC2
id*: string
result*: JsonNode

Rpc* = proc(params: RequestParamsRx): Future[JsonString] {.gcsafe, raises: [].}

template flavorUsesAutomaticObjectSerialization(T: type JrpcSys): bool =
true

proc readValue*(r: var JsonReader, val: var OptionalNode) =
try:

discard r.tokKind()
val = some r.parseJsonNode()
except CatchableError:
Expand All @@ -34,12 +36,10 @@ proc toJson*(params: RequestParamsRx): JsonNode =
for np in params.named:
result[np.name] = parseJson($np.value)
else:
result = newJArray() #TODO this may be wrong
result = newJArray()
for p in params.positional:
result.add parseJson($p)

type Rpc* = proc(params: RequestParamsRx): Future[JsonString] {.gcsafe, raises: [].}

proc wrapRpc*[T](
fn: proc(params: T): Future[auto] {.gcsafe, raises: [].}
): Rpc =
Expand Down Expand Up @@ -174,14 +174,14 @@ proc processMessage(ls: LanguageServer, message: string) {.raises:[].} =
let id = response.id
if id notin ls.responseMap:
error "Id not found in responseMap", id = id #TODO we should store the call name we are trying to responde to here

if response.result == nil:
ls.responseMap[id].complete(newJObject())
ls.responseMap.del id
else:
let r = response.result
ls.responseMap[id].complete(r)
ls.responseMap.del id

except JsonParsingError as ex:
error "[Processsing Message] Error parsing message", message = message
writeStackTrace(ex)
Expand Down Expand Up @@ -247,7 +247,6 @@ proc startStdioServer*(ls: LanguageServer) =
createThread(stdinThread, readStdin, ls.stdinContext)
asyncSpawn ls.startStdioLoop()


proc processClientLoop*(ls: LanguageServer, server: StreamServer, transport: StreamTransport) {.async: (raises: []), gcsafe.} =
ls.socketTransport = transport
while true:
Expand All @@ -263,4 +262,5 @@ proc startSocketServer*(ls: LanguageServer, port: Port) =
ls.srv = newRpcSocketServer(partial(processClientLoop, ls))
ls.initActions()
ls.srv.addStreamServer("localhost", port)
ls.srv.start
ls.srv.start

7 changes: 2 additions & 5 deletions nimlangserver.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json_rpc/[servers/socketserver, private/jrpc_sys, jsonmarshal, rpcclient, router]
import chronicles, chronos
import
std/[ syncio, os, json, strutils, strformat, net]
import std/[ syncio, os, json, strutils, strformat, net]
import ls, routes, suggestapi, utils, lstransports, asyncprocmonitor

import protocol/types
when defined(posix):
import posix
Expand Down Expand Up @@ -44,7 +42,6 @@ proc registerRoutes(srv: RpcSocketServer, ls: LanguageServer) =
srv.register("textDocument/didChange", wrapRpc(partial(didChange, ls)))
srv.register("$/setTrace", wrapRpc(partial(setTrace, ls)))


proc getNextFreePort*(): Port=
let s = newSocket()
s.bindAddr(Port(0), "localhost")
Expand Down Expand Up @@ -132,7 +129,7 @@ when isMainModule:
ls.stopNimsuggestProcessesP()
exitnow(1)
runForever()

except Exception as e:
error "Error in main"
writeStackTrace e
Expand Down
3 changes: 1 addition & 2 deletions routes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,6 @@ proc didOpen*(ls: LanguageServer, params: DidOpenTextDocumentParams):
proc didChangeConfiguration*(ls: LanguageServer, conf: JsonNode):
Future[void] {.async, gcsafe.} =
debug "Changed configuration: ", conf = conf

if ls.usePullConfigurationModel:
ls.maybeRequestConfigurationFromClient
else:
Expand All @@ -749,4 +748,4 @@ proc didChangeConfiguration*(ls: LanguageServer, conf: JsonNode):
ls.workspaceConfiguration = newFuture[JsonNode]()
ls.workspaceConfiguration.complete(conf)
handleConfigurationChanges(ls, oldConfiguration, newConfiguration)

0 comments on commit 17ce6a7

Please sign in to comment.