mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
The idea is pretty simple: When `MemberImportVisibility` is enabled, we know that imports can only affect the current source file. So, we can just try and remove every single `import` declaration in the file, check if a new error occurred and if not, we can safely remove it.
31 lines
1006 B
Swift
31 lines
1006 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2025 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if swift(>=6.4)
|
|
#warning("Remove this in favor of SE-0493 (Support async calls in defer bodies) when possible")
|
|
#endif
|
|
/// Run `body` and always ensure that `cleanup` gets run, independently of whether `body` threw an error or returned a
|
|
/// value.
|
|
package func run<T>(
|
|
_ body: () async throws -> T,
|
|
cleanup: () async -> Void
|
|
) async throws -> T {
|
|
do {
|
|
let result = try await body()
|
|
await cleanup()
|
|
return result
|
|
} catch {
|
|
await cleanup()
|
|
throw error
|
|
}
|
|
}
|