Skip to content

Commit af40849

Browse files
committed
Format sources with swift-format
1 parent 9cd33a6 commit af40849

15 files changed

+91
-62
lines changed

Sources/SKCore/CompilationDatabaseBuildSystem.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ public actor CompilationDatabaseBuildSystem {
7373
return nil
7474
}
7575

76-
public init?(projectRoot: AbsolutePath? = nil, searchPaths: [RelativePath], fileSystem: FileSystem = localFileSystem) {
76+
public init?(
77+
projectRoot: AbsolutePath? = nil,
78+
searchPaths: [RelativePath],
79+
fileSystem: FileSystem = localFileSystem
80+
) {
7781
self.fileSystem = fileSystem
7882
self.projectRoot = projectRoot
7983
self.searchPaths = searchPaths

Sources/SKCore/FileBuildSettings.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public extension FileBuildSettings {
7878
arguments.insert("-xobjective-c++", at: 0)
7979
}
8080
}
81-
return FileBuildSettings(compilerArguments: arguments, workingDirectory: self.workingDirectory, isFallback: self.isFallback)
81+
return FileBuildSettings(
82+
compilerArguments: arguments,
83+
workingDirectory: self.workingDirectory,
84+
isFallback: self.isFallback
85+
)
8286
}
8387
}

Sources/SKSupport/AsyncUtils.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,20 @@ public func withCancellableCheckedThrowingContinuation<Handle, Result>(
4848
}
4949
}
5050

51-
return try await withTaskCancellationHandler(operation: {
52-
try Task.checkCancellation()
53-
return try await withCheckedThrowingContinuation { continuation in
54-
handleWrapper.value = operation(continuation)
51+
return try await withTaskCancellationHandler(
52+
operation: {
53+
try Task.checkCancellation()
54+
return try await withCheckedThrowingContinuation { continuation in
55+
handleWrapper.value = operation(continuation)
5556

56-
// Check if the task was cancelled. This ensures we send a
57-
// CancelNotification even if the task gets cancelled after we register
58-
// the cancellation handler but before we set the `requestID`.
59-
if Task.isCancelled {
60-
callCancel()
57+
// Check if the task was cancelled. This ensures we send a
58+
// CancelNotification even if the task gets cancelled after we register
59+
// the cancellation handler but before we set the `requestID`.
60+
if Task.isCancelled {
61+
callCancel()
62+
}
6163
}
62-
}
63-
}, onCancel: callCancel)
64+
},
65+
onCancel: callCancel
66+
)
6467
}

