Skip to content

Commit

Permalink
Swift format for consistent whitespace (#15)
Browse files Browse the repository at this point in the history
* Add swift-format.json

* Add format script

* Automatically formatted source code
  • Loading branch information
koliyo authored Dec 9, 2023
1 parent 542c412 commit 9ae95d8
Show file tree
Hide file tree
Showing 57 changed files with 2,938 additions and 2,631 deletions.
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

0 comments on commit 9ae95d8

Please sign in to comment.