Files
sourcekit-lsp/Sources/SourceKitLSP/Swift/SourceKitD+ResponseError.swift
Alex Hoppen 4dba9c287b Add a maximum duration for sourcekitd requests
VS Code does not cancel semantic tokens requests. If a source file gets into a state where an AST build takes very long, this can cause us to wait for the semantic tokens from sourcekitd for a few minutes, effectively blocking all other semantic functionality in that file.

To circumvent this problem (or any other problem where an editor might not be cancelling requests they are no longer interested in) add a maximum request duration for SourceKitD requests, defaulting to 2 minutes.

rdar://130948453
2024-07-02 23:06:13 +02:00

34 lines
1.2 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
//
//===----------------------------------------------------------------------===//
import LanguageServerProtocol
import SourceKitD
extension ResponseError {
public init(_ value: SKDError) {
switch value {
case .requestCancelled:
self = .cancelled
case .timedOut:
self = .unknown("sourcekitd request timed out")
case .requestFailed(let desc):
self = .unknown("sourcekitd request failed: \(desc)")
case .requestInvalid(let desc):
self = .unknown("sourcekitd invalid request \(desc)")
case .missingRequiredSymbol(let desc):
self = .unknown("sourcekitd missing required symbol '\(desc)'")
case .connectionInterrupted:
self = .unknown("sourcekitd connection interrupted")
}
}
}