Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Sources/SKLogging/NonDarwinLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

@_spi(SourceKitLSP) public import ToolsProtocolsSwiftExtensions
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions

#if canImport(Darwin)
import Foundation
Expand All @@ -23,7 +23,7 @@ import Foundation

@_spi(SourceKitLSP) public enum LogConfig {
/// The globally set log level
@_spi(SourceKitLSP) public static let logLevel = ThreadSafeBox<NonDarwinLogLevel>(
private static let _logLevel = ThreadSafeBox<NonDarwinLogLevel>(
initialValue: {
if let envVar = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_LOG_LEVEL"],
let logLevel = NonDarwinLogLevel(envVar)
Expand All @@ -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<NonDarwinLogPrivacy>(
private static let _privacyLevel = ThreadSafeBox<NonDarwinLogPrivacy>(
initialValue: {
if let envVar = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_LOG_PRIVACY_LEVEL"],
let privacyLevel = NonDarwinLogPrivacy(envVar)
Expand All @@ -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
Expand Down Expand Up @@ -302,7 +320,7 @@ private let loggingQueue = AsyncQueue<Serial>()
/// 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
Expand All @@ -326,8 +344,8 @@ private let loggingQueue = AsyncQueue<Serial>()
) {
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
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SKLogging/SetGlobalLogFileHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intentionally increase the import level here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is needed to fix a break in the Linux build

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: What was the issue?

#endif

#if os(Windows)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@
//
//===----------------------------------------------------------------------===//

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
}
return self.fileExists(atPath: filePath)
}

/// 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Serial>()
Expand All @@ -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
}

Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/ToolsProtocolsSwiftExtensions/ThreadSafeBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Sendable>: @unchecked Sendable {
package class ThreadSafeBox<T: Sendable>: @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
Expand All @@ -39,19 +39,19 @@ import Foundation
}
}

@_spi(SourceKitLSP) public init(initialValue: T) {
package init(initialValue: T) {
_value = initialValue
}

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

/// 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<U>() -> T where U? == T {
package func takeValue<U>() -> T where U? == T {
lock.withLock {
guard let value = self._value else { return nil }
self._value = nil
Expand Down
10 changes: 5 additions & 5 deletions Sources/ToolsProtocolsSwiftExtensions/URLExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

public import Foundation
package import Foundation

#if os(Windows)
import WinSDK
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
}
Loading