Skip to content

Commit 241744d

Browse files
authored
Merge pull request #319 from compnerd/dispatch
LanguageServerProtocolJSONRPC: make Windows path work
2 parents a62aad4 + b33a517 commit 241744d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Sources/LanguageServerProtocolJSONRPC/JSONRPCConnection.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if canImport(CDispatch)
14+
import CDispatch
15+
#endif
1316
import Dispatch
1417
import Foundation
1518
import LanguageServerProtocol
1619
import LSPLogging
20+
#if os(Windows)
21+
import ucrt
22+
#endif
1723

1824
/// A connection between a message handler (e.g. language server) in the same process as the connection object and a remote message handler (e.g. language client) that may run in another process using JSON RPC messages sent over a pair of in/out file descriptors.
1925
///
@@ -67,15 +73,25 @@ public final class JSONRPCConnection {
6773
let ioGroup = DispatchGroup()
6874

6975
ioGroup.enter()
70-
receiveIO = DispatchIO(type: .stream, fileDescriptor: inFD, queue: queue) { (error: Int32) in
76+
#if os(Windows)
77+
let inDesc: dispatch_fd_t = dispatch_fd_t(_get_osfhandle(inFD))
78+
#else
79+
let inDesc: Int32 = Int32(inFD)
80+
#endif
81+
receiveIO = DispatchIO(type: .stream, fileDescriptor: inDesc, queue: queue) { (error: Int32) in
7182
if error != 0 {
7283
log("IO error \(error)", level: .error)
7384
}
7485
ioGroup.leave()
7586
}
7687

7788
ioGroup.enter()
78-
sendIO = DispatchIO(type: .stream, fileDescriptor: outFD, queue: sendQueue) { (error: Int32) in
89+
#if os(Windows)
90+
let outDesc: dispatch_fd_t = dispatch_fd_t(_get_osfhandle(outFD))
91+
#else
92+
let outDesc: Int32 = Int32(outFD)
93+
#endif
94+
sendIO = DispatchIO(type: .stream, fileDescriptor: outDesc, queue: sendQueue) { (error: Int32) in
7995
if error != 0 {
8096
log("IO error \(error)", level: .error)
8197
}

Sources/sourcekit-lsp/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct Main: ParsableCommand {
161161

162162
let clientConnection = JSONRPCConnection(
163163
protocol: MessageRegistry.lspProtocol,
164-
inFD: STDIN_FILENO,
164+
inFD: fileno(stdin),
165165
outFD: realStdout,
166166
syncRequests: syncRequests
167167
)

0 commit comments

Comments
 (0)