Skip to content

Fix an error that causes SourceKit-LSP to exit immediately on Windows #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions Sources/sourcekit-lsp/SourceKitLSP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=6)
public import ArgumentParser
import BuildSystemIntegration
import Csourcekitd // Not needed here, but fixes debugging...
import Diagnose
Expand All @@ -26,24 +24,16 @@ import SourceKitLSP
import SwiftExtensions
import ToolchainRegistry

#if canImport(Android)
import Android
#endif
import struct TSCBasic.AbsolutePath

#if compiler(>=6)
public import ArgumentParser
#else
import ArgumentParser
import BuildSystemIntegration
import Csourcekitd // Not needed here, but fixes debugging...
import Diagnose
import Dispatch
import Foundation
import LanguageServerProtocol
import LanguageServerProtocolExtensions
import LanguageServerProtocolJSONRPC
import SKLogging
import SKOptions
import SourceKitLSP
import SwiftExtensions
import ToolchainRegistry
#endif

#if canImport(Android)
import Android
#endif

extension PathPrefixMapping {
Expand Down Expand Up @@ -279,6 +269,10 @@ struct SourceKitLSP: AsyncParsableCommand {
outFD: realStdoutHandle
)

// 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.
_ = try AbsolutePath(validating: Bundle.main.bundlePath)

var inputMirror: FileHandle? = nil
if let inputMirrorDirectory = globalConfigurationOptions.loggingOrDefault.inputMirrorDirectory {
orLog("Setting up input mirror") {
Expand Down