Skip to content

Change static method DocumentURI.for(_:testName:) to an initializer DocumentURI.init(for:testName:) #1348

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
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
8 changes: 4 additions & 4 deletions Sources/SKTestSupport/SkipUnless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public actor SkipUnless {
) async throws {
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
testClient.openDocument("0.bitPattern", uri: uri)
let response = try unwrap(
await testClient.send(DocumentSemanticTokensRequest(textDocument: TextDocumentIdentifier(uri)))
Expand Down Expand Up @@ -134,7 +134,7 @@ public actor SkipUnless {
) async throws {
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument("func 1️⃣test() {}", uri: uri)
do {
_ = try await testClient.send(
Expand All @@ -154,7 +154,7 @@ public actor SkipUnless {
) async throws {
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.c)
let uri = DocumentURI(for: .c)
let positions = testClient.openDocument("void 1️⃣test() {}", uri: uri)
do {
_ = try await testClient.send(
Expand Down Expand Up @@ -214,7 +214,7 @@ public actor SkipUnless {
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
// The XML-based doc comment conversion did not preserve `Precondition`.
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
/// - Precondition: Must have an apple
Expand Down
7 changes: 4 additions & 3 deletions Sources/SKTestSupport/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ extension Language {
}

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

#if os(Windows)
let url = URL(fileURLWithPath: "C:/\(testBaseName)/\(UUID())/test.\(language.fileExtension)")
#else
let url = URL(fileURLWithPath: "/\(testBaseName)/\(UUID())/test.\(language.fileExtension)")
#endif
return DocumentURI(url)

self.init(url)
}
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/SourceKitDTests/CrashRecoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class CrashRecoveryTests: XCTestCase {
capabilities: ClientCapabilities(window: WindowClientCapabilities(workDoneProgress: true)),
usePullDiagnostics: false
)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

let positions = testClient.openDocument(
"""
Expand Down Expand Up @@ -150,7 +150,7 @@ final class CrashRecoveryTests: XCTestCase {
try SkipUnless.longTestsEnabled()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.cpp)
let uri = DocumentURI(for: .cpp)

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

Expand Down Expand Up @@ -256,7 +256,7 @@ final class CrashRecoveryTests: XCTestCase {
try SkipUnless.longTestsEnabled()

let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.cpp)
let uri = DocumentURI(for: .cpp)

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

Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitDTests/SourceKitDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class SourceKitDTests: XCTestCase {
let sourcekitdPath = await ToolchainRegistry.forTesting.default!.sourcekitd!
let sourcekitd = try await DynamicallyLoadedSourceKitD.getOrCreate(dylibPath: sourcekitdPath)
let keys = sourcekitd.keys
let path = DocumentURI.for(.swift).pseudoPath
let path = DocumentURI(for: .swift).pseudoPath

let isExpectedNotification = { @Sendable (response: SKDResponse) -> Bool in
if let notification: sourcekitd_api_uid_t = response.value?[keys.notification],
Expand Down
8 changes: 4 additions & 4 deletions Tests/SourceKitLSPTests/BuildSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ final class BuildSystemTests: XCTestCase {
func testClangdDocumentUpdatedBuildSettings() async throws {
guard haveClangd else { return }

let doc = DocumentURI.for(.objective_c)
let doc = DocumentURI(for: .objective_c)
let args = [doc.pseudoPath, "-DDEBUG"]
let text = """
#ifdef FOO
Expand Down Expand Up @@ -201,7 +201,7 @@ final class BuildSystemTests: XCTestCase {
}

func testSwiftDocumentUpdatedBuildSettings() async throws {
let doc = DocumentURI.for(.swift)
let doc = DocumentURI(for: .swift)
let args = await FallbackBuildSystem(buildSetup: .default)
.buildSettings(for: doc, language: .swift)!
.compilerArguments
Expand Down Expand Up @@ -236,7 +236,7 @@ final class BuildSystemTests: XCTestCase {
}

func testClangdDocumentFallbackWithholdsDiagnostics() async throws {
let doc = DocumentURI.for(.objective_c)
let doc = DocumentURI(for: .objective_c)
let args = [doc.pseudoPath, "-DDEBUG"]
let text = """
#ifdef FOO
Expand Down Expand Up @@ -270,7 +270,7 @@ final class BuildSystemTests: XCTestCase {
}

func testSwiftDocumentFallbackWithholdsSemanticDiagnostics() async throws {
let doc = DocumentURI.for(.swift)
let doc = DocumentURI(for: .swift)

// Primary settings must be different than the fallback settings.
var primarySettings = await FallbackBuildSystem(buildSetup: .default).buildSettings(for: doc, language: .swift)!
Expand Down
20 changes: 10 additions & 10 deletions Tests/SourceKitLSPTests/CodeActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ final class CodeActionTests: XCTestCase {

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

func testSemanticRefactorLocalRenameResult() async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
func localRename() {
Expand All @@ -240,7 +240,7 @@ final class CodeActionTests: XCTestCase {

func testSemanticRefactorLocationCodeActionResult() async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
func foo() -> String {
Expand Down Expand Up @@ -297,7 +297,7 @@ final class CodeActionTests: XCTestCase {

func testJSONCodableCodeActionResult() async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
1️⃣{
Expand Down Expand Up @@ -339,7 +339,7 @@ final class CodeActionTests: XCTestCase {

func testSemanticRefactorRangeCodeActionResult() async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
func foo() -> String {
Expand Down Expand Up @@ -410,7 +410,7 @@ final class CodeActionTests: XCTestCase {
capabilities: clientCapabilitiesWithCodeActionSupport,
usePullDiagnostics: false
)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

let positions = testClient.openDocument(
"""
Expand Down Expand Up @@ -497,7 +497,7 @@ final class CodeActionTests: XCTestCase {

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

func testPackageManifestEditingCodeActionResult() async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
// swift-tools-version: 5.5
Expand Down Expand Up @@ -650,7 +650,7 @@ final class CodeActionTests: XCTestCase {

func testPackageManifestEditingCodeActionNoTestResult() async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
// swift-tools-version: 5.5
Expand Down Expand Up @@ -1014,7 +1014,7 @@ final class CodeActionTests: XCTestCase {
line: UInt = #line
) async throws {
let testClient = try await TestSourceKitLSPClient(capabilities: clientCapabilitiesWithCodeActionSupport)
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(markedText, uri: uri)

var ranges = ranges
Expand Down
6 changes: 3 additions & 3 deletions Tests/SourceKitLSPTests/DefinitionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import enum PackageLoading.Platform
class DefinitionTests: XCTestCase {
func testJumpToDefinitionAtEndOfIdentifier() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

let positions = testClient.openDocument(
"""
Expand Down Expand Up @@ -200,7 +200,7 @@ class DefinitionTests: XCTestCase {

func testReportInitializerOnDefinitionForType() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
struct 1️⃣Foo {
Expand Down Expand Up @@ -353,7 +353,7 @@ class DefinitionTests: XCTestCase {

func testDefinitionOfImplicitInitializer() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

let positions = testClient.openDocument(
"""
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/DocumentColorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class DocumentColorTests: XCTestCase {
private func performDocumentColorRequest(text: String) async throws -> [ColorInformation] {
let testClient = try await TestSourceKitLSPClient()

let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

testClient.openDocument(text, uri: uri)

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

let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

testClient.openDocument(text, uri: uri)

Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/DocumentSymbolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ fileprivate func assertDocumentSymbols(
line: UInt = #line
) async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
let uri = DocumentURI(for: .swift)

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