Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fox0430 committed Oct 18, 2024
1 parent 09faf2a commit 59c6838
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/moepkg/lsp/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ proc notify(
proc read*(c: var LspClient): JsonRpcResponseResult =
## Read a response from the LSP server.

let r = jsonrpc.read(c.serverProcess.stdoutStream)
let r = jsonrpc.read(c.serverStreams.output.stream)
if r.isOk:
return JsonRpcResponseResult.ok r.get
else:
Expand Down Expand Up @@ -378,8 +378,8 @@ proc getForegroundWaitingResponse*(
if v.bufferId == bufferId and v.lspMethod.isForegroundWait:
return some(v)

proc getFdStdout(p: AsyncProcessRef): cint {.inline.} =
p.stdoutStream.tsource.fd.cint
template getFdStdout(c: LspClient): cint =
c.serverStreams.output.stream.tsource.fd.cint

proc initLspClient*(command: string): initLspClientResult =
## Start a LSP server process and init streams.
Expand Down Expand Up @@ -408,18 +408,18 @@ proc initLspClient*(command: string): initLspClientResult =
except CatchableError as e:
return initLspClientResult.err fmt"server start failed: {e.msg}"

c.serverStreams = Streams(
input: InputStream(stream: c.serverProcess.stdinStream),
output: OutputStream(stream: c.serverProcess.stdoutStream))

block:
# Init pollFd.
c.pollFd.addr.zeroMem(sizeof(c.pollFd))

# Registers fd and events.
c.pollFd.fd = c.serverProcess.getFdStdout
c.pollFd.fd = c.getFdStdout
c.pollFd.events = POLLIN or POLLERR

c.serverStreams = Streams(
input: InputStream(stream: c.serverProcess.stdinStream),
output: OutputStream(stream: c.serverProcess.stdoutStream))

c.serverName = commandSplit[0]

c.command = command
Expand Down
4 changes: 2 additions & 2 deletions src/moepkg/lsp/jsonrpc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type
input*: InputStream
output*: OutputStream

let Timeout = 10.milliseconds
let Timeout = 1000.milliseconds

proc skipWhitespace(x: string, pos: int): int =
result = pos
Expand Down Expand Up @@ -76,7 +76,7 @@ proc readFrame(s: AsyncStreamReader): ReadFrameResult =
while true:
let buf =
try:
let f = s.readLine(sep="\n")
let f = s.readLine
if waitFor f.withTimeout(Timeout):
f.value
else:
Expand Down

0 comments on commit 59c6838

Please sign in to comment.