Skip to content

Commit ac3eb32

Browse files
committed
Format sources with swift-format
1 parent 9988930 commit ac3eb32

23 files changed

+161
-129
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ let package = Package(
199199
dependencies: [
200200
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
201201
"LanguageServerProtocol",
202-
"LSPLogging"
202+
"LSPLogging",
203203
],
204204
exclude: ["CMakeLists.txt"]
205205
),

Sources/LSPLogging/NonDarwinLogging.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum LogConfig {
1818
/// The globally set log level
1919
fileprivate static let logLevel: NonDarwinLogLevel = {
2020
if let envVar = ProcessInfo.processInfo.environment["SOURCEKITLSP_LOG_LEVEL"],
21-
let logLevel = NonDarwinLogLevel(envVar) {
21+
let logLevel = NonDarwinLogLevel(envVar)
22+
{
2223
return logLevel
2324
}
2425
#if DEBUG

Sources/LanguageServerProtocol/SupportTypes/WorkspaceSettings.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public struct ClangWorkspaceSettings: Codable, Hashable {
5959

6060
var isValid: Bool {
6161
switch (compilationDatabasePath, compilationDatabaseChanges) {
62-
case (nil, .some), (.some, nil): return true
63-
default: return false
62+
case (nil, .some), (.some, nil): return true
63+
default: return false
6464
}
6565
}
6666
}

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/SKTestSupport/SwiftPMTestWorkspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class SwiftPMTestWorkspace: MultiFileTestWorkspace {
7979
"-Xcc", "-index-ignore-system-symbols",
8080
]
8181
var environment = ProcessEnv.vars
82-
// FIXME: SwiftPM does not index-while-building on non-Darwin platforms for C-family files (rdar://117744039).
82+
// FIXME: SwiftPM does not index-while-building on non-Darwin platforms for C-family files (rdar://117744039).
8383
// Force-enable index-while-building with the environment variable.
8484
environment["SWIFTPM_ENABLE_CLANG_INDEX_STORE"] = "1"
8585
try await Process.checkNonZeroExit(arguments: arguments, environment: environment)

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: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -205,55 +205,55 @@ fileprivate enum TaskMetadata: DependencyTracker {
205205

206206
init(_ notification: any NotificationType) {
207207
switch notification {
208-
case is CancelRequestNotification:
208+
case is CancelRequestNotification:
209209
self = .freestanding
210-
case is CancelWorkDoneProgressNotification:
210+
case is CancelWorkDoneProgressNotification:
211211
self = .freestanding
212-
case is DidChangeConfigurationNotification:
212+
case is DidChangeConfigurationNotification:
213213
self = .globalConfigurationChange
214-
case let notification as DidChangeNotebookDocumentNotification:
214+
case let notification as DidChangeNotebookDocumentNotification:
215215
self = .documentUpdate(notification.notebookDocument.uri)
216-
case let notification as DidChangeTextDocumentNotification:
216+
case let notification as DidChangeTextDocumentNotification:
217217
self = .documentUpdate(notification.textDocument.uri)
218-
case is DidChangeWatchedFilesNotification:
218+
case is DidChangeWatchedFilesNotification:
219219
self = .freestanding
220-
case is DidChangeWorkspaceFoldersNotification:
220+
case is DidChangeWorkspaceFoldersNotification:
221221
self = .globalConfigurationChange
222-
case let notification as DidCloseNotebookDocumentNotification:
222+
case let notification as DidCloseNotebookDocumentNotification:
223223
self = .documentUpdate(notification.notebookDocument.uri)
224-
case let notification as DidCloseTextDocumentNotification:
224+
case let notification as DidCloseTextDocumentNotification:
225225
self = .documentUpdate(notification.textDocument.uri)
226-
case is DidCreateFilesNotification:
226+
case is DidCreateFilesNotification:
227227
self = .freestanding
228-
case is DidDeleteFilesNotification:
228+
case is DidDeleteFilesNotification:
229229
self = .freestanding
230-
case let notification as DidOpenNotebookDocumentNotification:
230+
case let notification as DidOpenNotebookDocumentNotification:
231231
self = .documentUpdate(notification.notebookDocument.uri)
232-
case let notification as DidOpenTextDocumentNotification:
232+
case let notification as DidOpenTextDocumentNotification:
233233
self = .documentUpdate(notification.textDocument.uri)
234-
case is DidRenameFilesNotification:
234+
case is DidRenameFilesNotification:
235235
self = .freestanding
236-
case let notification as DidSaveNotebookDocumentNotification:
236+
case let notification as DidSaveNotebookDocumentNotification:
237237
self = .documentUpdate(notification.notebookDocument.uri)
238-
case let notification as DidSaveTextDocumentNotification:
238+
case let notification as DidSaveTextDocumentNotification:
239239
self = .documentUpdate(notification.textDocument.uri)
240-
case is ExitNotification:
240+
case is ExitNotification:
241241
self = .globalConfigurationChange
242-
case is InitializedNotification:
242+
case is InitializedNotification:
243243
self = .globalConfigurationChange
244-
case is LogMessageNotification:
244+
case is LogMessageNotification:
245245
self = .freestanding
246-
case is LogTraceNotification:
246+
case is LogTraceNotification:
247247
self = .freestanding
248-
case is PublishDiagnosticsNotification:
248+
case is PublishDiagnosticsNotification:
249249
self = .freestanding
250-
case is SetTraceNotification:
250+
case is SetTraceNotification:
251251
self = .globalConfigurationChange
252-
case is ShowMessageNotification:
252+
case is ShowMessageNotification:
253253
self = .freestanding
254-
case let notification as WillSaveTextDocumentNotification:
254+
case let notification as WillSaveTextDocumentNotification:
255255
self = .documentUpdate(notification.textDocument.uri)
256-
case is WorkDoneProgress:
256+
case is WorkDoneProgress:
257257
self = .freestanding
258258
default:
259259
logger.error(
@@ -269,71 +269,71 @@ fileprivate enum TaskMetadata: DependencyTracker {
269269
init(_ request: any RequestType) {
270270
switch request {
271271
case let request as any TextDocumentRequest: self = .documentRequest(request.textDocument.uri)
272-
case is ApplyEditRequest:
272+
case is ApplyEditRequest:
273273
self = .freestanding
274-
case is BarrierRequest:
274+
case is BarrierRequest:
275275
self = .globalConfigurationChange
276-
case is CallHierarchyIncomingCallsRequest:
276+
case is CallHierarchyIncomingCallsRequest:
277277
self = .freestanding
278-
case is CallHierarchyOutgoingCallsRequest:
278+
case is CallHierarchyOutgoingCallsRequest:
279279
self = .freestanding
280-
case is CodeActionResolveRequest:
280+
case is CodeActionResolveRequest:
281281
self = .freestanding
282-
case is CodeLensRefreshRequest:
282+
case is CodeLensRefreshRequest:
283283
self = .freestanding
284-
case is CodeLensResolveRequest:
284+
case is CodeLensResolveRequest:
285285
self = .freestanding
286-
case is CompletionItemResolveRequest:
286+
case is CompletionItemResolveRequest:
287287
self = .freestanding
288-
case is CreateWorkDoneProgressRequest:
288+
case is CreateWorkDoneProgressRequest:
289289
self = .freestanding
290-
case is DiagnosticsRefreshRequest:
290+
case is DiagnosticsRefreshRequest:
291291
self = .freestanding
292-
case is DocumentLinkResolveRequest:
292+
case is DocumentLinkResolveRequest:
293293
self = .freestanding
294-
case let request as ExecuteCommandRequest:
294+
case let request as ExecuteCommandRequest:
295295
if let uri = request.textDocument?.uri {
296296
self = .documentRequest(uri)
297297
} else {
298298
self = .freestanding
299299
}
300-
case is InitializeRequest:
300+
case is InitializeRequest:
301301
self = .globalConfigurationChange
302-
case is InlayHintRefreshRequest:
302+
case is InlayHintRefreshRequest:
303303
self = .freestanding
304-
case is InlayHintResolveRequest:
304+
case is InlayHintResolveRequest:
305305
self = .freestanding
306-
case is InlineValueRefreshRequest:
306+
case is InlineValueRefreshRequest:
307307
self = .freestanding
308-
case is PollIndexRequest:
308+
case is PollIndexRequest:
309309
self = .globalConfigurationChange
310-
case is RegisterCapabilityRequest:
310+
case is RegisterCapabilityRequest:
311311
self = .globalConfigurationChange
312-
case is ShowMessageRequest:
312+
case is ShowMessageRequest:
313313
self = .freestanding
314-
case is ShutdownRequest:
314+
case is ShutdownRequest:
315315
self = .globalConfigurationChange
316-
case is TypeHierarchySubtypesRequest:
316+
case is TypeHierarchySubtypesRequest:
317317
self = .freestanding
318-
case is TypeHierarchySupertypesRequest:
318+
case is TypeHierarchySupertypesRequest:
319319
self = .freestanding
320-
case is UnregisterCapabilityRequest:
320+
case is UnregisterCapabilityRequest:
321321
self = .globalConfigurationChange
322-
case is WillCreateFilesRequest:
322+
case is WillCreateFilesRequest:
323323
self = .freestanding
324-
case is WillDeleteFilesRequest:
324+
case is WillDeleteFilesRequest:
325325
self = .freestanding
326-
case is WillRenameFilesRequest:
326+
case is WillRenameFilesRequest:
327327
self = .freestanding
328-
case is WorkspaceDiagnosticsRequest:
328+
case is WorkspaceDiagnosticsRequest:
329329
self = .freestanding
330-
case is WorkspaceFoldersRequest:
330+
case is WorkspaceFoldersRequest:
331331
self = .freestanding
332-
case is WorkspaceSemanticTokensRefreshRequest:
332+
case is WorkspaceSemanticTokensRefreshRequest:
333333
self = .freestanding
334-
case is WorkspaceSymbolResolveRequest:
334+
case is WorkspaceSymbolResolveRequest:
335335
self = .freestanding
336-
case is WorkspaceSymbolsRequest:
336+
case is WorkspaceSymbolsRequest:
337337
self = .freestanding
338338
default:
339339
logger.error(

Sources/SourceKitLSP/Swift/CodeCompletion.swift

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

4444
let filterText = String(snapshot.text[start..<end])
4545

46-
let clientSupportsSnippets = capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
46+
let clientSupportsSnippets =
47+
capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
4748
let buildSettings = await buildSettings(for: snapshot.uri)
4849
return try await CodeCompletionSession.completionList(
4950
sourcekitd: sourcekitd,
@@ -59,7 +60,7 @@ extension SwiftLanguageServer {
5960
)
6061
}
6162

62-
/// Adjust completion position to the start of identifier characters.
63+
/// Adjust completion position to the start of identifier characters.
6364
private func adjustCompletionLocation(_ pos: Position, in snapshot: DocumentSnapshot) -> Position? {
6465
guard pos.line < snapshot.lineTable.count else {
6566
// Line out of range.

Sources/SourceKitLSP/Swift/CodeCompletionSession.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import Dispatch
1414
import LSPLogging
1515
import LanguageServerProtocol
16-
import SourceKitD
1716
import SKSupport
17+
import SourceKitD
1818

1919
/// Represents a code-completion session for a given source location that can be efficiently
2020
/// re-filtered by calling `update()`.
@@ -52,7 +52,7 @@ class CodeCompletionSession {
5252
/// Modification of code completion sessions should only happen on
5353
/// `completionQueue`.
5454
private static var completionSessions: [ObjectIdentifier: CodeCompletionSession] = [:]
55-
55+
5656
/// Gets the code completion results for the given parameters.
5757
///
5858
/// If a code completion session that is compatible with the parameters
@@ -99,16 +99,20 @@ class CodeCompletionSession {
9999
) async throws -> CompletionList {
100100
let task = completionQueue.asyncThrowing {
101101
if let session = completionSessions[ObjectIdentifier(sourcekitd)], session.state == .open {
102-
let isCompatible = session.snapshot.uri == snapshot.uri &&
103-
session.utf8StartOffset == completionUtf8Offset &&
104-
session.position == completionPosition &&
105-
session.compileCommand == compileCommand &&
106-
session.clientSupportsSnippets == clientSupportsSnippets
102+
let isCompatible =
103+
session.snapshot.uri == snapshot.uri && session.utf8StartOffset == completionUtf8Offset
104+
&& session.position == completionPosition && session.compileCommand == compileCommand
105+
&& session.clientSupportsSnippets == clientSupportsSnippets
107106

108107
if isCompatible {
109-
return try await session.update(filterText: filterText, position: cursorPosition, in: snapshot, options: options)
108+
return try await session.update(
109+
filterText: filterText,
110+
position: cursorPosition,
111+
in: snapshot,
112+
options: options
113+
)
110114
}
111-
115+
112116
if mustReuse {
113117
logger.error(
114118
"""

0 commit comments

Comments
 (0)