Skip to content

Commit c21a4e7

Browse files
committed
Expose less SPI from ToolsProtocolsSwiftExtensions
1 parent 30084e9 commit c21a4e7

File tree

9 files changed

+46
-28
lines changed

9 files changed

+46
-28
lines changed

Sources/SKLogging/NonDarwinLogging.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_spi(SourceKitLSP) public import ToolsProtocolsSwiftExtensions
13+
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions
1414

1515
#if canImport(Darwin)
1616
import Foundation
@@ -23,7 +23,7 @@ import Foundation
2323

2424
@_spi(SourceKitLSP) public enum LogConfig {
2525
/// The globally set log level
26-
@_spi(SourceKitLSP) public static let logLevel = ThreadSafeBox<NonDarwinLogLevel>(
26+
private static let _logLevel = ThreadSafeBox<NonDarwinLogLevel>(
2727
initialValue: {
2828
if let envVar = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_LOG_LEVEL"],
2929
let logLevel = NonDarwinLogLevel(envVar)
@@ -38,8 +38,17 @@ import Foundation
3838
}()
3939
)
4040

41+
@_spi(SourceKitLSP) public static var logLevel: NonDarwinLogLevel {
42+
get {
43+
_logLevel.value
44+
}
45+
set {
46+
_logLevel.value = newValue
47+
}
48+
}
49+
4150
/// The globally set privacy level
42-
@_spi(SourceKitLSP) public static let privacyLevel = ThreadSafeBox<NonDarwinLogPrivacy>(
51+
private static let _privacyLevel = ThreadSafeBox<NonDarwinLogPrivacy>(
4352
initialValue: {
4453
if let envVar = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_LOG_PRIVACY_LEVEL"],
4554
let privacyLevel = NonDarwinLogPrivacy(envVar)
@@ -53,6 +62,15 @@ import Foundation
5362
#endif
5463
}()
5564
)
65+
66+
@_spi(SourceKitLSP) public static var privacyLevel: NonDarwinLogPrivacy {
67+
get {
68+
_privacyLevel.value
69+
}
70+
set {
71+
_privacyLevel.value = newValue
72+
}
73+
}
5674
}
5775

5876
/// A type that is API-compatible to `OSLogType` for all uses within
@@ -302,7 +320,7 @@ private let loggingQueue = AsyncQueue<Serial>()
302320
/// not available.
303321
///
304322
/// `overrideLogHandler` allows capturing of the logged messages for testing purposes.
305-
@_spi(SourceKitLSP) public struct NonDarwinLogger: Sendable {
323+
public struct NonDarwinLogger: Sendable {
306324
private let subsystem: String
307325
private let category: String
308326
private let logLevel: NonDarwinLogLevel
@@ -326,8 +344,8 @@ private let loggingQueue = AsyncQueue<Serial>()
326344
) {
327345
self.subsystem = subsystem
328346
self.category = category
329-
self.logLevel = logLevel ?? LogConfig.logLevel.value
330-
self.privacyLevel = privacyLevel ?? LogConfig.privacyLevel.value
347+
self.logLevel = logLevel ?? LogConfig.logLevel
348+
self.privacyLevel = privacyLevel ?? LogConfig.privacyLevel
331349
self.overrideLogHandler = overrideLogHandler
332350
}
333351

Sources/SKLogging/SetGlobalLogFileHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import ToolsProtocolsSwiftExtensions
1717
public import Foundation
1818
#else
1919
// TODO: @preconcurrency needed because stderr is not sendable on Linux https://github.com/swiftlang/swift/issues/75601
20-
@preconcurrency package import Foundation
20+
@preconcurrency public import Foundation
2121
#endif
2222

2323
#if os(Windows)

Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public protocol DependencyTracker: Sendable, Hashable {
3535
/// A dependency tracker where each task depends on every other, i.e. a serial
3636
/// queue.
3737
public struct Serial: DependencyTracker {
38-
@_spi(SourceKitLSP) public func isDependency(of other: Serial) -> Bool {
38+
public func isDependency(of other: Serial) -> Bool {
3939
return true
4040
}
4141
}

Sources/ToolsProtocolsSwiftExtensions/Collection+Only.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_spi(SourceKitLSP) public extension Collection {
13+
package extension Collection {
1414
/// If the collection contains a single element, return it, otherwise `nil`.
1515
var only: Element? {
1616
if !isEmpty && index(after: startIndex) == endIndex {

Sources/ToolsProtocolsSwiftExtensions/Duration+Seconds.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
extension Duration {
14-
@_spi(SourceKitLSP) public var seconds: Double {
14+
package var seconds: Double {
1515
return Double(self.components.attoseconds) / 1_000_000_000_000_000_000 + Double(self.components.seconds)
1616
}
1717
}

Sources/ToolsProtocolsSwiftExtensions/FileManagerExtensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public import Foundation
13+
package import Foundation
1414

1515
extension FileManager {
1616
/// Same as `fileExists(atPath:)` but takes a `URL` instead of a `String`.
17-
@_spi(SourceKitLSP) public func fileExists(at url: URL) -> Bool {
17+
package func fileExists(at url: URL) -> Bool {
1818
guard let filePath = try? url.filePath else {
1919
return false
2020
}
2121
return self.fileExists(atPath: filePath)
2222
}
2323

2424
/// Returns `true` if an entry exists in the file system at the given URL and that entry is a directory.
25-
@_spi(SourceKitLSP) public func isDirectory(at url: URL) -> Bool {
25+
package func isDirectory(at url: URL) -> Bool {
2626
var isDirectory: ObjCBool = false
2727
return self.fileExists(atPath: url.path, isDirectory: &isDirectory) && isDirectory.boolValue
2828
}
2929

3030
/// Returns `true` if an entry exists in the file system at the given URL and that entry is a file, ie. not a
3131
/// directory.
32-
@_spi(SourceKitLSP) public func isFile(at url: URL) -> Bool {
32+
package func isFile(at url: URL) -> Bool {
3333
var isDirectory: ObjCBool = false
3434
return self.fileExists(atPath: url.path, isDirectory: &isDirectory) && !isDirectory.boolValue
3535
}

Sources/ToolsProtocolsSwiftExtensions/PipeAsStringHandler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public import Foundation
13+
package import Foundation
1414

1515
/// Gathers data from a stdout or stderr pipe. When it has accumulated a full line, calls the handler to handle the
1616
/// string.
17-
@_spi(SourceKitLSP) public actor PipeAsStringHandler {
17+
package actor PipeAsStringHandler {
1818
/// Queue on which all data from the pipe will be handled. This allows us to have a
1919
/// nonisolated `handle` function but ensure that data gets processed in order.
2020
private let queue = AsyncQueue<Serial>()
@@ -23,7 +23,7 @@ public import Foundation
2323
/// The closure that actually handles
2424
private let handler: @Sendable (String) -> Void
2525

26-
@_spi(SourceKitLSP) public init(handler: @escaping @Sendable (String) -> Void) {
26+
package init(handler: @escaping @Sendable (String) -> Void) {
2727
self.handler = handler
2828
}
2929

@@ -49,7 +49,7 @@ public import Foundation
4949
}
5050
}
5151

52-
@_spi(SourceKitLSP) public nonisolated func handleDataFromPipe(_ newData: Data) {
52+
package nonisolated func handleDataFromPipe(_ newData: Data) {
5353
queue.async {
5454
await self.handleDataFromPipeImpl(newData)
5555
}

Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import Foundation
1515
/// A thread safe container that contains a value of type `T`.
1616
///
1717
/// - Note: Unchecked sendable conformance because value is guarded by a lock.
18-
@_spi(SourceKitLSP) public class ThreadSafeBox<T: Sendable>: @unchecked Sendable {
18+
package class ThreadSafeBox<T: Sendable>: @unchecked Sendable {
1919
/// Lock guarding `_value`.
2020
private let lock = NSLock()
2121

2222
private var _value: T
2323

24-
@_spi(SourceKitLSP) public var value: T {
24+
package var value: T {
2525
get {
2626
return lock.withLock {
2727
return _value
@@ -39,19 +39,19 @@ import Foundation
3939
}
4040
}
4141

42-
@_spi(SourceKitLSP) public init(initialValue: T) {
42+
package init(initialValue: T) {
4343
_value = initialValue
4444
}
4545

46-
@_spi(SourceKitLSP) public func withLock<Result>(_ body: (inout T) throws -> Result) rethrows -> Result {
46+
package func withLock<Result>(_ body: (inout T) throws -> Result) rethrows -> Result {
4747
return try lock.withLock {
4848
return try body(&_value)
4949
}
5050
}
5151

5252
/// If the value in the box is an optional, return it and reset it to `nil`
5353
/// in an atomic operation.
54-
@_spi(SourceKitLSP) public func takeValue<U>() -> T where U? == T {
54+
package func takeValue<U>() -> T where U? == T {
5555
lock.withLock {
5656
guard let value = self._value else { return nil }
5757
self._value = nil

Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public import Foundation
13+
package import Foundation
1414

1515
#if os(Windows)
1616
import WinSDK
@@ -37,7 +37,7 @@ extension URL {
3737
/// path by stripping away `private` prefixes. Since sourcekitd is not performing this standardization, using
3838
/// `resolvingSymlinksInPath` can lead to slightly mismatched URLs between the sourcekit-lsp response and the test
3939
/// assertion.
40-
@_spi(SourceKitLSP) public var realpath: URL {
40+
package var realpath: URL {
4141
get throws {
4242
#if canImport(Darwin)
4343
return try self.filePath.withCString { path in
@@ -63,7 +63,7 @@ extension URL {
6363
/// - It throws an error when called on a non-file URL.
6464
///
6565
/// `filePath` should generally be preferred over `path` when dealing with file URLs.
66-
@_spi(SourceKitLSP) public var filePath: String {
66+
package var filePath: String {
6767
get throws {
6868
guard self.isFileURL else {
6969
throw FilePathError.noFileURL(self)
@@ -89,7 +89,7 @@ extension URL {
8989

9090
/// Assuming this URL is a file URL, checks if it looks like a root path. This is a string check, ie. the return
9191
/// value for a path of `"/foo/.."` would be `false`. An error will be thrown is this is a non-file URL.
92-
@_spi(SourceKitLSP) public var isRoot: Bool {
92+
package var isRoot: Bool {
9393
get throws {
9494
let checkPath = try filePath
9595
#if os(Windows)
@@ -101,7 +101,7 @@ extension URL {
101101
}
102102

103103
/// Returns true if the path of `self` starts with the path in `other`.
104-
@_spi(SourceKitLSP) public func isDescendant(of other: URL) -> Bool {
104+
package func isDescendant(of other: URL) -> Bool {
105105
return self.pathComponents.dropLast().starts(with: other.pathComponents)
106106
}
107107
}

0 commit comments

Comments
 (0)