Files
sourcekit-lsp/Sources/SourceKitLSP/Hooks.swift
Alex Hoppen 14cfd50582 If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
This should be a last stop-gap measure in case sourcekitd or clangd get stuck, don’t respond to any requests anymore and don’t honor cancellation either. In that case we can restore SourceKit-LSP behavior by killing them and using the crash recovery logic to restore functionality.

rdar://149492159
2025-05-07 13:43:28 +02:00

54 lines
1.9 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
package import BuildSystemIntegration
import Foundation
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
package import SemanticIndex
import struct TSCBasic.AbsolutePath
import struct TSCBasic.RelativePath
/// Closures can be used to inspect or modify internal behavior in SourceKit-LSP.
public struct Hooks: Sendable {
package var indexHooks: IndexHooks
package var buildSystemHooks: BuildSystemHooks
/// A hook that will be executed before a request is handled.
///
/// This allows requests to be artificially delayed.
package var preHandleRequest: (@Sendable (any RequestType) async -> Void)?
/// Closure that is executed before a request is forwarded to clangd.
///
/// This allows tests to simulate a `clangd` process that's unresponsive.
package var preForwardRequestToClangd: (@Sendable (any RequestType) async -> Void)?
public init() {
self.init(indexHooks: IndexHooks(), buildSystemHooks: BuildSystemHooks())
}
package init(
indexHooks: IndexHooks = IndexHooks(),
buildSystemHooks: BuildSystemHooks = BuildSystemHooks(),
preHandleRequest: (@Sendable (any RequestType) async -> Void)? = nil,
preForwardRequestToClangd: (@Sendable (any RequestType) async -> Void)? = nil
) {
self.indexHooks = indexHooks
self.buildSystemHooks = buildSystemHooks
self.preHandleRequest = preHandleRequest
self.preForwardRequestToClangd = preForwardRequestToClangd
}
}