Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift format for consistent whitespace #15

Merged
merged 3 commits into from
Dec 9, 2023
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
7 changes: 7 additions & 0 deletions .swift-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"indentation" : {
"tabs" : 1
},
"tabWidth" : 4,
"version" : 1
}
81 changes: 43 additions & 38 deletions Sources/LanguageServerProtocol/Additions/AsyncStreamPolyfill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,50 @@ import Foundation

#if compiler(<5.9)

// @available(SwiftStdlib 5.1, *)
extension AsyncStream {
/// Initializes a new ``AsyncStream`` and an ``AsyncStream/Continuation``.
///
/// - Parameters:
/// - elementType: The element type of the stream.
/// - limit: The buffering policy that the stream should use.
/// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the
/// producer while the stream should be passed to the consumer.
// @backDeployed(before: SwiftStdlib 5.9)
static func makeStream(
of elementType: Element.Type = Element.self,
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded
) -> (stream: AsyncStream<Element>, continuation: AsyncStream<Element>.Continuation) {
var continuation: AsyncStream<Element>.Continuation!
let stream = AsyncStream<Element>(bufferingPolicy: limit) { continuation = $0 }
return (stream: stream, continuation: continuation!)
// @available(SwiftStdlib 5.1, *)
extension AsyncStream {
/// Initializes a new ``AsyncStream`` and an ``AsyncStream/Continuation``.
///
/// - Parameters:
/// - elementType: The element type of the stream.
/// - limit: The buffering policy that the stream should use.
/// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the
/// producer while the stream should be passed to the consumer.
// @backDeployed(before: SwiftStdlib 5.9)
static func makeStream(
of elementType: Element.Type = Element.self,
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded
) -> (stream: AsyncStream<Element>, continuation: AsyncStream<Element>.Continuation) {
var continuation: AsyncStream<Element>.Continuation!
let stream = AsyncStream<Element>(bufferingPolicy: limit) { continuation = $0 }
return (stream: stream, continuation: continuation!)
}
}
}

// @available(SwiftStdlib 5.1, *)
extension AsyncThrowingStream {
/// Initializes a new ``AsyncThrowingStream`` and an ``AsyncThrowingStream/Continuation``.
///
/// - Parameters:
/// - elementType: The element type of the stream.
/// - failureType: The failure type of the stream.
/// - limit: The buffering policy that the stream should use.
/// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the
/// producer while the stream should be passed to the consumer.
// @backDeployed(before: SwiftStdlib 5.9)
static func makeStream(
of elementType: Element.Type = Element.self,
throwing failureType: Failure.Type = Failure.self,
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded
) -> (stream: AsyncThrowingStream<Element, Failure>, continuation: AsyncThrowingStream<Element, Failure>.Continuation) where Failure == Error {
var continuation: AsyncThrowingStream<Element, Failure>.Continuation!
let stream = AsyncThrowingStream<Element, Failure>(bufferingPolicy: limit) { continuation = $0 }
return (stream: stream, continuation: continuation!)
// @available(SwiftStdlib 5.1, *)
extension AsyncThrowingStream {
/// Initializes a new ``AsyncThrowingStream`` and an ``AsyncThrowingStream/Continuation``.
///
/// - Parameters:
/// - elementType: The element type of the stream.
/// - failureType: The failure type of the stream.
/// - limit: The buffering policy that the stream should use.
/// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the
/// producer while the stream should be passed to the consumer.
// @backDeployed(before: SwiftStdlib 5.9)
static func makeStream(
of elementType: Element.Type = Element.self,
throwing failureType: Failure.Type = Failure.self,
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded
) -> (
stream: AsyncThrowingStream<Element, Failure>,
continuation: AsyncThrowingStream<Element, Failure>.Continuation
) where Failure == Error {
var continuation: AsyncThrowingStream<Element, Failure>.Continuation!
let stream = AsyncThrowingStream<Element, Failure>(bufferingPolicy: limit) {
continuation = $0
}
return (stream: stream, continuation: continuation!)
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import Foundation

extension NSRegularExpression {
func matches(inFullString string: String, options: NSRegularExpression.MatchingOptions = []) -> [NSTextCheckingResult] {
let range = NSMakeRange(0, string.utf16.count)
func matches(inFullString string: String, options: NSRegularExpression.MatchingOptions = [])
-> [NSTextCheckingResult]
{
let range = NSMakeRange(0, string.utf16.count)

return matches(in: string, options: options, range: range)
}
return matches(in: string, options: options, range: range)
}
}

extension NSTextCheckingResult {
func range(at index: Int, in string: String) -> Range<String.Index>? {
let nsRange = range(at: index)
func range(at index: Int, in string: String) -> Range<String.Index>? {
let nsRange = range(at: index)

return Range(nsRange, in: string)
}
return Range(nsRange, in: string)
}

func stringValue(at index: Int, in string: String) -> Substring? {
guard let captureRange = range(at: index, in: string) else {
return nil
}
func stringValue(at index: Int, in string: String) -> Substring? {
guard let captureRange = range(at: index, in: string) else {
return nil
}

return string[captureRange]
}
return string[captureRange]
}

func intValue(at index: Int, in string: String) -> Int? {
return stringValue(at: index, in: string).flatMap { Int($0) }
}
func intValue(at index: Int, in string: String) -> Int? {
return stringValue(at: index, in: string).flatMap { Int($0) }
}
}
Loading