Skip to content

Commit 33d803f

Browse files
committed
Change methods that were only public for testing purposes to be @_spi(Testing)
Fixes #876 Fixes #877 rdar://116705648 rdar://116705669
1 parent addfb9e commit 33d803f

18 files changed

+91
-94
lines changed

Sources/LanguageServerProtocolJSONRPC/MessageCoding.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
import LanguageServerProtocol
1414

15-
/// *Public For Testing*. A single JSONRPC message suitable for encoding/decoding.
16-
public enum JSONRPCMessage {
15+
@_spi(Testing) public enum JSONRPCMessage {
1716
case notification(NotificationType)
1817
case request(_RequestType, id: RequestID)
1918
case response(ResponseType, id: RequestID)

Sources/SKCore/BuildSystemManager.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ extension BuildSystemManager {
417417

418418
extension BuildSystemManager {
419419

420-
/// *For Testing* Returns the main file used for `uri`, if this is a registered file.
421-
public func _cachedMainFile(for uri: DocumentURI) -> DocumentURI? {
420+
/// Returns the main file used for `uri`, if this is a registered file.
421+
///
422+
/// For testing purposes only.
423+
@_spi(Testing) public func cachedMainFile(for uri: DocumentURI) -> DocumentURI? {
422424
return self.watchedFiles[uri]?.mainFile
423425
}
424426
}

Sources/SKCore/ToolchainRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public final actor ToolchainRegistry {
7171

7272
/// Create a toolchain registry with a pre-defined list of toolchains.
7373
///
74-
/// For testing purposes.
74+
/// For testing purposes only.
7575
@_spi(Testing)
7676
public init(toolchains: [Toolchain]) {
7777
self.init(

Sources/SKCore/XCToolchainPlist.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ extension XCToolchainPlist: Codable {
105105
self.displayName = try container.decodeIfPresent(String.self, forKey: .DisplayName)
106106
}
107107

108-
/// Encode the info plist. **For testing**.
108+
/// Encode the info plist.
109+
///
110+
/// For testing purposes only.
109111
public func encode(to encoder: Encoder) throws {
110112
var container = encoder.container(keyedBy: CodingKeys.self)
111113
if identifier.starts(with: "com.apple") {

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ actor ClangLanguageService: LanguageService, MessageHandler {
342342
return nil
343343
}
344344

345-
func _crash() {
345+
func crash() {
346346
// Since `clangd` doesn't have a method to crash it, kill it.
347347
#if os(Windows)
348348
if self.hClangd != INVALID_HANDLE_VALUE {

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,5 @@ public protocol LanguageService: AnyObject, Sendable {
237237
func canonicalDeclarationPosition(of position: Position, in uri: DocumentURI) async -> Position?
238238

239239
/// Crash the language server. Should be used for crash recovery testing only.
240-
func _crash() async
240+
func crash() async
241241
}

Sources/SourceKitLSP/SourceKitIndexDelegate.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import SKSupport
1818
import SwiftExtensions
1919

2020
/// `IndexDelegate` for the SourceKit workspace.
21-
///
22-
/// *Public for testing*.
23-
public actor SourceKitIndexDelegate: IndexDelegate {
21+
actor SourceKitIndexDelegate: IndexDelegate {
2422

2523
let queue = AsyncQueue<Serial>()
2624

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public actor SourceKitLSPServer {
113113

114114
var languageServices: [LanguageServerType: [LanguageService]] = [:]
115115

116-
let documentManager = DocumentManager()
116+
@_spi(Testing) public let documentManager = DocumentManager()
117117

118118
/// The `TaskScheduler` that schedules all background indexing tasks.
119119
///
@@ -132,11 +132,6 @@ public actor SourceKitLSPServer {
132132
title: "SourceKit-LSP: Reloading Package"
133133
)
134134

135-
/// **Public for testing**
136-
public var _documentManager: DocumentManager {
137-
return documentManager
138-
}
139-
140135
/// Caches which workspace a document with the given URI should be opened in.
141136
///
142137
/// - Important: Must only be modified from `workspaceQueue`. This means that the value of `uriToWorkspaceCache`
@@ -496,16 +491,7 @@ public actor SourceKitLSPServer {
496491
}
497492
}
498493

499-
/// **Public for testing purposes only**
500-
public func _languageService(
501-
for uri: DocumentURI,
502-
_ language: Language,
503-
in workspace: Workspace
504-
) async -> LanguageService? {
505-
return await languageService(for: uri, language, in: workspace)
506-
}
507-
508-
func languageService(
494+
@_spi(Testing) public func languageService(
509495
for uri: DocumentURI,
510496
_ language: Language,
511497
in workspace: Workspace

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public actor SwiftLanguageService: LanguageService, Sendable {
224224
}
225225

226226
/// - Important: For testing only
227-
public func setReusedNodeCallback(_ callback: (@Sendable (_ node: Syntax) -> ())?) async {
227+
@_spi(Testing) public func setReusedNodeCallback(_ callback: (@Sendable (_ node: Syntax) -> ())?) async {
228228
await self.syntaxTreeManager.setReusedNodeCallback(callback)
229229
}
230230

@@ -334,7 +334,7 @@ extension SwiftLanguageService {
334334
}
335335

336336
/// Tell sourcekitd to crash itself. For testing purposes only.
337-
public func _crash() async {
337+
public func crash() async {
338338
let req = sourcekitd.dictionary([
339339
keys.request: sourcekitd.requests.crashWithExit
340340
])

Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct SyntaxHighlightingTokenParser {
205205

206206
extension Range<Position> {
207207
/// Splits a potentially multi-line range to multiple single-line ranges.
208-
func splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
208+
@_spi(Testing) public func splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
209209
if isEmpty {
210210
return []
211211
}
@@ -234,9 +234,4 @@ extension Range<Position> {
234234
}
235235
.filter { !$0.isEmpty }
236236
}
237-
238-
/// **Public for testing**
239-
public func _splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
240-
splitToSingleLineRanges(in: snapshot)
241-
}
242237
}

0 commit comments

Comments
 (0)