Skip to content

Format sources with swift-format #955

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

Merged
merged 1 commit into from
Nov 1, 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ let package = Package(
dependencies: [
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
"LanguageServerProtocol",
"LSPLogging"
"LSPLogging",
],
exclude: ["CMakeLists.txt"]
),
Expand Down
3 changes: 2 additions & 1 deletion Sources/LSPLogging/NonDarwinLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum LogConfig {
/// The globally set log level
fileprivate static let logLevel: NonDarwinLogLevel = {
if let envVar = ProcessInfo.processInfo.environment["SOURCEKITLSP_LOG_LEVEL"],
let logLevel = NonDarwinLogLevel(envVar) {
let logLevel = NonDarwinLogLevel(envVar)
{
return logLevel
}
#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public struct ClangWorkspaceSettings: Codable, Hashable {

var isValid: Bool {
switch (compilationDatabasePath, compilationDatabaseChanges) {
case (nil, .some), (.some, nil): return true
default: return false
case (nil, .some), (.some, nil): return true
default: return false
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/SKCore/CompilationDatabaseBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public actor CompilationDatabaseBuildSystem {
return nil
}

public init?(projectRoot: AbsolutePath? = nil, searchPaths: [RelativePath], fileSystem: FileSystem = localFileSystem) {
public init?(
projectRoot: AbsolutePath? = nil,
searchPaths: [RelativePath],
fileSystem: FileSystem = localFileSystem
) {
self.fileSystem = fileSystem
self.projectRoot = projectRoot
self.searchPaths = searchPaths
Expand Down
6 changes: 5 additions & 1 deletion Sources/SKCore/FileBuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public extension FileBuildSettings {
arguments.insert("-xobjective-c++", at: 0)
}
}
return FileBuildSettings(compilerArguments: arguments, workingDirectory: self.workingDirectory, isFallback: self.isFallback)
return FileBuildSettings(
compilerArguments: arguments,
workingDirectory: self.workingDirectory,
isFallback: self.isFallback
)
}
}
25 changes: 14 additions & 11 deletions Sources/SKSupport/AsyncUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ public func withCancellableCheckedThrowingContinuation<Handle, Result>(
}
}

return try await withTaskCancellationHandler(operation: {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
handleWrapper.value = operation(continuation)
return try await withTaskCancellationHandler(
operation: {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
handleWrapper.value = operation(continuation)

// Check if the task was cancelled. This ensures we send a
// CancelNotification even if the task gets cancelled after we register
// the cancellation handler but before we set the `requestID`.
if Task.isCancelled {
callCancel()
// Check if the task was cancelled. This ensures we send a
// CancelNotification even if the task gets cancelled after we register
// the cancellation handler but before we set the `requestID`.
if Task.isCancelled {
callCancel()
}
}
}
}, onCancel: callCancel)
},
onCancel: callCancel
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public struct IndexedSingleSwiftFileWorkspace {
var compilerArguments: [String] = [
testFileURL.path,
"-index-store-path", indexURL.path,
"-typecheck"
"-typecheck",
]
if !indexSystemModules {
compilerArguments.append("-index-ignore-system-modules")
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKTestSupport/SwiftPMTestWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class SwiftPMTestWorkspace: MultiFileTestWorkspace {
"-Xcc", "-index-ignore-system-symbols",
]
var environment = ProcessEnv.vars
// FIXME: SwiftPM does not index-while-building on non-Darwin platforms for C-family files (rdar://117744039).
// FIXME: SwiftPM does not index-while-building on non-Darwin platforms for C-family files (rdar://117744039).
// Force-enable index-while-building with the environment variable.
environment["SWIFTPM_ENABLE_CLANG_INDEX_STORE"] = "1"
try await Process.checkNonZeroExit(arguments: arguments, environment: environment)
Expand Down
12 changes: 9 additions & 3 deletions Sources/SourceKitD/sourcekitd_uids.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,12 @@ public struct sourcekitd_values {
ref_function_accessor_didset = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.didset")!
decl_function_accessor_address = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.address")!
ref_function_accessor_address = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.address")!
decl_function_accessor_mutableaddress = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.mutableaddress")!
ref_function_accessor_mutableaddress = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.mutableaddress")!
decl_function_accessor_mutableaddress = api.uid_get_from_cstr(
"source.lang.swift.decl.function.accessor.mutableaddress"
)!
ref_function_accessor_mutableaddress = api.uid_get_from_cstr(
"source.lang.swift.ref.function.accessor.mutableaddress"
)!
decl_function_accessor_read = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.read")!
ref_function_accessor_read = api.uid_get_from_cstr("source.lang.swift.ref.function.accessor.read")!
decl_function_accessor_modify = api.uid_get_from_cstr("source.lang.swift.decl.function.accessor.modify")!
Expand Down Expand Up @@ -412,7 +416,9 @@ public struct sourcekitd_values {
syntaxtype_operator = api.uid_get_from_cstr("source.lang.swift.syntaxtype.operator")!
syntaxtype_number = api.uid_get_from_cstr("source.lang.swift.syntaxtype.number")!
syntaxtype_string = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string")!
syntaxtype_string_interpolation_anchor = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string_interpolation_anchor")!
syntaxtype_string_interpolation_anchor = api.uid_get_from_cstr(
"source.lang.swift.syntaxtype.string_interpolation_anchor"
)!
syntaxtype_type_identifier = api.uid_get_from_cstr("source.lang.swift.syntaxtype.typeidentifier")!
syntaxtype_identifier = api.uid_get_from_cstr("source.lang.swift.syntaxtype.identifier")!
expr_object_literal = api.uid_get_from_cstr("source.lang.swift.expr.object_literal")!
Expand Down
4 changes: 2 additions & 2 deletions Sources/SourceKitLSP/Clang/ClangLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ fileprivate class ClangdStderrLogForwarder {
self.buffer += newData
while let newlineIndex = self.buffer.firstIndex(of: UInt8(ascii: "\n")) {
// Output a separate log message for every line in clangd's stderr.
// The reason why we don't output multiple lines in a single log message is that
// The reason why we don't output multiple lines in a single log message is that
// a) os_log truncates log messages at about 1000 bytes. The assumption is that a single line is usually less
// than 1000 bytes long but if we merge multiple lines into one message, we might easily exceed this limit.
// b) It might be confusing why sometimes a single log message contains one line while sometimes it contains
// b) It might be confusing why sometimes a single log message contains one line while sometimes it contains
// multiple.
let logger = Logger(subsystem: subsystem, category: "clangd-stderr")
logger.info("\(String(data: self.buffer[...newlineIndex], encoding: .utf8) ?? "<invalid UTF-8>")")
Expand Down
112 changes: 56 additions & 56 deletions Sources/SourceKitLSP/SourceKitServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,55 +205,55 @@ fileprivate enum TaskMetadata: DependencyTracker {

init(_ notification: any NotificationType) {
switch notification {
case is CancelRequestNotification:
case is CancelRequestNotification:
self = .freestanding
case is CancelWorkDoneProgressNotification:
case is CancelWorkDoneProgressNotification:
self = .freestanding
case is DidChangeConfigurationNotification:
case is DidChangeConfigurationNotification:
self = .globalConfigurationChange
case let notification as DidChangeNotebookDocumentNotification:
case let notification as DidChangeNotebookDocumentNotification:
self = .documentUpdate(notification.notebookDocument.uri)
case let notification as DidChangeTextDocumentNotification:
case let notification as DidChangeTextDocumentNotification:
self = .documentUpdate(notification.textDocument.uri)
case is DidChangeWatchedFilesNotification:
case is DidChangeWatchedFilesNotification:
self = .freestanding
case is DidChangeWorkspaceFoldersNotification:
case is DidChangeWorkspaceFoldersNotification:
self = .globalConfigurationChange
case let notification as DidCloseNotebookDocumentNotification:
case let notification as DidCloseNotebookDocumentNotification:
self = .documentUpdate(notification.notebookDocument.uri)
case let notification as DidCloseTextDocumentNotification:
case let notification as DidCloseTextDocumentNotification:
self = .documentUpdate(notification.textDocument.uri)
case is DidCreateFilesNotification:
case is DidCreateFilesNotification:
self = .freestanding
case is DidDeleteFilesNotification:
case is DidDeleteFilesNotification:
self = .freestanding
case let notification as DidOpenNotebookDocumentNotification:
case let notification as DidOpenNotebookDocumentNotification:
self = .documentUpdate(notification.notebookDocument.uri)
case let notification as DidOpenTextDocumentNotification:
case let notification as DidOpenTextDocumentNotification:
self = .documentUpdate(notification.textDocument.uri)
case is DidRenameFilesNotification:
case is DidRenameFilesNotification:
self = .freestanding
case let notification as DidSaveNotebookDocumentNotification:
case let notification as DidSaveNotebookDocumentNotification:
self = .documentUpdate(notification.notebookDocument.uri)
case let notification as DidSaveTextDocumentNotification:
case let notification as DidSaveTextDocumentNotification:
self = .documentUpdate(notification.textDocument.uri)
case is ExitNotification:
case is ExitNotification:
self = .globalConfigurationChange
case is InitializedNotification:
case is InitializedNotification:
self = .globalConfigurationChange
case is LogMessageNotification:
case is LogMessageNotification:
self = .freestanding
case is LogTraceNotification:
case is LogTraceNotification:
self = .freestanding
case is PublishDiagnosticsNotification:
case is PublishDiagnosticsNotification:
self = .freestanding
case is SetTraceNotification:
case is SetTraceNotification:
self = .globalConfigurationChange
case is ShowMessageNotification:
case is ShowMessageNotification:
self = .freestanding
case let notification as WillSaveTextDocumentNotification:
case let notification as WillSaveTextDocumentNotification:
self = .documentUpdate(notification.textDocument.uri)
case is WorkDoneProgress:
case is WorkDoneProgress:
self = .freestanding
default:
logger.error(
Expand All @@ -269,71 +269,71 @@ fileprivate enum TaskMetadata: DependencyTracker {
init(_ request: any RequestType) {
switch request {
case let request as any TextDocumentRequest: self = .documentRequest(request.textDocument.uri)
case is ApplyEditRequest:
case is ApplyEditRequest:
self = .freestanding
case is BarrierRequest:
case is BarrierRequest:
self = .globalConfigurationChange
case is CallHierarchyIncomingCallsRequest:
case is CallHierarchyIncomingCallsRequest:
self = .freestanding
case is CallHierarchyOutgoingCallsRequest:
case is CallHierarchyOutgoingCallsRequest:
self = .freestanding
case is CodeActionResolveRequest:
case is CodeActionResolveRequest:
self = .freestanding
case is CodeLensRefreshRequest:
case is CodeLensRefreshRequest:
self = .freestanding
case is CodeLensResolveRequest:
case is CodeLensResolveRequest:
self = .freestanding
case is CompletionItemResolveRequest:
case is CompletionItemResolveRequest:
self = .freestanding
case is CreateWorkDoneProgressRequest:
case is CreateWorkDoneProgressRequest:
self = .freestanding
case is DiagnosticsRefreshRequest:
case is DiagnosticsRefreshRequest:
self = .freestanding
case is DocumentLinkResolveRequest:
case is DocumentLinkResolveRequest:
self = .freestanding
case let request as ExecuteCommandRequest:
case let request as ExecuteCommandRequest:
if let uri = request.textDocument?.uri {
self = .documentRequest(uri)
} else {
self = .freestanding
}
case is InitializeRequest:
case is InitializeRequest:
self = .globalConfigurationChange
case is InlayHintRefreshRequest:
case is InlayHintRefreshRequest:
self = .freestanding
case is InlayHintResolveRequest:
case is InlayHintResolveRequest:
self = .freestanding
case is InlineValueRefreshRequest:
case is InlineValueRefreshRequest:
self = .freestanding
case is PollIndexRequest:
case is PollIndexRequest:
self = .globalConfigurationChange
case is RegisterCapabilityRequest:
case is RegisterCapabilityRequest:
self = .globalConfigurationChange
case is ShowMessageRequest:
case is ShowMessageRequest:
self = .freestanding
case is ShutdownRequest:
case is ShutdownRequest:
self = .globalConfigurationChange
case is TypeHierarchySubtypesRequest:
case is TypeHierarchySubtypesRequest:
self = .freestanding
case is TypeHierarchySupertypesRequest:
case is TypeHierarchySupertypesRequest:
self = .freestanding
case is UnregisterCapabilityRequest:
case is UnregisterCapabilityRequest:
self = .globalConfigurationChange
case is WillCreateFilesRequest:
case is WillCreateFilesRequest:
self = .freestanding
case is WillDeleteFilesRequest:
case is WillDeleteFilesRequest:
self = .freestanding
case is WillRenameFilesRequest:
case is WillRenameFilesRequest:
self = .freestanding
case is WorkspaceDiagnosticsRequest:
case is WorkspaceDiagnosticsRequest:
self = .freestanding
case is WorkspaceFoldersRequest:
case is WorkspaceFoldersRequest:
self = .freestanding
case is WorkspaceSemanticTokensRefreshRequest:
case is WorkspaceSemanticTokensRefreshRequest:
self = .freestanding
case is WorkspaceSymbolResolveRequest:
case is WorkspaceSymbolResolveRequest:
self = .freestanding
case is WorkspaceSymbolsRequest:
case is WorkspaceSymbolsRequest:
self = .freestanding
default:
logger.error(
Expand Down
5 changes: 3 additions & 2 deletions Sources/SourceKitLSP/Swift/CodeCompletion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ extension SwiftLanguageServer {

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

let clientSupportsSnippets = capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
let clientSupportsSnippets =
capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
let buildSettings = await buildSettings(for: snapshot.uri)
return try await CodeCompletionSession.completionList(
sourcekitd: sourcekitd,
Expand All @@ -59,7 +60,7 @@ extension SwiftLanguageServer {
)
}

/// Adjust completion position to the start of identifier characters.
/// Adjust completion position to the start of identifier characters.
private func adjustCompletionLocation(_ pos: Position, in snapshot: DocumentSnapshot) -> Position? {
guard pos.line < snapshot.lineTable.count else {
// Line out of range.
Expand Down
22 changes: 13 additions & 9 deletions Sources/SourceKitLSP/Swift/CodeCompletionSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import Dispatch
import LSPLogging
import LanguageServerProtocol
import SourceKitD
import SKSupport
import SourceKitD

/// Represents a code-completion session for a given source location that can be efficiently
/// re-filtered by calling `update()`.
Expand Down Expand Up @@ -52,7 +52,7 @@ class CodeCompletionSession {
/// Modification of code completion sessions should only happen on
/// `completionQueue`.
private static var completionSessions: [ObjectIdentifier: CodeCompletionSession] = [:]

/// Gets the code completion results for the given parameters.
///
/// If a code completion session that is compatible with the parameters
Expand Down Expand Up @@ -99,16 +99,20 @@ class CodeCompletionSession {
) async throws -> CompletionList {
let task = completionQueue.asyncThrowing {
if let session = completionSessions[ObjectIdentifier(sourcekitd)], session.state == .open {
let isCompatible = session.snapshot.uri == snapshot.uri &&
session.utf8StartOffset == completionUtf8Offset &&
session.position == completionPosition &&
session.compileCommand == compileCommand &&
session.clientSupportsSnippets == clientSupportsSnippets
let isCompatible =
session.snapshot.uri == snapshot.uri && session.utf8StartOffset == completionUtf8Offset
&& session.position == completionPosition && session.compileCommand == compileCommand
&& session.clientSupportsSnippets == clientSupportsSnippets

if isCompatible {
return try await session.update(filterText: filterText, position: cursorPosition, in: snapshot, options: options)
return try await session.update(
filterText: filterText,
position: cursorPosition,
in: snapshot,
options: options
)
}

if mustReuse {
logger.error(
"""
Expand Down
Loading