Skip to content

Commit e6b8e07

Browse files
committed
Fix an error that causes SourceKit-LSP to exit immediately on Windows
For reasons that are completely oblivious to me, `DispatchIO.write`, which is used to write LSP responses to stdout fails with error code 5 on Windows unless we call `AbsolutePath(validating:)` on some URL first.
1 parent 7a06eb0 commit e6b8e07

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

Sources/sourcekit-lsp/SourceKitLSP.swift

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

13-
#if compiler(>=6)
14-
public import ArgumentParser
1513
import BuildSystemIntegration
1614
import Csourcekitd // Not needed here, but fixes debugging...
1715
import Diagnose
@@ -26,24 +24,16 @@ import SourceKitLSP
2624
import SwiftExtensions
2725
import ToolchainRegistry
2826

29-
#if canImport(Android)
30-
import Android
31-
#endif
27+
import struct TSCBasic.AbsolutePath
28+
29+
#if compiler(>=6)
30+
public import ArgumentParser
3231
#else
3332
import ArgumentParser
34-
import BuildSystemIntegration
35-
import Csourcekitd // Not needed here, but fixes debugging...
36-
import Diagnose
37-
import Dispatch
38-
import Foundation
39-
import LanguageServerProtocol
40-
import LanguageServerProtocolExtensions
41-
import LanguageServerProtocolJSONRPC
42-
import SKLogging
43-
import SKOptions
44-
import SourceKitLSP
45-
import SwiftExtensions
46-
import ToolchainRegistry
33+
#endif
34+
35+
#if canImport(Android)
36+
import Android
4737
#endif
4838

4939
extension PathPrefixMapping {
@@ -279,6 +269,10 @@ struct SourceKitLSP: AsyncParsableCommand {
279269
outFD: realStdoutHandle
280270
)
281271

272+
// For reasons that are completely oblivious to me, `DispatchIO.write`, which is used to write LSP responses to
273+
// stdout fails with error code 5 on Windows unless we call `AbsolutePath(validating:)` on some URL first.
274+
_ = try AbsolutePath(validating: Bundle.main.bundlePath)
275+
282276
var inputMirror: FileHandle? = nil
283277
if let inputMirrorDirectory = globalConfigurationOptions.loggingOrDefault.inputMirrorDirectory {
284278
orLog("Setting up input mirror") {

0 commit comments

Comments
 (0)