diff --git a/Sources/SKLogging/NonDarwinLogging.swift b/Sources/SKLogging/NonDarwinLogging.swift index c93c0500..33648c01 100644 --- a/Sources/SKLogging/NonDarwinLogging.swift +++ b/Sources/SKLogging/NonDarwinLogging.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -@_spi(SourceKitLSP) public import ToolsProtocolsSwiftExtensions +@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions #if canImport(Darwin) import Foundation @@ -23,7 +23,7 @@ import Foundation @_spi(SourceKitLSP) public enum LogConfig { /// The globally set log level - @_spi(SourceKitLSP) public static let logLevel = ThreadSafeBox( + private static let _logLevel = ThreadSafeBox( initialValue: { if let envVar = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_LOG_LEVEL"], let logLevel = NonDarwinLogLevel(envVar) @@ -38,8 +38,17 @@ import Foundation }() ) + @_spi(SourceKitLSP) public static var logLevel: NonDarwinLogLevel { + get { + _logLevel.value + } + set { + _logLevel.value = newValue + } + } + /// The globally set privacy level - @_spi(SourceKitLSP) public static let privacyLevel = ThreadSafeBox( + private static let _privacyLevel = ThreadSafeBox( initialValue: { if let envVar = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_LOG_PRIVACY_LEVEL"], let privacyLevel = NonDarwinLogPrivacy(envVar) @@ -53,6 +62,15 @@ import Foundation #endif }() ) + + @_spi(SourceKitLSP) public static var privacyLevel: NonDarwinLogPrivacy { + get { + _privacyLevel.value + } + set { + _privacyLevel.value = newValue + } + } } /// A type that is API-compatible to `OSLogType` for all uses within @@ -302,7 +320,7 @@ private let loggingQueue = AsyncQueue() /// not available. /// /// `overrideLogHandler` allows capturing of the logged messages for testing purposes. -@_spi(SourceKitLSP) public struct NonDarwinLogger: Sendable { +public struct NonDarwinLogger: Sendable { private let subsystem: String private let category: String private let logLevel: NonDarwinLogLevel @@ -326,8 +344,8 @@ private let loggingQueue = AsyncQueue() ) { self.subsystem = subsystem self.category = category - self.logLevel = logLevel ?? LogConfig.logLevel.value - self.privacyLevel = privacyLevel ?? LogConfig.privacyLevel.value + self.logLevel = logLevel ?? LogConfig.logLevel + self.privacyLevel = privacyLevel ?? LogConfig.privacyLevel self.overrideLogHandler = overrideLogHandler } diff --git a/Sources/SKLogging/SetGlobalLogFileHandler.swift b/Sources/SKLogging/SetGlobalLogFileHandler.swift index ac13ddd9..bbe1071c 100644 --- a/Sources/SKLogging/SetGlobalLogFileHandler.swift +++ b/Sources/SKLogging/SetGlobalLogFileHandler.swift @@ -17,7 +17,7 @@ import ToolsProtocolsSwiftExtensions public import Foundation #else // TODO: @preconcurrency needed because stderr is not sendable on Linux https://github.com/swiftlang/swift/issues/75601 -@preconcurrency package import Foundation +@preconcurrency public import Foundation #endif #if os(Windows) diff --git a/Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift b/Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift index b26c9d7f..cc394e93 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift @@ -35,7 +35,7 @@ public protocol DependencyTracker: Sendable, Hashable { /// A dependency tracker where each task depends on every other, i.e. a serial /// queue. public struct Serial: DependencyTracker { - @_spi(SourceKitLSP) public func isDependency(of other: Serial) -> Bool { + public func isDependency(of other: Serial) -> Bool { return true } } diff --git a/Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift b/Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift index 5c6f1fec..d00b91ab 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -@_spi(SourceKitLSP) public extension Collection { +package extension Collection { /// If the collection contains a single element, return it, otherwise `nil`. var only: Element? { if !isEmpty && index(after: startIndex) == endIndex { diff --git a/Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift b/Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift index 7e469ac9..69245ded 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// extension Duration { - @_spi(SourceKitLSP) public var seconds: Double { + package var seconds: Double { return Double(self.components.attoseconds) / 1_000_000_000_000_000_000 + Double(self.components.seconds) } } diff --git a/Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift b/Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift index 45105e6a..80dfe587 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// -public import Foundation +package import Foundation extension FileManager { /// Same as `fileExists(atPath:)` but takes a `URL` instead of a `String`. - @_spi(SourceKitLSP) public func fileExists(at url: URL) -> Bool { + package func fileExists(at url: URL) -> Bool { guard let filePath = try? url.filePath else { return false } @@ -22,14 +22,14 @@ extension FileManager { } /// Returns `true` if an entry exists in the file system at the given URL and that entry is a directory. - @_spi(SourceKitLSP) public func isDirectory(at url: URL) -> Bool { + package func isDirectory(at url: URL) -> Bool { var isDirectory: ObjCBool = false return self.fileExists(atPath: url.path, isDirectory: &isDirectory) && isDirectory.boolValue } /// Returns `true` if an entry exists in the file system at the given URL and that entry is a file, ie. not a /// directory. - @_spi(SourceKitLSP) public func isFile(at url: URL) -> Bool { + package func isFile(at url: URL) -> Bool { var isDirectory: ObjCBool = false return self.fileExists(atPath: url.path, isDirectory: &isDirectory) && !isDirectory.boolValue } diff --git a/Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift b/Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift index a2d38811..3d12dba7 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// -public import Foundation +package import Foundation /// Gathers data from a stdout or stderr pipe. When it has accumulated a full line, calls the handler to handle the /// string. -@_spi(SourceKitLSP) public actor PipeAsStringHandler { +package actor PipeAsStringHandler { /// Queue on which all data from the pipe will be handled. This allows us to have a /// nonisolated `handle` function but ensure that data gets processed in order. private let queue = AsyncQueue() @@ -23,7 +23,7 @@ public import Foundation /// The closure that actually handles private let handler: @Sendable (String) -> Void - @_spi(SourceKitLSP) public init(handler: @escaping @Sendable (String) -> Void) { + package init(handler: @escaping @Sendable (String) -> Void) { self.handler = handler } @@ -49,7 +49,7 @@ public import Foundation } } - @_spi(SourceKitLSP) public nonisolated func handleDataFromPipe(_ newData: Data) { + package nonisolated func handleDataFromPipe(_ newData: Data) { queue.async { await self.handleDataFromPipeImpl(newData) } diff --git a/Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift b/Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift index 8bf6799c..bc0ec9be 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift @@ -15,13 +15,13 @@ import Foundation /// A thread safe container that contains a value of type `T`. /// /// - Note: Unchecked sendable conformance because value is guarded by a lock. -@_spi(SourceKitLSP) public class ThreadSafeBox: @unchecked Sendable { +package class ThreadSafeBox: @unchecked Sendable { /// Lock guarding `_value`. private let lock = NSLock() private var _value: T - @_spi(SourceKitLSP) public var value: T { + package var value: T { get { return lock.withLock { return _value @@ -39,11 +39,11 @@ import Foundation } } - @_spi(SourceKitLSP) public init(initialValue: T) { + package init(initialValue: T) { _value = initialValue } - @_spi(SourceKitLSP) public func withLock(_ body: (inout T) throws -> Result) rethrows -> Result { + package func withLock(_ body: (inout T) throws -> Result) rethrows -> Result { return try lock.withLock { return try body(&_value) } @@ -51,7 +51,7 @@ import Foundation /// If the value in the box is an optional, return it and reset it to `nil` /// in an atomic operation. - @_spi(SourceKitLSP) public func takeValue() -> T where U? == T { + package func takeValue() -> T where U? == T { lock.withLock { guard let value = self._value else { return nil } self._value = nil diff --git a/Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift b/Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift index feef4689..629313ae 100644 --- a/Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift +++ b/Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -public import Foundation +package import Foundation #if os(Windows) import WinSDK @@ -37,7 +37,7 @@ extension URL { /// path by stripping away `private` prefixes. Since sourcekitd is not performing this standardization, using /// `resolvingSymlinksInPath` can lead to slightly mismatched URLs between the sourcekit-lsp response and the test /// assertion. - @_spi(SourceKitLSP) public var realpath: URL { + package var realpath: URL { get throws { #if canImport(Darwin) return try self.filePath.withCString { path in @@ -63,7 +63,7 @@ extension URL { /// - It throws an error when called on a non-file URL. /// /// `filePath` should generally be preferred over `path` when dealing with file URLs. - @_spi(SourceKitLSP) public var filePath: String { + package var filePath: String { get throws { guard self.isFileURL else { throw FilePathError.noFileURL(self) @@ -89,7 +89,7 @@ extension URL { /// Assuming this URL is a file URL, checks if it looks like a root path. This is a string check, ie. the return /// value for a path of `"/foo/.."` would be `false`. An error will be thrown is this is a non-file URL. - @_spi(SourceKitLSP) public var isRoot: Bool { + package var isRoot: Bool { get throws { let checkPath = try filePath #if os(Windows) @@ -101,7 +101,7 @@ extension URL { } /// Returns true if the path of `self` starts with the path in `other`. - @_spi(SourceKitLSP) public func isDescendant(of other: URL) -> Bool { + package func isDescendant(of other: URL) -> Bool { return self.pathComponents.dropLast().starts(with: other.pathComponents) } }