Skip to content

Commit 1b0d1e4

Browse files
authored
Merge pull request #1305 from ahoppen/6.0/revert-test-item-extension-merging
Revert #1227
2 parents 8e5736d + ff5db5f commit 1b0d1e4

File tree

6 files changed

+74
-509
lines changed

6 files changed

+74
-509
lines changed

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public protocol LanguageService: AnyObject, Sendable {
200200
/// This is used as a fallback to show the test cases in a file if the index for a given file is not up-to-date.
201201
///
202202
/// A return value of `nil` indicates that this language service does not support syntactic test discovery.
203-
func syntacticDocumentTests(for uri: DocumentURI, in workspace: Workspace) async throws -> [AnnotatedTestItem]?
203+
func syntacticDocumentTests(for uri: DocumentURI, in workspace: Workspace) async throws -> [TestItem]?
204204

205205
/// Crash the language server. Should be used for crash recovery testing only.
206206
func _crash() async

Sources/SourceKitLSP/Swift/SwiftTestingScanner.swift

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,9 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
177177
private let parentTypeNames: [String]
178178

179179
/// The discovered test items.
180-
private var result: [AnnotatedTestItem] = []
180+
private var result: [TestItem] = []
181181

182-
private init(
183-
snapshot: DocumentSnapshot,
184-
allTestsDisabled: Bool,
185-
parentTypeNames: [String]
186-
) {
182+
private init(snapshot: DocumentSnapshot, allTestsDisabled: Bool, parentTypeNames: [String]) {
187183
self.snapshot = snapshot
188184
self.allTestsDisabled = allTestsDisabled
189185
self.parentTypeNames = parentTypeNames
@@ -194,7 +190,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
194190
public static func findTestSymbols(
195191
in snapshot: DocumentSnapshot,
196192
syntaxTreeManager: SyntaxTreeManager
197-
) async -> [AnnotatedTestItem] {
193+
) async -> [TestItem] {
198194
guard snapshot.text.contains("Suite") || snapshot.text.contains("Test") else {
199195
// If the file contains swift-testing tests, it must contain a `@Suite` or `@Test` attribute.
200196
// Only check for the attribute name because the attribute may be module qualified and contain an arbitrary amount
@@ -203,11 +199,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
203199
return []
204200
}
205201
let syntaxTree = await syntaxTreeManager.syntaxTree(for: snapshot)
206-
let visitor = SyntacticSwiftTestingTestScanner(
207-
snapshot: snapshot,
208-
allTestsDisabled: false,
209-
parentTypeNames: []
210-
)
202+
let visitor = SyntacticSwiftTestingTestScanner(snapshot: snapshot, allTestsDisabled: false, parentTypeNames: [])
211203
visitor.walk(syntaxTree)
212204
return visitor.result
213205
}
@@ -249,18 +241,14 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
249241
}
250242

251243
let range = snapshot.range(of: node.positionAfterSkippingLeadingTrivia..<node.endPositionBeforeTrailingTrivia)
252-
// Members won't be extensions since extensions will only be at the top level.
253-
let testItem = AnnotatedTestItem(
254-
testItem: TestItem(
255-
id: (parentTypeNames + typeNames).joined(separator: "/"),
256-
label: attributeData?.displayName ?? typeNames.last!,
257-
disabled: (attributeData?.isDisabled ?? false) || allTestsDisabled,
258-
style: TestStyle.swiftTesting,
259-
location: Location(uri: snapshot.uri, range: range),
260-
children: memberScanner.result.map(\.testItem),
261-
tags: attributeData?.tags.map(TestTag.init(id:)) ?? []
262-
),
263-
isExtension: node.is(ExtensionDeclSyntax.self)
244+
let testItem = TestItem(
245+
id: (parentTypeNames + typeNames).joined(separator: "/"),
246+
label: attributeData?.displayName ?? typeNames.last!,
247+
disabled: (attributeData?.isDisabled ?? false) || allTestsDisabled,
248+
style: TestStyle.swiftTesting,
249+
location: Location(uri: snapshot.uri, range: range),
250+
children: memberScanner.result,
251+
tags: attributeData?.tags.map(TestTag.init(id:)) ?? []
264252
)
265253
result.append(testItem)
266254
return .skipChildren
@@ -307,17 +295,14 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
307295
node.name.text + "(" + node.signature.parameterClause.parameters.map { "\($0.firstName.text):" }.joined() + ")"
308296

309297
let range = snapshot.range(of: node.positionAfterSkippingLeadingTrivia..<node.endPositionBeforeTrailingTrivia)
310-
let testItem = AnnotatedTestItem(
311-
testItem: TestItem(
312-
id: (parentTypeNames + [name]).joined(separator: "/"),
313-
label: attributeData.displayName ?? name,
314-
disabled: attributeData.isDisabled || allTestsDisabled,
315-
style: TestStyle.swiftTesting,
316-
location: Location(uri: snapshot.uri, range: range),
317-
children: [],
318-
tags: attributeData.tags.map(TestTag.init(id:))
319-
),
320-
isExtension: false
298+
let testItem = TestItem(
299+
id: (parentTypeNames + [name]).joined(separator: "/"),
300+
label: attributeData.displayName ?? name,
301+
disabled: attributeData.isDisabled || allTestsDisabled,
302+
style: TestStyle.swiftTesting,
303+
location: Location(uri: snapshot.uri, range: range),
304+
children: [],
305+
tags: attributeData.tags.map(TestTag.init(id:))
321306
)
322307
result.append(testItem)
323308
return .visitChildren

Sources/SourceKitLSP/Swift/SyntacticTestIndex.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fileprivate enum TaskMetadata: DependencyTracker, Equatable {
5151
/// Data from a syntactic scan of a source file for tests.
5252
fileprivate struct IndexedTests {
5353
/// The tests within the source file.
54-
let tests: [AnnotatedTestItem]
54+
let tests: [TestItem]
5555

5656
/// The modification date of the source file when it was scanned. A file won't get re-scanned if its modification date
5757
/// is older or the same as this date.
@@ -63,7 +63,7 @@ fileprivate struct IndexedTests {
6363
/// Does not write the results to the index.
6464
///
6565
/// The order of the returned tests is not defined. The results should be sorted before being returned to the editor.
66-
fileprivate func testItems(in url: URL) async -> [AnnotatedTestItem] {
66+
fileprivate func testItems(in url: URL) async -> [TestItem] {
6767
guard url.pathExtension == "swift" else {
6868
return []
6969
}
@@ -79,7 +79,6 @@ fileprivate func testItems(in url: URL) async -> [AnnotatedTestItem] {
7979
syntaxTreeManager: syntaxTreeManager
8080
)
8181
async let xcTests = SyntacticSwiftXCTestScanner.findTestSymbols(in: snapshot, syntaxTreeManager: syntaxTreeManager)
82-
8382
return await swiftTestingTests + xcTests
8483
}
8584

@@ -207,7 +206,7 @@ actor SyntacticTestIndex {
207206
/// Gets all the tests in the syntactic index.
208207
///
209208
/// This waits for any pending document updates to be indexed before returning a result.
210-
nonisolated func tests() async -> [AnnotatedTestItem] {
209+
nonisolated func tests() async -> [TestItem] {
211210
let readTask = indexingQueue.async(metadata: .read) {
212211
return await self.indexedTests.values.flatMap { $0.tests }
213212
}

0 commit comments

Comments
 (0)