Skip to content

Commit 11e34ce

Browse files
committed
More robust fully qualified name resolution
Add a `components` property to MemberAccessExprSyntax that provides all the base names and the member's name as an array. When resolving swift-testing Tags check if they start with Tag or Testing.Tag and drop that from the name.
1 parent 003b4a3 commit 11e34ce

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

Sources/SourceKitLSP/Swift/SwiftTestingScanner.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,6 @@ fileprivate extension MemberAccessExprSyntax {
364364
} else if let baseMemberAccessExpr = base?.as(MemberAccessExprSyntax.self) {
365365
return baseMemberAccessExpr.components + [declName.baseName.text]
366366
}
367-
368-
return [declName.baseName.text]
369367
}
370368
}
371369

Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,61 @@ final class DocumentTestDiscoveryTests: XCTestCase {
693693
)
694694
}
695695

696+
func testSwiftTestingTestWithCustomTags() async throws {
697+
let testClient = try await TestSourceKitLSPClient()
698+
let uri = DocumentURI.for(.swift)
699+
700+
let positions = testClient.openDocument(
701+
"""
702+
import Testing
703+
704+
extension Tag {
705+
@Tag static var foo: Self
706+
@Tag static var bar: Self
707+
708+
struct Nested {
709+
@Tag static var foo: Tag
710+
}
711+
}
712+
713+
1️⃣@Suite(.tags("Suites"))
714+
struct MyTests {
715+
2️⃣@Test(.tags(.foo, Nested.foo, Testing.Tag.bar))
716+
func oneIsTwo() {
717+
#expect(1 == 2)
718+
}3️⃣
719+
}4️⃣
720+
""",
721+
uri: uri
722+
)
723+
724+
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
725+
XCTAssertEqual(
726+
tests,
727+
[
728+
TestItem(
729+
id: "MyTests",
730+
label: "MyTests",
731+
disabled: false,
732+
style: TestStyle.swiftTesting,
733+
location: Location(uri: uri, range: positions["1️⃣"]..<positions["4️⃣"]),
734+
children: [
735+
TestItem(
736+
id: "MyTests/oneIsTwo()",
737+
label: "oneIsTwo()",
738+
disabled: false,
739+
style: TestStyle.swiftTesting,
740+
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"]),
741+
children: [],
742+
tags: [TestTag(id: "foo"), TestTag(id: "Nested.foo"), TestTag(id: "bar")]
743+
)
744+
],
745+
tags: [TestTag(id: "Suites")]
746+
)
747+
]
748+
)
749+
}
750+
696751
func testSwiftTestingTestsWithExtension() async throws {
697752
let testClient = try await TestSourceKitLSPClient()
698753
let uri = DocumentURI.for(.swift)

0 commit comments

Comments
 (0)