Sources/SKTestSupport/IndexedSingleSwiftFileWorkspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct IndexedSingleSwiftFileWorkspace {
5757
var compilerArguments: [String] = [
5858
testFileURL.path,
5959
"-index-store-path", indexURL.path,
60-
"-typecheck"
60+
"-typecheck",
6161
]
6262
if !indexSystemModules {
6363
compilerArguments.append("-index-ignore-system-modules")

Sources/SourceKitD/sourcekitd_uids.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,12 @@ public struct sourcekitd_values {
345345
ref_function_accessor_didset = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.didset")!
346346
decl_function_accessor_address = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.address")!
347347
ref_function_accessor_address = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.address")!
348-
decl_function_accessor_mutableaddress = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.mutableaddress")!
349-
ref_function_accessor_mutableaddress = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.mutableaddress")!
348+
decl_function_accessor_mutableaddress = api.uid_get_from_cstr(
349+
"source.lang.swift.decl.function.accessor.mutableaddress"
350+
)!
351+
ref_function_accessor_mutableaddress = api.uid_get_from_cstr(
352+
"source.lang.swift.ref.function.accessor.mutableaddress"
353+
)!
350354
decl_function_accessor_read = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.read")!
351355
ref_function_accessor_read = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.read")!
352356
decl_function_accessor_modify = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.modify")!
@@ -412,7 +416,9 @@ public struct sourcekitd_values {
412416
syntaxtype_operator = api.uid_get_from_cstr("source.lang.swift.syntaxtype.operator")!
413417
syntaxtype_number = api.uid_get_from_cstr("source.lang.swift.syntaxtype.number")!
414418
syntaxtype_string = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string")!
415-
syntaxtype_string_interpolation_anchor = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string_interpolation_anchor")!
419+
syntaxtype_string_interpolation_anchor = api.uid_get_from_cstr(
420+
"source.lang.swift.syntaxtype.string_interpolation_anchor"
421+
)!
416422
syntaxtype_type_identifier = api.uid_get_from_cstr("source.lang.swift.syntaxtype.typeidentifier")!
417423
syntaxtype_identifier = api.uid_get_from_cstr("source.lang.swift.syntaxtype.identifier")!
418424
expr_object_literal = api.uid_get_from_cstr("source.lang.swift.expr.object_literal")!

Sources/SourceKitLSP/Clang/ClangLanguageServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ fileprivate class ClangdStderrLogForwarder {
4040
self.buffer += newData
4141
while let newlineIndex = self.buffer.firstIndex(of: UInt8(ascii: "\n")) {
4242
// Output a separate log message for every line in clangd's stderr.
43-
// The reason why we don't output multiple lines in a single log message is that
43+
// The reason why we don't output multiple lines in a single log message is that
4444
// a) os_log truncates log messages at about 1000 bytes. The assumption is that a single line is usually less
4545
// than 1000 bytes long but if we merge multiple lines into one message, we might easily exceed this limit.
46-
// b) It might be confusing why sometimes a single log message contains one line while sometimes it contains
46+
// b) It might be confusing why sometimes a single log message contains one line while sometimes it contains
4747
// multiple.
4848
let logger = Logger(subsystem: subsystem, category: "clangd-stderr")
4949
logger.info("\(String(data: self.buffer[...newlineIndex], encoding: .utf8) ?? "<invalid UTF-8>")")

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,13 @@ extension SourceKitServer: MessageHandler {
720720
"""
721721
)
722722
case .failure(let error):
723-
logger.log(
723+
logger.log(
724724
"""
725725
Failed (took \(endDate.timeIntervalSince(startDate) * 1000, privacy: .public)ms)
726726
\(R.method, privacy: .public)(\(id, privacy: .public))
727727
\(error.forLogging, privacy: .private)
728728
"""
729-
)
729+
)
730730
}
731731
}
732732
}

Sources/SourceKitLSP/Swift/CodeCompletion.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ extension SwiftLanguageServer {
4646

4747
let filterText = String(snapshot.text[start..<end])
4848

49-
let clientSupportsSnippets = capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
49+
let clientSupportsSnippets =
50+
capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
5051
let buildSettings = await buildSettings(for: snapshot.uri)
5152
return try await CodeCompletionSession.completionList(
5253
sourcekitd: sourcekitd,
@@ -62,7 +63,7 @@ extension SwiftLanguageServer {
6263
)
6364
}
6465

65-
/// Adjust completion position to the start of identifier characters.
66+
/// Adjust completion position to the start of identifier characters.
6667
private func adjustCompletionLocation(_ pos: Position, in snapshot: DocumentSnapshot) -> Position? {
6768
guard pos.line < snapshot.lineTable.count else {
6869
// Line out of range.

Sources/SourceKitLSP/Swift/CodeCompletionSession.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CodeCompletionSession {
5151
/// Modification of code completion sessions should only happen on
5252
/// `completionQueue`.
5353
private static var completionSessions: [ObjectIdentifier: CodeCompletionSession] = [:]
54-
54+
5555
/// Gets the code completion results for the given parameters.
5656
///
5757
/// If a code completion session that is compatible with the parameters
@@ -98,16 +98,20 @@ class CodeCompletionSession {
9898
) async throws -> CompletionList {
9999
let task = completionQueue.asyncThrowing {
100100
if let session = completionSessions[ObjectIdentifier(sourcekitd)], session.state == .open {
101-
let isCompatible = session.snapshot.uri == snapshot.uri &&
102-
session.utf8StartOffset == completionUtf8Offset &&
103-
session.position == completionPosition &&
104-
session.compileCommand == compileCommand &&
105-
session.clientSupportsSnippets == clientSupportsSnippets
101+
let isCompatible =
102+
session.snapshot.uri == snapshot.uri && session.utf8StartOffset == completionUtf8Offset
103+
&& session.position == completionPosition && session.compileCommand == compileCommand
104+
&& session.clientSupportsSnippets == clientSupportsSnippets
106105

107106
if isCompatible {
108-
return try await session.update(filterText: filterText, position: cursorPosition, in: snapshot, options: options)
107+
return try await session.update(
108+
filterText: filterText,
109+
position: cursorPosition,
110+
in: snapshot,
111+
options: options
112+
)
109113
}
110-
114+
111115
if mustReuse {
112116
logger.error(
113117
"""

Sources/SourceKitLSP/Swift/DocumentSymbols.swift

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

13+
import LSPLogging
1314
import LanguageServerProtocol
1415
import SwiftSyntax
15-
import LSPLogging
1616

1717
extension SwiftLanguageServer {
1818
public func documentSymbol(_ req: DocumentSymbolRequest) async throws -> DocumentSymbolResponse? {
@@ -85,19 +85,20 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor {
8585
guard let node = node.asProtocol(NamedDeclSyntax.self) else {
8686
return .visitChildren
8787
}
88-
let symbolKind: SymbolKind? = switch node.kind {
89-
case .actorDecl: .class
90-
case .associatedTypeDecl: .typeParameter
91-
case .classDecl: .class
92-
case .enumDecl: .enum
93-
case .macroDecl: .function // LSP doesn't have a macro symbol kind. Function is the closest.
94-
case .operatorDecl: .operator
95-
case .precedenceGroupDecl: .operator // LSP doesn't have a precedence group symbol kind. Operator is the closest.
96-
case .protocolDecl: .interface
97-
case .structDecl: .struct
98-
case .typeAliasDecl: .typeParameter // LSP doesn't have a typealias symbol kind. Type parameter is the closest.
99-
default: nil
100-
}
88+
let symbolKind: SymbolKind? =
89+
switch node.kind {
90+
case .actorDecl: .class
91+
case .associatedTypeDecl: .typeParameter
92+
case .classDecl: .class
93+
case .enumDecl: .enum
94+
case .macroDecl: .function // LSP doesn't have a macro symbol kind. Function is the closest.
95+
case .operatorDecl: .operator
96+
case .precedenceGroupDecl: .operator // LSP doesn't have a precedence group symbol kind. Operator is the closest.
97+
case .protocolDecl: .interface
98+
case .structDecl: .struct
99+
case .typeAliasDecl: .typeParameter // LSP doesn't have a typealias symbol kind. Type parameter is the closest.
100+
default: nil
101+
}
101102

102103
guard let symbolKind else {
103104
return .visitChildren
@@ -139,13 +140,14 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor {
139140
}
140141

141142
override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
142-
let kind: SymbolKind = if node.name.tokenKind.isOperator {
143-
.operator
144-
} else if node.parent?.is(MemberBlockItemSyntax.self) ?? false {
145-
.method
146-
} else {
147-
.function
148-
}
143+
let kind: SymbolKind =
144+
if node.name.tokenKind.isOperator {
145+
.operator
146+
} else if node.parent?.is(MemberBlockItemSyntax.self) ?? false {
147+
.method
148+
} else {
149+
.function
150+
}
149151
return record(
150152
node: node,
151153
name: node.qualifiedDeclName,
@@ -184,7 +186,7 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor {
184186
guard let variableDecl = node.parent?.parent?.as(VariableDeclSyntax.self) else {
185187
return .visitChildren
186188
}
187-
let rangeNode: Syntax = variableDecl.bindings.count == 1 ? Syntax(variableDecl) : Syntax(node)
189+
let rangeNode: Syntax = variableDecl.bindings.count == 1 ? Syntax(variableDecl) : Syntax(node)
188190

189191
return record(
190192
node: node,

Tests/SKCoreTests/BuildSystemManagerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ final class BuildSystemManagerTests: XCTestCase {
5858

5959
await mainFiles.updateMainFiles(for: a, to: [a])
6060
await mainFiles.updateMainFiles(for: b, to: [c, d, a])
61-
61+
6262
await assertEqual(bsm._cachedMainFile(for: a), c)
6363
await assertEqual(bsm._cachedMainFile(for: b), bMain)
6464
await assertEqual(bsm._cachedMainFile(for: c), c)
@@ -236,7 +236,7 @@ final class BuildSystemManagerTests: XCTestCase {
236236
let cpp2 = DocumentURI(string: "bsm:other.cpp")
237237
let mainFiles = ManualMainFilesProvider(
238238
[
239-
h: [cpp1],
239+
h: [cpp1],
240240
cpp1: [cpp1],
241241
cpp2: [cpp2],
242242
]
@@ -411,7 +411,7 @@ private final actor ManualMainFilesProvider: MainFilesProvider {
411411
self.mainFiles = mainFiles
412412
}
413413

414-
func updateMainFiles(for file: DocumentURI, to mainFiles: Set<DocumentURI>)async {
414+
func updateMainFiles(for file: DocumentURI, to mainFiles: Set<DocumentURI>) async {
415415
self.mainFiles[file] = mainFiles
416416
}
417417

Tests/SourceKitDTests/CrashRecoveryTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ final class CrashRecoveryTests: XCTestCase {
5151
let testClient = try await TestSourceKitLSPClient()
5252
let uri = DocumentURI.for(.swift)
5353

54-
let positions = testClient.openDocument("""
54+
let positions = testClient.openDocument(
55+
"""
5556
func 1️⃣foo() {
5657
print("Hello world")
5758
}
58-
""", uri: uri)
59+
""",
60+
uri: uri
61+
)
5962

6063
// Wait for diagnostics to be produced to make sure the document open got handled by sourcekitd.
6164
_ = try await testClient.nextDiagnosticsNotification()

Tests/SourceKitDTests/SourceKitDTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import Foundation
1414
import ISDBTestSupport
1515
import ISDBTibs
1616
import LSPTestSupport
17+
import LanguageServerProtocol
1718
import SKCore
1819
import SKSupport
20+
import SKTestSupport
1921
import SourceKitD
2022
import TSCBasic
2123
import XCTest
22-
import LanguageServerProtocol
23-
import SKTestSupport
2424

2525
import enum PackageLoading.Platform
2626
import class TSCBasic.Process

Tests/SourceKitLSPTests/DocumentSymbolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ final class DocumentSymbolTests: XCTestCase {
318318
range: positions["4️⃣"]..<positions["6️⃣"],
319319
selectionRange: positions["4️⃣"]..<positions["5️⃣"],
320320
children: []
321-
)
321+
),
322322
]
323323
}
324324
}

Tests/SourceKitLSPTests/SourceKitTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ final class SKTests: XCTestCase {
183183

184184
let workspaceDirectory = try testScratchDir()
185185

186-
guard let versionedPath = try await checkRunningIndex(cleanUp: false, workspaceDirectory: workspaceDirectory) else { return }
186+
guard let versionedPath = try await checkRunningIndex(cleanUp: false, workspaceDirectory: workspaceDirectory) else {
187+
return
188+
}
187189

188190
let versionContentsAfter = try listdir(versionedPath)
189191
XCTAssertEqual(versionContentsAfter.count, 1)

0 commit comments

Comments
 (0)