Skip to content

Commit 715796f

Browse files
authored
Merge pull request #1348 from lokesh-tr/change-static-method-documenturi-for-to-an-initializer
Change static method `DocumentURI.for(_:testName:)` to an initializer `DocumentURI.init(for:testName:)`
2 parents 3356873 + 1571b89 commit 715796f

25 files changed

+98
-97
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public actor SkipUnless {
103103
) async throws {
104104
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
105105
let testClient = try await TestSourceKitLSPClient()
106-
let uri = DocumentURI.for(.swift)
106+
let uri = DocumentURI(for: .swift)
107107
testClient.openDocument("0.bitPattern", uri: uri)
108108
let response = try unwrap(
109109
await testClient.send(DocumentSemanticTokensRequest(textDocument: TextDocumentIdentifier(uri)))
@@ -134,7 +134,7 @@ public actor SkipUnless {
134134
) async throws {
135135
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
136136
let testClient = try await TestSourceKitLSPClient()
137-
let uri = DocumentURI.for(.swift)
137+
let uri = DocumentURI(for: .swift)
138138
let positions = testClient.openDocument("func 1️⃣test() {}", uri: uri)
139139
do {
140140
_ = try await testClient.send(
@@ -154,7 +154,7 @@ public actor SkipUnless {
154154
) async throws {
155155
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
156156
let testClient = try await TestSourceKitLSPClient()
157-
let uri = DocumentURI.for(.c)
157+
let uri = DocumentURI(for: .c)
158158
let positions = testClient.openDocument("void 1️⃣test() {}", uri: uri)
159159
do {
160160
_ = try await testClient.send(
@@ -214,7 +214,7 @@ public actor SkipUnless {
214214
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
215215
// The XML-based doc comment conversion did not preserve `Precondition`.
216216
let testClient = try await TestSourceKitLSPClient()
217-
let uri = DocumentURI.for(.swift)
217+
let uri = DocumentURI(for: .swift)
218218
let positions = testClient.openDocument(
219219
"""
220220
/// - Precondition: Must have an apple

Sources/SKTestSupport/Utils.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ extension Language {
3636
}
3737

3838
extension DocumentURI {
39-
/// Create a unique URI for a document of the given language.
40-
public static func `for`(_ language: Language, testName: String = #function) -> DocumentURI {
39+
/// Construct a `DocumentURI` by creating a unique URI for a document of the given language.
40+
public init(for language: Language, testName: String = #function) {
4141
let testBaseName = testName.prefix(while: \.isLetter)
4242

4343
#if os(Windows)
4444
let url = URL(fileURLWithPath: "C:/\(testBaseName)/\(UUID())/test.\(language.fileExtension)")
4545
#else
4646
let url = URL(fileURLWithPath: "/\(testBaseName)/\(UUID())/test.\(language.fileExtension)")
4747
#endif
48-
return DocumentURI(url)
48+
49+
self.init(url)
4950
}
5051
}
5152

Tests/SourceKitDTests/CrashRecoveryTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ final class CrashRecoveryTests: XCTestCase {
5252
capabilities: ClientCapabilities(window: WindowClientCapabilities(workDoneProgress: true)),
5353
usePullDiagnostics: false
5454
)
55-
let uri = DocumentURI.for(.swift)
55+
let uri = DocumentURI(for: .swift)
5656

5757
let positions = testClient.openDocument(
5858
"""
@@ -150,7 +150,7 @@ final class CrashRecoveryTests: XCTestCase {
150150
try SkipUnless.longTestsEnabled()
151151

152152
let testClient = try await TestSourceKitLSPClient()
153-
let uri = DocumentURI.for(.cpp)
153+
let uri = DocumentURI(for: .cpp)
154154

155155
let positions = testClient.openDocument("1️⃣", uri: uri)
156156

@@ -256,7 +256,7 @@ final class CrashRecoveryTests: XCTestCase {
256256
try SkipUnless.longTestsEnabled()
257257

258258
let testClient = try await TestSourceKitLSPClient()
259-
let uri = DocumentURI.for(.cpp)
259+
let uri = DocumentURI(for: .cpp)
260260

261261
let positions = testClient.openDocument("1️⃣", uri: uri)
262262

Tests/SourceKitDTests/SourceKitDTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class SourceKitDTests: XCTestCase {
3030
let sourcekitdPath = await ToolchainRegistry.forTesting.default!.sourcekitd!
3131
let sourcekitd = try await DynamicallyLoadedSourceKitD.getOrCreate(dylibPath: sourcekitdPath)
3232
let keys = sourcekitd.keys
33-
let path = DocumentURI.for(.swift).pseudoPath
33+
let path = DocumentURI(for: .swift).pseudoPath
3434

3535
let isExpectedNotification = { @Sendable (response: SKDResponse) -> Bool in
3636
if let notification: sourcekitd_api_uid_t = response.value?[keys.notification],

Tests/SourceKitLSPTests/BuildSystemTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ final class BuildSystemTests: XCTestCase {
159159
func testClangdDocumentUpdatedBuildSettings() async throws {
160160
guard haveClangd else { return }
161161

162-
let doc = DocumentURI.for(.objective_c)
162+
let doc = DocumentURI(for: .objective_c)
163163
let args = [doc.pseudoPath, "-DDEBUG"]
164164
let text = """
165165
#ifdef FOO
@@ -201,7 +201,7 @@ final class BuildSystemTests: XCTestCase {
201201
}
202202

203203
func testSwiftDocumentUpdatedBuildSettings() async throws {
204-
let doc = DocumentURI.for(.swift)
204+
let doc = DocumentURI(for: .swift)
205205
let args = await FallbackBuildSystem(buildSetup: .default)
206206
.buildSettings(for: doc, language: .swift)!
207207
.compilerArguments
@@ -236,7 +236,7 @@ final class BuildSystemTests: XCTestCase {
236236
}
237237

238238
func testClangdDocumentFallbackWithholdsDiagnostics() async throws {
239-
let doc = DocumentURI.for(.objective_c)
239+
let doc = DocumentURI(for: .objective_c)
240240
let args = [doc.pseudoPath, "-DDEBUG"]
241241
let text = """
242242
#ifdef FOO
@@ -270,7 +270,7 @@ final class BuildSystemTests: XCTestCase {
270270
}
271271

272272
func testSwiftDocumentFallbackWithholdsSemanticDiagnostics() async throws {
273-
let doc = DocumentURI.for(.swift)
273+
let doc = DocumentURI(for: .swift)
274274

275275
// Primary settings must be different than the fallback settings.
276276
var primarySettings = await FallbackBuildSystem(buildSetup: .default).buildSettings(for: doc, language: .swift)!

Tests/SourceKitLSPTests/CodeActionTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ final class CodeActionTests: XCTestCase {
191191

192192
func testEmptyCodeActionResult() async throws {
193193
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
194-
let uri = DocumentURI.for(.swift)
194+
let uri = DocumentURI(for: .swift)
195195
let positions = testClient.openDocument(
196196
"""
197197
func foo() -> String {
@@ -214,7 +214,7 @@ final class CodeActionTests: XCTestCase {
214214

215215
func testSemanticRefactorLocalRenameResult() async throws {
216216
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
217-
let uri = DocumentURI.for(.swift)
217+
let uri = DocumentURI(for: .swift)
218218
let positions = testClient.openDocument(
219219
"""
220220
func localRename() {
@@ -240,7 +240,7 @@ final class CodeActionTests: XCTestCase {
240240

241241
func testSemanticRefactorLocationCodeActionResult() async throws {
242242
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
243-
let uri = DocumentURI.for(.swift)
243+
let uri = DocumentURI(for: .swift)
244244
let positions = testClient.openDocument(
245245
"""
246246
func foo() -> String {
@@ -297,7 +297,7 @@ final class CodeActionTests: XCTestCase {
297297

298298
func testJSONCodableCodeActionResult() async throws {
299299
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
300-
let uri = DocumentURI.for(.swift)
300+
let uri = DocumentURI(for: .swift)
301301
let positions = testClient.openDocument(
302302
"""
303303
1️⃣{
@@ -339,7 +339,7 @@ final class CodeActionTests: XCTestCase {
339339

340340
func testSemanticRefactorRangeCodeActionResult() async throws {
341341
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
342-
let uri = DocumentURI.for(.swift)
342+
let uri = DocumentURI(for: .swift)
343343
let positions = testClient.openDocument(
344344
"""
345345
func foo() -> String {
@@ -410,7 +410,7 @@ final class CodeActionTests: XCTestCase {
410410
capabilities: clientCapabilitiesWithCodeActionSupport,
411411
usePullDiagnostics: false
412412
)
413-
let uri = DocumentURI.for(.swift)
413+
let uri = DocumentURI(for: .swift)
414414

415415
let positions = testClient.openDocument(
416416
"""
@@ -497,7 +497,7 @@ final class CodeActionTests: XCTestCase {
497497

498498
func testAddDocumentationCodeActionResult() async throws {
499499
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
500-
let uri = DocumentURI.for(.swift)
500+
let uri = DocumentURI(for: .swift)
501501
let positions = testClient.openDocument(
502502
"""
503503
2️⃣func refacto1️⃣r(syntax: DeclSyntax, in context: Void) -> DeclSyntax? { }3️⃣
@@ -576,7 +576,7 @@ final class CodeActionTests: XCTestCase {
576576

577577
func testPackageManifestEditingCodeActionResult() async throws {
578578
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
579-
let uri = DocumentURI.for(.swift)
579+
let uri = DocumentURI(for: .swift)
580580
let positions = testClient.openDocument(
581581
"""
582582
// swift-tools-version: 5.5
@@ -650,7 +650,7 @@ final class CodeActionTests: XCTestCase {
650650

651651
func testPackageManifestEditingCodeActionNoTestResult() async throws {
652652
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
653-
let uri = DocumentURI.for(.swift)
653+
let uri = DocumentURI(for: .swift)
654654
let positions = testClient.openDocument(
655655
"""
656656
// swift-tools-version: 5.5
@@ -1014,7 +1014,7 @@ final class CodeActionTests: XCTestCase {
10141014
line: UInt = #line
10151015
) async throws {
10161016
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
1017-
let uri = DocumentURI.for(.swift)
1017+
let uri = DocumentURI(for: .swift)
10181018
let positions = testClient.openDocument(markedText, uri: uri)
10191019

10201020
var ranges = ranges

Tests/SourceKitLSPTests/DefinitionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import enum PackageLoading.Platform
1919
class DefinitionTests: XCTestCase {
2020
func testJumpToDefinitionAtEndOfIdentifier() async throws {
2121
let testClient = try await TestSourceKitLSPClient()
22-
let uri = DocumentURI.for(.swift)
22+
let uri = DocumentURI(for: .swift)
2323

2424
let positions = testClient.openDocument(
2525
"""
@@ -200,7 +200,7 @@ class DefinitionTests: XCTestCase {
200200

201201
func testReportInitializerOnDefinitionForType() async throws {
202202
let testClient = try await TestSourceKitLSPClient()
203-
let uri = DocumentURI.for(.swift)
203+
let uri = DocumentURI(for: .swift)
204204
let positions = testClient.openDocument(
205205
"""
206206
struct 1️⃣Foo {
@@ -353,7 +353,7 @@ class DefinitionTests: XCTestCase {
353353

354354
func testDefinitionOfImplicitInitializer() async throws {
355355
let testClient = try await TestSourceKitLSPClient()
356-
let uri = DocumentURI.for(.swift)
356+
let uri = DocumentURI(for: .swift)
357357

358358
let positions = testClient.openDocument(
359359
"""

Tests/SourceKitLSPTests/DocumentColorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class DocumentColorTests: XCTestCase {
2222
private func performDocumentColorRequest(text: String) async throws -> [ColorInformation] {
2323
let testClient = try await TestSourceKitLSPClient()
2424

25-
let uri = DocumentURI.for(.swift)
25+
let uri = DocumentURI(for: .swift)
2626

2727
testClient.openDocument(text, uri: uri)
2828

@@ -37,7 +37,7 @@ final class DocumentColorTests: XCTestCase {
3737
) async throws -> [ColorPresentation] {
3838
let testClient = try await TestSourceKitLSPClient()
3939

40-
let uri = DocumentURI.for(.swift)
40+
let uri = DocumentURI(for: .swift)
4141

4242
testClient.openDocument(text, uri: uri)
4343

Tests/SourceKitLSPTests/DocumentSymbolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ fileprivate func assertDocumentSymbols(
738738
line: UInt = #line
739739
) async throws {
740740
let testClient = try await TestSourceKitLSPClient()
741-
let uri = DocumentURI.for(.swift)
741+
let uri = DocumentURI(for: .swift)
742742

743743
let positions = testClient.openDocument(markedText, uri: uri)
744744
let symbols = try unwrap(try await testClient.send(DocumentSymbolRequest(textDocument: TextDocumentIdentifier(uri))))

0 commit comments

Comments
 (0)