Skip to content

Commit

Permalink
lsp: Use poll instead of epoll for better compatibility (#1909)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox0430 authored Oct 29, 2023
1 parent 62cf2be commit 5379804
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
7 changes: 7 additions & 0 deletions changelog.d/20231029_205646_GitHub_Actions_use-poll.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _#1909: https://github.com/fox0430/moe/pull/1909

Changed
.......

- `#1909`_ lsp: Use poll instead of epoll for better compatibility

38 changes: 17 additions & 21 deletions src/moepkg/lsp/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# NOTE: Language Server Protocol Specification - 3.17
# https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/

import std/[strformat, strutils, json, options, os, osproc, posix, epoll]
import std/[strformat, strutils, json, options, os, osproc, posix]
import pkg/results

import ../appinfo
Expand Down Expand Up @@ -99,28 +99,24 @@ proc exit*(c: LspClient) =

proc readyOutput(c: LspClient, timeout: int): Result[(), string] =
## Return when output is written from the LSP server or timesout.
## Wait for the output from process to be written using epoll(7).
## Wait for the output from process to be written using poll(2).
## timeout is milliseconds.

var epoll = epoll_create(sizeof(cint).cint)
if epoll < 0:
return Result[(), string].err "epoll_create failed"

var ev: EpollEvent
ev.events = EPOLLIN;
var ctl = epoll.epoll_ctl(
EPOLL_CTL_ADD,
c.serverProcess.outputHandle.cint,
ev.addr)
if ctl < 0:
return Result[(), string].err "epoll_ctl failed"

const MaxEvent = 1
let r = epoll.epoll_wait(ev.addr, MaxEvent, timeout.cint)
if r < 0:
return Result[(), string].err "epoll_wait failed"

return Result[(), string].ok ()
# Init pollFd.
var pollFd: TPollfd
pollFd.addr.zeroMem(sizeof(pollFd))

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

# Wait a server response.
const FdLen = 1
let r = pollFd.addr.poll(FdLen.Tnfds, timeout)
if r == 1:
return Result[(), string].ok ()
else:
return Result[(), string].err "timeout"

proc call(
c: LspClient,
Expand Down

0 comments on commit 5379804

Please sign in to comment.