diff --git a/Package.swift b/Package.swift index fe9e2a6c..eb7452c4 100644 --- a/Package.swift +++ b/Package.swift @@ -199,7 +199,7 @@ let package = Package( dependencies: [ .product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"), "LanguageServerProtocol", - "LSPLogging" + "LSPLogging", ], exclude: ["CMakeLists.txt"] ), diff --git a/Sources/LSPLogging/NonDarwinLogging.swift b/Sources/LSPLogging/NonDarwinLogging.swift index 68f0d2e1..b1219b13 100644 --- a/Sources/LSPLogging/NonDarwinLogging.swift +++ b/Sources/LSPLogging/NonDarwinLogging.swift @@ -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 diff --git a/Sources/LanguageServerProtocol/SupportTypes/WorkspaceSettings.swift b/Sources/LanguageServerProtocol/SupportTypes/WorkspaceSettings.swift index 7aecf76f..2fd6729b 100644 --- a/Sources/LanguageServerProtocol/SupportTypes/WorkspaceSettings.swift +++ b/Sources/LanguageServerProtocol/SupportTypes/WorkspaceSettings.swift @@ -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 } } } diff --git a/Sources/SKCore/CompilationDatabaseBuildSystem.swift b/Sources/SKCore/CompilationDatabaseBuildSystem.swift index eb5d0501..730b40b2 100644 --- a/Sources/SKCore/CompilationDatabaseBuildSystem.swift +++ b/Sources/SKCore/CompilationDatabaseBuildSystem.swift @@ -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 diff --git a/Sources/SKCore/FileBuildSettings.swift b/Sources/SKCore/FileBuildSettings.swift index c65e502d..613d7ddb 100644 --- a/Sources/SKCore/FileBuildSettings.swift +++ b/Sources/SKCore/FileBuildSettings.swift @@ -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 + ) } } diff --git a/Sources/SKSupport/AsyncUtils.swift b/Sources/SKSupport/AsyncUtils.swift index dc6df396..35aea38f 100644 --- a/Sources/SKSupport/AsyncUtils.swift +++ b/Sources/SKSupport/AsyncUtils.swift @@ -48,17 +48,20 @@ public func withCancellableCheckedThrowingContinuation( } } - 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 + ) } diff --git a/Sources/SKTestSupport/IndexedSingleSwiftFileWorkspace.swift b/Sources/SKTestSupport/IndexedSingleSwiftFileWorkspace.swift index 5298bd83..f11fad90 100644 --- a/Sources/SKTestSupport/IndexedSingleSwiftFileWorkspace.swift +++ b/Sources/SKTestSupport/IndexedSingleSwiftFileWorkspace.swift @@ -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") diff --git a/Sources/SKTestSupport/SwiftPMTestWorkspace.swift b/Sources/SKTestSupport/SwiftPMTestWorkspace.swift index 8686cd46..67df2c67 100644 --- a/Sources/SKTestSupport/SwiftPMTestWorkspace.swift +++ b/Sources/SKTestSupport/SwiftPMTestWorkspace.swift @@ -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) diff --git a/Sources/SourceKitD/sourcekitd_uids.swift b/Sources/SourceKitD/sourcekitd_uids.swift index 947a0c4d..4647e0de 100644 --- a/Sources/SourceKitD/sourcekitd_uids.swift +++ b/Sources/SourceKitD/sourcekitd_uids.swift @@ -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")! @@ -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")! diff --git a/Sources/SourceKitLSP/Clang/ClangLanguageServer.swift b/Sources/SourceKitLSP/Clang/ClangLanguageServer.swift index 91fb45f6..12143d5a 100644 --- a/Sources/SourceKitLSP/Clang/ClangLanguageServer.swift +++ b/Sources/SourceKitLSP/Clang/ClangLanguageServer.swift @@ -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) ?? "")") diff --git a/Sources/SourceKitLSP/SourceKitServer.swift b/Sources/SourceKitLSP/SourceKitServer.swift index 6161e832..e9624cc7 100644 --- a/Sources/SourceKitLSP/SourceKitServer.swift +++ b/Sources/SourceKitLSP/SourceKitServer.swift @@ -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( @@ -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( diff --git a/Sources/SourceKitLSP/Swift/CodeCompletion.swift b/Sources/SourceKitLSP/Swift/CodeCompletion.swift index 9321fb04..9e113d28 100644 --- a/Sources/SourceKitLSP/Swift/CodeCompletion.swift +++ b/Sources/SourceKitLSP/Swift/CodeCompletion.swift @@ -43,7 +43,8 @@ extension SwiftLanguageServer { let filterText = String(snapshot.text[start.. Position? { guard pos.line < snapshot.lineTable.count else { // Line out of range. diff --git a/Sources/SourceKitLSP/Swift/CodeCompletionSession.swift b/Sources/SourceKitLSP/Swift/CodeCompletionSession.swift index d1c171e0..ebddb098 100644 --- a/Sources/SourceKitLSP/Swift/CodeCompletionSession.swift +++ b/Sources/SourceKitLSP/Swift/CodeCompletionSession.swift @@ -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()`. @@ -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 @@ -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( """ diff --git a/Sources/SourceKitLSP/Swift/DocumentSymbols.swift b/Sources/SourceKitLSP/Swift/DocumentSymbols.swift index a1cf3c1e..f8c18633 100644 --- a/Sources/SourceKitLSP/Swift/DocumentSymbols.swift +++ b/Sources/SourceKitLSP/Swift/DocumentSymbols.swift @@ -10,9 +10,9 @@ // //===----------------------------------------------------------------------===// +import LSPLogging import LanguageServerProtocol import SwiftSyntax -import LSPLogging extension SwiftLanguageServer { public func documentSymbol(_ req: DocumentSymbolRequest) async throws -> DocumentSymbolResponse? { @@ -82,19 +82,20 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor { guard let node = node.asProtocol(NamedDeclSyntax.self) else { return .visitChildren } - let symbolKind: SymbolKind? = switch node.kind { - case .actorDecl: .class - case .associatedTypeDecl: .typeParameter - case .classDecl: .class - case .enumDecl: .enum - case .macroDecl: .function // LSP doesn't have a macro symbol kind. Function is the closest. - case .operatorDecl: .operator - case .precedenceGroupDecl: .operator // LSP doesn't have a precedence group symbol kind. Operator is the closest. - case .protocolDecl: .interface - case .structDecl: .struct - case .typeAliasDecl: .typeParameter // LSP doesn't have a typealias symbol kind. Type parameter is the closest. - default: nil - } + let symbolKind: SymbolKind? = + switch node.kind { + case .actorDecl: .class + case .associatedTypeDecl: .typeParameter + case .classDecl: .class + case .enumDecl: .enum + case .macroDecl: .function // LSP doesn't have a macro symbol kind. `function`` is closest. + case .operatorDecl: .operator + case .precedenceGroupDecl: .operator // LSP doesn't have a precedence group symbol kind. `operator` is closest. + case .protocolDecl: .interface + case .structDecl: .struct + case .typeAliasDecl: .typeParameter // LSP doesn't have a typealias symbol kind. `typeParameter` is closest. + default: nil + } guard let symbolKind else { return .visitChildren @@ -136,13 +137,14 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor { } override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind { - let kind: SymbolKind = if node.name.tokenKind.isOperator { - .operator - } else if node.parent?.is(MemberBlockItemSyntax.self) ?? false { - .method - } else { - .function - } + let kind: SymbolKind = + if node.name.tokenKind.isOperator { + .operator + } else if node.parent?.is(MemberBlockItemSyntax.self) ?? false { + .method + } else { + .function + } return record( node: node, name: node.declName, @@ -181,7 +183,7 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor { guard let variableDecl = node.parent?.parent?.as(VariableDeclSyntax.self) else { return .visitChildren } - let rangeNode: Syntax = variableDecl.bindings.count == 1 ? Syntax(variableDecl) : Syntax(node) + let rangeNode: Syntax = variableDecl.bindings.count == 1 ? Syntax(variableDecl) : Syntax(node) return record( node: node, diff --git a/Tests/SKCoreTests/BuildSystemManagerTests.swift b/Tests/SKCoreTests/BuildSystemManagerTests.swift index 1bf65609..1b1a32ed 100644 --- a/Tests/SKCoreTests/BuildSystemManagerTests.swift +++ b/Tests/SKCoreTests/BuildSystemManagerTests.swift @@ -58,7 +58,7 @@ final class BuildSystemManagerTests: XCTestCase { await mainFiles.updateMainFiles(for: a, to: [a]) await mainFiles.updateMainFiles(for: b, to: [c, d, a]) - + await assertEqual(bsm._cachedMainFile(for: a), c) await assertEqual(bsm._cachedMainFile(for: b), bMain) await assertEqual(bsm._cachedMainFile(for: c), c) @@ -236,7 +236,7 @@ final class BuildSystemManagerTests: XCTestCase { let cpp2 = DocumentURI(string: "bsm:other.cpp") let mainFiles = ManualMainFilesProvider( [ - h: [cpp1], + h: [cpp1], cpp1: [cpp1], cpp2: [cpp2], ] @@ -411,7 +411,7 @@ private final actor ManualMainFilesProvider: MainFilesProvider { self.mainFiles = mainFiles } - func updateMainFiles(for file: DocumentURI, to mainFiles: Set)async { + func updateMainFiles(for file: DocumentURI, to mainFiles: Set) async { self.mainFiles[file] = mainFiles } diff --git a/Tests/SourceKitDTests/CrashRecoveryTests.swift b/Tests/SourceKitDTests/CrashRecoveryTests.swift index 387900c8..ddf83d18 100644 --- a/Tests/SourceKitDTests/CrashRecoveryTests.swift +++ b/Tests/SourceKitDTests/CrashRecoveryTests.swift @@ -51,11 +51,14 @@ final class CrashRecoveryTests: XCTestCase { let testClient = try await TestSourceKitLSPClient() let uri = DocumentURI.for(.swift) - let positions = testClient.openDocument(""" + let positions = testClient.openDocument( + """ func 1️⃣foo() { print("Hello world") } - """, uri: uri) + """, + uri: uri + ) // Wait for diagnostics to be produced to make sure the document open got handled by sourcekitd. _ = try await testClient.nextDiagnosticsNotification() diff --git a/Tests/SourceKitDTests/SourceKitDTests.swift b/Tests/SourceKitDTests/SourceKitDTests.swift index 08b8166d..0b2bed05 100644 --- a/Tests/SourceKitDTests/SourceKitDTests.swift +++ b/Tests/SourceKitDTests/SourceKitDTests.swift @@ -14,13 +14,13 @@ import Foundation import ISDBTestSupport import ISDBTibs import LSPTestSupport +import LanguageServerProtocol import SKCore import SKSupport +import SKTestSupport import SourceKitD import TSCBasic import XCTest -import LanguageServerProtocol -import SKTestSupport import enum PackageLoading.Platform import class TSCBasic.Process diff --git a/Tests/SourceKitLSPTests/DocumentSymbolTests.swift b/Tests/SourceKitLSPTests/DocumentSymbolTests.swift index 0480b856..8c1680da 100644 --- a/Tests/SourceKitLSPTests/DocumentSymbolTests.swift +++ b/Tests/SourceKitLSPTests/DocumentSymbolTests.swift @@ -318,7 +318,7 @@ final class DocumentSymbolTests: XCTestCase { range: positions["4️⃣"].." // Need to end this in another line so Xcode doesn't treat it as a real placeholder + var text = + "<#basic placeholder" // Need to end this in another line so Xcode doesn't treat it as a real placeholder + + "#>" var data = EditorPlaceholder(text) XCTAssertNotNil(data) if let data = data { diff --git a/Tests/SourceKitLSPTests/MainFilesProviderTests.swift b/Tests/SourceKitLSPTests/MainFilesProviderTests.swift index c66102f0..cde9bdde 100644 --- a/Tests/SourceKitLSPTests/MainFilesProviderTests.swift +++ b/Tests/SourceKitLSPTests/MainFilesProviderTests.swift @@ -98,7 +98,7 @@ final class MainFilesProviderTests: XCTestCase { try await SwiftPMTestWorkspace.build(at: ws.scratchDirectory) - // After building we know that 'shared.h' is included from 'MyLibrary.c' and thus we use its build settings, + // After building we know that 'shared.h' is included from 'MyLibrary.c' and thus we use its build settings, // defining `VARIABLE_NAME` to `fromMyLibrary`. let postBuildDiags = try await ws.testClient.nextDiagnosticsNotification() XCTAssertEqual(postBuildDiags.diagnostics.count, 1) @@ -148,7 +148,7 @@ final class MainFilesProviderTests: XCTestCase { _ = try ws.openDocument("shared.h", language: .c) // We could pick build settings from either 'MyLibrary.c' or 'MyFancyLibrary.c'. We currently pick the - // lexicographically first to be deterministic, which is 'MyFancyLibrary'. Thus `VARIABLE_NAME` is set to + // lexicographically first to be deterministic, which is 'MyFancyLibrary'. Thus `VARIABLE_NAME` is set to // `fromMyFancyLibrary`. let diags = try await ws.testClient.nextDiagnosticsNotification() XCTAssertEqual(diags.diagnostics.count, 1) @@ -195,7 +195,7 @@ final class MainFilesProviderTests: XCTestCase { _ = try ws.openDocument("shared.h", language: .c) - // 'MyLibrary.c' is the only file that includes 'shared.h' at first. So we use build settings from MyLibrary and + // 'MyLibrary.c' is the only file that includes 'shared.h' at first. So we use build settings from MyLibrary and // define `VARIABLE_NAME` to `fromMyLibrary`. let preEditDiags = try await ws.testClient.nextDiagnosticsNotification() XCTAssertEqual(preEditDiags.diagnostics.count, 1) diff --git a/Tests/SourceKitLSPTests/PullDiagnosticsTests.swift b/Tests/SourceKitLSPTests/PullDiagnosticsTests.swift index e3ce9f7f..3e7788ef 100644 --- a/Tests/SourceKitLSPTests/PullDiagnosticsTests.swift +++ b/Tests/SourceKitLSPTests/PullDiagnosticsTests.swift @@ -112,7 +112,7 @@ final class PullDiagnosticsTests: XCTestCase { // for test.swift so that we fall back to producing diagnostics from the built-in swift-syntax. let ws = try await MultiFileTestWorkspace(files: [ "test.swift": "func foo() 1️⃣{2️⃣", - "compile_commands.json": "[]" + "compile_commands.json": "[]", ]) let (uri, positions) = try ws.openDocument("test.swift") @@ -126,7 +126,7 @@ final class PullDiagnosticsTests: XCTestCase { let diagnostic = try XCTUnwrap(fullReport.items.first) XCTAssertEqual(diagnostic.message, "expected '}' to end function") XCTAssertEqual(diagnostic.range, Range(positions["2️⃣"])) - + XCTAssertEqual(diagnostic.relatedInformation?.count, 1) let note = try XCTUnwrap(diagnostic.relatedInformation?.first) XCTAssertEqual(note.message, "to match this opening '{'") diff --git a/Tests/SourceKitLSPTests/SemanticTokensTests.swift b/Tests/SourceKitLSPTests/SemanticTokensTests.swift index 881f0e0b..bb6b27ca 100644 --- a/Tests/SourceKitLSPTests/SemanticTokensTests.swift +++ b/Tests/SourceKitLSPTests/SemanticTokensTests.swift @@ -13,8 +13,8 @@ import LSPTestSupport import LanguageServerProtocol import SKTestSupport -import SourceKitLSP import SourceKitD +import SourceKitLSP import XCTest private typealias Token = SyntaxHighlightingToken diff --git a/Tests/SourceKitLSPTests/SourceKitTests.swift b/Tests/SourceKitLSPTests/SourceKitTests.swift index 6be73a70..4231d18f 100644 --- a/Tests/SourceKitLSPTests/SourceKitTests.swift +++ b/Tests/SourceKitLSPTests/SourceKitTests.swift @@ -183,7 +183,9 @@ final class SKTests: XCTestCase { let workspaceDirectory = try testScratchDir() - guard let versionedPath = try await checkRunningIndex(cleanUp: false, workspaceDirectory: workspaceDirectory) else { return } + guard let versionedPath = try await checkRunningIndex(cleanUp: false, workspaceDirectory: workspaceDirectory) else { + return + } let versionContentsAfter = try listdir(versionedPath) XCTAssertEqual(versionContentsAfter.count, 1)