diff --git a/Package.swift b/Package.swift index a2cb1cb2f..fafc27207 100644 --- a/Package.swift +++ b/Package.swift @@ -20,8 +20,8 @@ var products: [Product] = [ .library(name: "LanguageServerProtocolTransport", targets: ["LanguageServerProtocolTransport"]), .library(name: "SKLogging", targets: ["SKLogging"]), .library(name: "_SKLoggingForPlugin", targets: ["_SKLoggingForPlugin"]), - .library(name: "SwiftExtensions", targets: ["SwiftExtensions"]), - .library(name: "_SwiftExtensionsForPlugin", targets: ["_SwiftExtensionsForPlugin"]), + .library(name: "ToolsProtocolsSwiftExtensions", targets: ["ToolsProtocolsSwiftExtensions"]), + .library(name: "_ToolsProtocolsSwiftExtensionsForPlugin", targets: ["_ToolsProtocolsSwiftExtensionsForPlugin"]), ] var targets: [Target] = [ @@ -86,7 +86,7 @@ var targets: [Target] = [ "BuildServerProtocol", "LanguageServerProtocol", "SKLogging", - "SwiftExtensions", + "ToolsProtocolsSwiftExtensions", ], exclude: ["CMakeLists.txt"], swiftSettings: globalSwiftSettings @@ -107,7 +107,7 @@ var targets: [Target] = [ .target( name: "SKLogging", dependencies: [ - "SwiftExtensions", + "ToolsProtocolsSwiftExtensions", ], exclude: ["CMakeLists.txt"], swiftSettings: globalSwiftSettings + lspLoggingSwiftSettings @@ -117,12 +117,12 @@ var targets: [Target] = [ .target( name: "_SKLoggingForPlugin", dependencies: [ - "_SwiftExtensionsForPlugin" + "_ToolsProtocolsSwiftExtensionsForPlugin" ], exclude: ["CMakeLists.txt"], swiftSettings: globalSwiftSettings + lspLoggingSwiftSettings + [ .unsafeFlags([ - "-module-alias", "SwiftExtensions=_SwiftExtensionsForPlugin", + "-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin", ]), ] ), @@ -144,34 +144,34 @@ var targets: [Target] = [ "LanguageServerProtocol", "LanguageServerProtocolTransport", "SKLogging", - "SwiftExtensions", + "ToolsProtocolsSwiftExtensions", ], swiftSettings: globalSwiftSettings ), - // MARK: SwiftExtensions + // MARK: ToolsProtocolsSwiftExtensions .target( - name: "SwiftExtensions", + name: "ToolsProtocolsSwiftExtensions", dependencies: ["ToolsProtocolsCAtomics"], exclude: ["CMakeLists.txt"], swiftSettings: globalSwiftSettings ), - // SourceKit-LSP SPI target. Builds SwiftExtensions with an alternate module name to avoid runtime type collisions. + // SourceKit-LSP SPI target. Builds ToolsProtocolsSwiftExtensions with an alternate module name to avoid runtime type collisions. .target( - name: "_SwiftExtensionsForPlugin", + name: "_ToolsProtocolsSwiftExtensionsForPlugin", dependencies: ["ToolsProtocolsCAtomics"], exclude: ["CMakeLists.txt"], swiftSettings: globalSwiftSettings ), .testTarget( - name: "SwiftExtensionsTests", + name: "ToolsProtocolsSwiftExtensionsTests", dependencies: [ "SKLogging", "ToolsProtocolsTestSupport", - "SwiftExtensions", + "ToolsProtocolsSwiftExtensions", ], swiftSettings: globalSwiftSettings ), diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 3ae3a5450..f1dab2859 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -6,4 +6,4 @@ add_subdirectory(ToolsProtocolsCAtomics) add_subdirectory(LanguageServerProtocol) add_subdirectory(LanguageServerProtocolTransport) add_subdirectory(SKLogging) -add_subdirectory(SwiftExtensions) +add_subdirectory(ToolsProtocolsSwiftExtensions) diff --git a/Sources/LanguageServerProtocolTransport/BuildServerMessageDependencyTracker.swift b/Sources/LanguageServerProtocolTransport/BuildServerMessageDependencyTracker.swift index 769b93e84..0b25cb756 100644 --- a/Sources/LanguageServerProtocolTransport/BuildServerMessageDependencyTracker.swift +++ b/Sources/LanguageServerProtocolTransport/BuildServerMessageDependencyTracker.swift @@ -13,7 +13,7 @@ import BuildServerProtocol public import LanguageServerProtocol @_spi(SourceKitLSP) import SKLogging -import SwiftExtensions +import ToolsProtocolsSwiftExtensions /// A lightweight way of describing tasks that are created from handling BSP /// requests or notifications for the purpose of dependency tracking. diff --git a/Sources/LanguageServerProtocolTransport/JSONRPCConnection.swift b/Sources/LanguageServerProtocolTransport/JSONRPCConnection.swift index 0142ef105..cd0cb5232 100644 --- a/Sources/LanguageServerProtocolTransport/JSONRPCConnection.swift +++ b/Sources/LanguageServerProtocolTransport/JSONRPCConnection.swift @@ -14,7 +14,7 @@ public import Dispatch public import Foundation public import LanguageServerProtocol @_spi(SourceKitLSP) import SKLogging -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions #if canImport(Android) import Android diff --git a/Sources/LanguageServerProtocolTransport/LocalConnection.swift b/Sources/LanguageServerProtocolTransport/LocalConnection.swift index 99a3726ea..f910ceb13 100644 --- a/Sources/LanguageServerProtocolTransport/LocalConnection.swift +++ b/Sources/LanguageServerProtocolTransport/LocalConnection.swift @@ -14,7 +14,7 @@ import Dispatch import Foundation public import LanguageServerProtocol @_spi(SourceKitLSP) import SKLogging -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions /// A connection between two message handlers in the same process. /// diff --git a/Sources/LanguageServerProtocolTransport/QueueBasedMessageHandler.swift b/Sources/LanguageServerProtocolTransport/QueueBasedMessageHandler.swift index 1f4c4bb48..fadc54aa2 100644 --- a/Sources/LanguageServerProtocolTransport/QueueBasedMessageHandler.swift +++ b/Sources/LanguageServerProtocolTransport/QueueBasedMessageHandler.swift @@ -13,7 +13,7 @@ import Foundation public import LanguageServerProtocol @_spi(SourceKitLSP) import SKLogging -@_spi(SourceKitLSP) public import SwiftExtensions +@_spi(SourceKitLSP) public import ToolsProtocolsSwiftExtensions /// Side structure in which `QueueBasedMessageHandler` can keep track of active requests etc. /// diff --git a/Sources/LanguageServerProtocolTransport/RequestAndReply.swift b/Sources/LanguageServerProtocolTransport/RequestAndReply.swift index d4dc717ff..f41fd2964 100644 --- a/Sources/LanguageServerProtocolTransport/RequestAndReply.swift +++ b/Sources/LanguageServerProtocolTransport/RequestAndReply.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// public import LanguageServerProtocol -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions /// A request and a callback that returns the request's reply public final class RequestAndReply: Sendable { diff --git a/Sources/SKLogging/CMakeLists.txt b/Sources/SKLogging/CMakeLists.txt index 477ea120d..452fc20b5 100644 --- a/Sources/SKLogging/CMakeLists.txt +++ b/Sources/SKLogging/CMakeLists.txt @@ -14,18 +14,18 @@ set_target_properties(SKLogging PROPERTIES target_link_libraries(SKLogging PRIVATE $<$>:Foundation>) target_link_libraries(SKLogging PUBLIC - SwiftExtensions) + ToolsProtocolsSwiftExtensions) add_library(SKLoggingForPlugin STATIC ${sources}) set_target_properties(SKLoggingForPlugin PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) target_compile_options(SKLoggingForPlugin PRIVATE $<$: - "SHELL:-module-alias SwiftExtensions=SwiftExtensionsForPlugin" + "SHELL:-module-alias ToolsProtocolsSwiftExtensions=ToolsProtocolsSwiftExtensionsForPlugin" >) target_link_libraries(SKLoggingForPlugin PRIVATE $<$>:Foundation>) target_link_libraries(SKLoggingForPlugin PUBLIC - SwiftExtensionsForPlugin) + ToolsProtocolsSwiftExtensionsForPlugin) set_property(GLOBAL APPEND PROPERTY SWIFTTOOLSPROTOCOLS_EXPORTS SKLogging) diff --git a/Sources/SKLogging/LoggingScope.swift b/Sources/SKLogging/LoggingScope.swift index dbcfb1d3c..0f63271e0 100644 --- a/Sources/SKLogging/LoggingScope.swift +++ b/Sources/SKLogging/LoggingScope.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// import Foundation -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions public final class LoggingScope { diff --git a/Sources/SKLogging/NonDarwinLogging.swift b/Sources/SKLogging/NonDarwinLogging.swift index bed3ff50c..c93c05002 100644 --- a/Sources/SKLogging/NonDarwinLogging.swift +++ b/Sources/SKLogging/NonDarwinLogging.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -@_spi(SourceKitLSP) public import SwiftExtensions +@_spi(SourceKitLSP) public import ToolsProtocolsSwiftExtensions #if canImport(Darwin) import Foundation diff --git a/Sources/SKLogging/SetGlobalLogFileHandler.swift b/Sources/SKLogging/SetGlobalLogFileHandler.swift index a161fce27..ac13ddd94 100644 --- a/Sources/SKLogging/SetGlobalLogFileHandler.swift +++ b/Sources/SKLogging/SetGlobalLogFileHandler.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// import RegexBuilder -import SwiftExtensions +import ToolsProtocolsSwiftExtensions #if canImport(Darwin) public import Foundation diff --git a/Sources/SwiftExtensions/Array+Safe.swift b/Sources/SwiftExtensions/Array+Safe.swift deleted file mode 100644 index f7ab49e95..000000000 --- a/Sources/SwiftExtensions/Array+Safe.swift +++ /dev/null @@ -1,19 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2018 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 -// -//===----------------------------------------------------------------------===// - -extension Array { - /// Returns the element at the specified index if it is within the Array's - /// bounds, otherwise `nil`. - @_spi(SourceKitLSP) public subscript(safe index: Index) -> Element? { - return index >= 0 && index < count ? self[index] : nil - } -} diff --git a/Sources/SwiftExtensions/CMakeLists.txt b/Sources/SwiftExtensions/CMakeLists.txt deleted file mode 100644 index c29efe237..000000000 --- a/Sources/SwiftExtensions/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -set(sources - Array+Safe.swift - AsyncQueue.swift - AsyncUtils.swift - Atomics.swift - Cache.swift - CartesianProduct.swift - Collection+Only.swift - Collection+PartitionIntoBatches.swift - Duration+Seconds.swift - FileManagerExtensions.swift - LazyValue.swift - NSLock+WithLock.swift - PipeAsStringHandler.swift - Platform.swift - Process+terminate.swift - ResultExtensions.swift - Sequence+AsyncMap.swift - Sequence+ContainsAnyIn.swift - Task+WithPriorityChangedHandler.swift - ThreadSafeBox.swift - TransitiveClosure.swift - URLExtensions.swift -) - -add_library(SwiftExtensions STATIC ${sources}) -set_target_properties(SwiftExtensions PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) -target_link_libraries(SwiftExtensions PUBLIC - ToolsProtocolsCAtomics) -target_link_libraries(SwiftExtensions PRIVATE - $<$>:Foundation>) - -add_library(SwiftExtensionsForPlugin STATIC ${sources}) -set_target_properties(SwiftExtensionsForPlugin PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) -target_link_libraries(SwiftExtensionsForPlugin PUBLIC - ToolsProtocolsCAtomics) -target_link_libraries(SwiftExtensionsForPlugin PRIVATE - $<$>:Foundation>) - -set_property(GLOBAL APPEND PROPERTY SWIFTTOOLSPROTOCOLS_EXPORTS SwiftExtensions) diff --git a/Sources/SwiftExtensions/Cache.swift b/Sources/SwiftExtensions/Cache.swift deleted file mode 100644 index e01a72e4f..000000000 --- a/Sources/SwiftExtensions/Cache.swift +++ /dev/null @@ -1,82 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -/// Essentially a dictionary where results are asynchronously computed on access. -@_spi(SourceKitLSP) public class Cache { - private var storage: [Key: Task] = [:] - - @_spi(SourceKitLSP) public init() {} - - @_spi(SourceKitLSP) public func get( - _ key: Key, - isolation: isolated any Actor, - compute: @Sendable @escaping (Key) async throws -> Result - ) async throws -> Result { - let task: Task - if let cached = storage[key] { - task = cached - } else { - task = Task { - try await compute(key) - } - storage[key] = task - } - return try await task.value - } - - /// Force the value for a specific key to a value. - /// - /// This should only be used if a value for this key is received by means that aren't covered through the `compute` - /// function in `get`. An example of this is receiving the results of a BSP request after a timeout, in which case we - /// would have cached the timeout result through `get` but now we have an updated value. - package func set(_ key: Key, to value: Result) { - storage[key] = Task { value } - } - - /// Get the value cached for `key`. If no value exists for `key`, try deriving the result from an existing cache entry - /// that satisfies `canReuseKey` by applying `transform` to that result. - @_spi(SourceKitLSP) public func getDerived( - isolation: isolated any Actor, - _ key: Key, - canReuseKey: @Sendable @escaping (Key) -> Bool, - transform: @Sendable @escaping (_ cachedResult: Result) -> Result - ) async throws -> Result? { - if let cached = storage[key] { - // If we have a value for the requested key, prefer that - return try await cached.value - } - - // See if don't have an entry for this key, see if we can derive the value from a cached entry. - for (cachedKey, cachedValue) in storage { - guard canReuseKey(cachedKey) else { - continue - } - let transformed = Task { try await transform(cachedValue.value) } - // Cache the transformed result. - storage[key] = transformed - return try await transformed.value - } - return nil - } - - @_spi(SourceKitLSP) public func clear(isolation: isolated any Actor, where condition: (Key) -> Bool) { - for key in storage.keys { - if condition(key) { - storage[key] = nil - } - } - } - - @_spi(SourceKitLSP) public func clearAll(isolation: isolated any Actor) { - storage.removeAll() - } -} diff --git a/Sources/SwiftExtensions/CartesianProduct.swift b/Sources/SwiftExtensions/CartesianProduct.swift deleted file mode 100644 index 2cbc96cff..000000000 --- a/Sources/SwiftExtensions/CartesianProduct.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2024 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 -// -//===----------------------------------------------------------------------===// - -/// Calculates the cartesian product of `lhs` and `rhs` -/// -/// Creates an array of tuple pairs, known as "Cartesian Product", which contains all the possible ways of -/// pairing each element from `lhs` with each element in `rhs`. -/// -/// Example Usage: -/// ```swift -/// let alphaNumberPairs = cartesianProduct([1, 2, 3], ["a", "b", "c"]) -/// print(alphaNumberPairs) -/// // Prints: "[(1, "a"), (2, "a"), (3, "a"), (1, "b"), (2, "b"), (3, "b"), (1, "c"), (2, "c"), (3, "c")]" -/// ``` -package func cartesianProduct(_ lhs: [T], _ rhs: [U]) -> [(T, U)] { - var result: [(T, U)] = [] - - for lhsElement in lhs { - for rhsElement in rhs { - result.append((lhsElement, rhsElement)) - } - } - return result -} diff --git a/Sources/SwiftExtensions/Collection+PartitionIntoBatches.swift b/Sources/SwiftExtensions/Collection+PartitionIntoBatches.swift deleted file mode 100644 index d11ce097a..000000000 --- a/Sources/SwiftExtensions/Collection+PartitionIntoBatches.swift +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2024 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 -// -//===----------------------------------------------------------------------===// - -@_spi(SourceKitLSP) public extension Collection where Index == Int { - /// Partition the elements of the collection into `numberOfBatches` roughly equally sized batches. - /// - /// Elements are assigned to the batches round-robin. This ensures that elements that are close to each other in the - /// original collection end up in different batches. This is important because eg. test files will live close to each - /// other in the file system and test scanning wants to scan them in different batches so we don't end up with one - /// batch only containing source files and the other only containing test files. - func partition(intoNumberOfBatches numberOfBatches: Int) -> [[Element]] { - var batches: [[Element]] = Array( - repeating: { - var batch: [Element] = [] - batch.reserveCapacity(self.count / numberOfBatches) - return batch - }(), - count: numberOfBatches - ) - - for (index, element) in self.enumerated() { - batches[index % numberOfBatches].append(element) - } - return batches.filter { !$0.isEmpty } - } - - /// Partition the collection into batches that have a maximum size of `batchSize`. - /// - /// The last batch will contain the remainder elements. - func partition(intoBatchesOfSize batchSize: Int) -> [[Element]] { - var batches: [[Element]] = [] - batches.reserveCapacity(self.count / batchSize) - var lastIndex = self.startIndex - for index in stride(from: self.startIndex, to: self.endIndex, by: batchSize).dropFirst() + [self.endIndex] { - batches.append(Array(self[lastIndex.. { - case computed(T) - case uninitialized - - /// If the value has already been computed return it, otherwise compute it using `compute`. - @_spi(SourceKitLSP) public mutating func cachedValueOrCompute(_ compute: () -> T) -> T { - switch self { - case .computed(let value): - return value - case .uninitialized: - let newValue = compute() - self = .computed(newValue) - return newValue - } - } - - @_spi(SourceKitLSP) public mutating func reset() { - self = .uninitialized - } -} diff --git a/Sources/SwiftExtensions/Platform.swift b/Sources/SwiftExtensions/Platform.swift deleted file mode 100644 index 191376eff..000000000 --- a/Sources/SwiftExtensions/Platform.swift +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2024 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 -// -//===----------------------------------------------------------------------===// - -@_spi(SourceKitLSP) public enum Platform: Equatable, Sendable { - case darwin - case linux - case windows - - @_spi(SourceKitLSP) public static var current: Platform? { - #if os(Windows) - return .windows - #elseif canImport(Darwin) - return .darwin - #else - return .linux - #endif - } - - /// The file extension used for a dynamic library on this platform. - @_spi(SourceKitLSP) public var dynamicLibraryExtension: String { - switch self { - case .darwin: return ".dylib" - case .linux: return ".so" - case .windows: return ".dll" - } - } - - @_spi(SourceKitLSP) public var executableExtension: String { - switch self { - case .windows: return ".exe" - case .linux, .darwin: return "" - } - } -} diff --git a/Sources/SwiftExtensions/Process+terminate.swift b/Sources/SwiftExtensions/Process+terminate.swift deleted file mode 100644 index 15b94cf27..000000000 --- a/Sources/SwiftExtensions/Process+terminate.swift +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -public import Foundation - -extension Foundation.Process { - /// If the process has not exited after `duration`, terminate it. - @_spi(SourceKitLSP) public func terminateIfRunning(after duration: Duration, pollInterval: Duration = .milliseconds(5)) async throws { - for _ in 0..( - _ transform: (Element) async throws -> T - ) async rethrows -> [T] { - var result: [T] = [] - result.reserveCapacity(self.underestimatedCount) - - for element in self { - try await result.append(transform(element)) - } - - return result - } - - /// Just like `Sequence.flatMap` but allows an `async` transform function. - @_spi(SourceKitLSP) public func asyncFlatMap( - _ transform: (Element) async throws -> SegmentOfResult - ) async rethrows -> [SegmentOfResult.Element] { - var result: [SegmentOfResult.Element] = [] - result.reserveCapacity(self.underestimatedCount) - - for element in self { - result += try await transform(element) - } - - return result - } - - /// Just like `Sequence.compactMap` but allows an `async` transform function. - @_spi(SourceKitLSP) public func asyncCompactMap( - _ transform: (Element) async throws -> T? - ) async rethrows -> [T] { - var result: [T] = [] - - for element in self { - if let transformed = try await transform(element) { - result.append(transformed) - } - } - - return result - } - - /// Just like `Sequence.map` but allows an `async` transform function. - @_spi(SourceKitLSP) public func asyncFilter( - _ predicate: (Element) async throws -> Bool - ) async rethrows -> [Element] { - var result: [Element] = [] - - for element in self { - if try await predicate(element) { - result.append(element) - } - } - - return result - } - - /// Just like `Sequence.first` but allows an `async` predicate function. - @_spi(SourceKitLSP) public func asyncFirst(where predicate: (Element) async throws -> Bool) async rethrows -> Element? { - for element in self { - if try await predicate(element) { - return element - } - } - - return nil - } - - /// Just like `Sequence.contains` but allows an `async` predicate function. - @_spi(SourceKitLSP) public func asyncContains( - where predicate: (Element) async throws -> Bool - ) async rethrows -> Bool { - return try await asyncFirst(where: predicate) != nil - } -} diff --git a/Sources/SwiftExtensions/Sequence+ContainsAnyIn.swift b/Sources/SwiftExtensions/Sequence+ContainsAnyIn.swift deleted file mode 100644 index 2d3cd62b2..000000000 --- a/Sources/SwiftExtensions/Sequence+ContainsAnyIn.swift +++ /dev/null @@ -1,18 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2024 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 -// -//===----------------------------------------------------------------------===// - -extension Sequence { - /// Returns `true` if the intersection of `self` and `other` is not empty. - package func contains(anyIn other: Set) -> Bool where Element: Hashable { - return self.contains { other.contains($0) } - } -} diff --git a/Sources/SwiftExtensions/TransitiveClosure.swift b/Sources/SwiftExtensions/TransitiveClosure.swift deleted file mode 100644 index 96b748f62..000000000 --- a/Sources/SwiftExtensions/TransitiveClosure.swift +++ /dev/null @@ -1,24 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -@_spi(SourceKitLSP) public func transitiveClosure(of values: some Collection, successors: (T) -> Set) -> Set { - var transitiveClosure: Set = [] - var workList = Array(values) - while let element = workList.popLast() { - for successor in successors(element) { - if transitiveClosure.insert(successor).inserted { - workList.append(successor) - } - } - } - return transitiveClosure -} diff --git a/Sources/SwiftExtensions/AsyncQueue.swift b/Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift similarity index 98% rename from Sources/SwiftExtensions/AsyncQueue.swift rename to Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift index 9ee6da913..b26c9d7f5 100644 --- a/Sources/SwiftExtensions/AsyncQueue.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift @@ -90,7 +90,7 @@ public final class AsyncQueue: Sendable { /// finish execution before the barrier is executed and all tasks that are /// added later will wait until the barrier finishes execution. @discardableResult - @_spi(SourceKitLSP) public func async( + public func async( priority: TaskPriority? = nil, metadata: TaskMetadata, @_inheritActorContext operation: @escaping @Sendable () async -> Success @@ -111,7 +111,7 @@ public final class AsyncQueue: Sendable { /// /// - Important: The caller is responsible for handling any errors thrown from /// the operation by awaiting the result of the returned task. - @_spi(SourceKitLSP) public func asyncThrowing( +public func asyncThrowing( priority: TaskPriority? = nil, metadata: TaskMetadata, @_inheritActorContext operation: @escaping @Sendable () async throws -> Success diff --git a/Sources/SwiftExtensions/AsyncUtils.swift b/Sources/ToolsProtocolsSwiftExtensions/AsyncUtils.swift similarity index 100% rename from Sources/SwiftExtensions/AsyncUtils.swift rename to Sources/ToolsProtocolsSwiftExtensions/AsyncUtils.swift diff --git a/Sources/SwiftExtensions/Atomics.swift b/Sources/ToolsProtocolsSwiftExtensions/Atomics.swift similarity index 100% rename from Sources/SwiftExtensions/Atomics.swift rename to Sources/ToolsProtocolsSwiftExtensions/Atomics.swift diff --git a/Sources/ToolsProtocolsSwiftExtensions/CMakeLists.txt b/Sources/ToolsProtocolsSwiftExtensions/CMakeLists.txt new file mode 100644 index 000000000..2ce1b4ef7 --- /dev/null +++ b/Sources/ToolsProtocolsSwiftExtensions/CMakeLists.txt @@ -0,0 +1,31 @@ +set(sources + AsyncQueue.swift + AsyncUtils.swift + Atomics.swift + Collection+Only.swift + Duration+Seconds.swift + FileManagerExtensions.swift + NSLock+WithLock.swift + PipeAsStringHandler.swift + Task+WithPriorityChangedHandler.swift + ThreadSafeBox.swift + URLExtensions.swift +) + +add_library(ToolsProtocolsSwiftExtensions STATIC ${sources}) +set_target_properties(ToolsProtocolsSwiftExtensions PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_link_libraries(ToolsProtocolsSwiftExtensions PUBLIC + ToolsProtocolsCAtomics) +target_link_libraries(ToolsProtocolsSwiftExtensions PRIVATE + $<$>:Foundation>) + +add_library(ToolsProtocolsSwiftExtensionsForPlugin STATIC ${sources}) +set_target_properties(ToolsProtocolsSwiftExtensionsForPlugin PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_link_libraries(ToolsProtocolsSwiftExtensionsForPlugin PUBLIC + ToolsProtocolsCAtomics) +target_link_libraries(ToolsProtocolsSwiftExtensionsForPlugin PRIVATE + $<$>:Foundation>) + +set_property(GLOBAL APPEND PROPERTY SWIFTTOOLSPROTOCOLS_EXPORTS ToolsProtocolsSwiftExtensions) diff --git a/Sources/SwiftExtensions/Collection+Only.swift b/Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift similarity index 100% rename from Sources/SwiftExtensions/Collection+Only.swift rename to Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift diff --git a/Sources/SwiftExtensions/Duration+Seconds.swift b/Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift similarity index 100% rename from Sources/SwiftExtensions/Duration+Seconds.swift rename to Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift diff --git a/Sources/SwiftExtensions/FileManagerExtensions.swift b/Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift similarity index 100% rename from Sources/SwiftExtensions/FileManagerExtensions.swift rename to Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift diff --git a/Sources/SwiftExtensions/NSLock+WithLock.swift b/Sources/ToolsProtocolsSwiftExtensions/NSLock+WithLock.swift similarity index 100% rename from Sources/SwiftExtensions/NSLock+WithLock.swift rename to Sources/ToolsProtocolsSwiftExtensions/NSLock+WithLock.swift diff --git a/Sources/SwiftExtensions/PipeAsStringHandler.swift b/Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift similarity index 100% rename from Sources/SwiftExtensions/PipeAsStringHandler.swift rename to Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift diff --git a/Sources/SwiftExtensions/Task+WithPriorityChangedHandler.swift b/Sources/ToolsProtocolsSwiftExtensions/Task+WithPriorityChangedHandler.swift similarity index 100% rename from Sources/SwiftExtensions/Task+WithPriorityChangedHandler.swift rename to Sources/ToolsProtocolsSwiftExtensions/Task+WithPriorityChangedHandler.swift diff --git a/Sources/SwiftExtensions/ThreadSafeBox.swift b/Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift similarity index 100% rename from Sources/SwiftExtensions/ThreadSafeBox.swift rename to Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift diff --git a/Sources/SwiftExtensions/URLExtensions.swift b/Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift similarity index 100% rename from Sources/SwiftExtensions/URLExtensions.swift rename to Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift diff --git a/Sources/ToolsProtocolsTestSupport/RepeatUntilExpectedResult.swift b/Sources/ToolsProtocolsTestSupport/RepeatUntilExpectedResult.swift index b9600300f..4ed718f4e 100644 --- a/Sources/ToolsProtocolsTestSupport/RepeatUntilExpectedResult.swift +++ b/Sources/ToolsProtocolsTestSupport/RepeatUntilExpectedResult.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// import SKLogging -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions import XCTest /// Runs the body repeatedly once per second until it returns `true`, giving up after `timeout`. diff --git a/Sources/ToolsProtocolsTestSupport/TestJSONRPCConnection.swift b/Sources/ToolsProtocolsTestSupport/TestJSONRPCConnection.swift index fbacdac3a..7680cfce3 100644 --- a/Sources/ToolsProtocolsTestSupport/TestJSONRPCConnection.swift +++ b/Sources/ToolsProtocolsTestSupport/TestJSONRPCConnection.swift @@ -12,7 +12,7 @@ public import LanguageServerProtocol package import LanguageServerProtocolTransport -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions import XCTest package import class Foundation.Pipe diff --git a/Sources/_SwiftExtensionsForPlugin b/Sources/_SwiftExtensionsForPlugin deleted file mode 120000 index 6f5bb646e..000000000 --- a/Sources/_SwiftExtensionsForPlugin +++ /dev/null @@ -1 +0,0 @@ -SwiftExtensions \ No newline at end of file diff --git a/Sources/_ToolsProtocolsSwiftExtensionsForPlugin b/Sources/_ToolsProtocolsSwiftExtensionsForPlugin new file mode 120000 index 000000000..c20c44209 --- /dev/null +++ b/Sources/_ToolsProtocolsSwiftExtensionsForPlugin @@ -0,0 +1 @@ +ToolsProtocolsSwiftExtensions \ No newline at end of file diff --git a/Tests/SwiftExtensionsTests/ResultExtensionsTests.swift b/Tests/SwiftExtensionsTests/ResultExtensionsTests.swift deleted file mode 100644 index 881f1bb9e..000000000 --- a/Tests/SwiftExtensionsTests/ResultExtensionsTests.swift +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2018 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 -// -//===----------------------------------------------------------------------===// - -@_spi(SourceKitLSP) import SwiftExtensions -import XCTest - -final class ResultExtensionsTests: XCTestCase { - func testResultProjection() { - enum MyError: Error, Equatable { - case err1, err2 - } - typealias MyResult = Swift.Result - - XCTAssertEqual(MyResult.success(1).success, 1) - XCTAssertNil(MyResult.failure(.err1).success) - XCTAssertNil(MyResult.success(1).failure) - XCTAssertEqual(MyResult.failure(.err1).failure, .err1) - } -} diff --git a/Tests/SwiftExtensionsTests/AsyncUtilsTests.swift b/Tests/ToolsProtocolsSwiftExtensionsTests/AsyncUtilsTests.swift similarity index 97% rename from Tests/SwiftExtensionsTests/AsyncUtilsTests.swift rename to Tests/ToolsProtocolsSwiftExtensionsTests/AsyncUtilsTests.swift index 37659b655..3e29f8025 100644 --- a/Tests/SwiftExtensionsTests/AsyncUtilsTests.swift +++ b/Tests/ToolsProtocolsSwiftExtensionsTests/AsyncUtilsTests.swift @@ -12,7 +12,7 @@ @_spi(SourceKitLSP) import SKLogging import ToolsProtocolsTestSupport -@_spi(SourceKitLSP) import SwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions import XCTest #if os(Windows)