Skip to content

Commit e740bb3

Browse files
committed
Dont expose isExtension on TestItem
1 parent d8d6cd1 commit e740bb3

File tree

7 files changed

+113
-193
lines changed

7 files changed

+113
-193
lines changed

Sources/LanguageServerProtocol/SupportTypes/TestItem.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@ public struct TestItem: ResponseType, Equatable {
5656
/// Tags associated with this test item.
5757
public var tags: [TestTag]
5858

59-
/// Whether the `TestItem` is declared in an extension.
60-
public var isExtension: Bool
61-
6259
public init(
6360
id: String,
6461
label: String,
6562
description: String? = nil,
6663
sortText: String? = nil,
6764
disabled: Bool,
68-
isExtension: Bool,
6965
style: String,
7066
location: Location,
7167
children: [TestItem],
@@ -76,7 +72,6 @@ public struct TestItem: ResponseType, Equatable {
7672
self.description = description
7773
self.sortText = sortText
7874
self.disabled = disabled
79-
self.isExtension = isExtension
8075
self.style = style
8176
self.location = location
8277
self.children = children

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 {
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 -> [TestItem]?
203+
func syntacticDocumentTests(for uri: DocumentURI, in workspace: Workspace) async throws -> [AnnotatedTestItem]?
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: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
163163
/// This is the case when the scanner is looking for tests inside a disabled suite.
164164
private let allTestsDisabled: Bool
165165

166-
/// Whether the tests discovered by the scanner should be marked as being delcared in an extension.
167-
private let isScanningExtension: Bool
168-
169166
/// The names of the types that this scanner is scanning members for.
170167
///
171168
/// For example, when scanning for tests inside `Bar` in the following, this is `["Foo", "Bar"]`
@@ -180,26 +177,24 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
180177
private let parentTypeNames: [String]
181178

182179
/// The discovered test items.
183-
private var result: [TestItem] = []
180+
private var result: [AnnotatedTestItem] = []
184181

185182
private init(
186183
snapshot: DocumentSnapshot,
187184
allTestsDisabled: Bool,
188-
isScanningExtension: Bool,
189185
parentTypeNames: [String]
190186
) {
191187
self.snapshot = snapshot
192188
self.allTestsDisabled = allTestsDisabled
193189
self.parentTypeNames = parentTypeNames
194-
self.isScanningExtension = isScanningExtension
195190
super.init(viewMode: .fixedUp)
196191
}
197192

198193
/// Public entry point. Scans the syntax tree of the given snapshot for swift-testing tests.
199194
public static func findTestSymbols(
200195
in snapshot: DocumentSnapshot,
201196
syntaxTreeManager: SyntaxTreeManager
202-
) async -> [TestItem] {
197+
) async -> [AnnotatedTestItem] {
203198
guard snapshot.text.contains("Suite") || snapshot.text.contains("Test") else {
204199
// If the file contains swift-testing tests, it must contain a `@Suite` or `@Test` attribute.
205200
// Only check for the attribute name because the attribute may be module qualified and contain an arbitrary amount
@@ -211,7 +206,6 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
211206
let visitor = SyntacticSwiftTestingTestScanner(
212207
snapshot: snapshot,
213208
allTestsDisabled: false,
214-
isScanningExtension: false,
215209
parentTypeNames: []
216210
)
217211
visitor.walk(syntaxTree)
@@ -245,7 +239,6 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
245239
let memberScanner = SyntacticSwiftTestingTestScanner(
246240
snapshot: snapshot,
247241
allTestsDisabled: attributeData?.isDisabled ?? false,
248-
isScanningExtension: node is ExtensionDeclSyntax,
249242
parentTypeNames: parentTypeNames + typeNames
250243
)
251244
memberScanner.walk(node.memberBlock)
@@ -256,15 +249,18 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
256249
}
257250

258251
let range = snapshot.range(of: node.positionAfterSkippingLeadingTrivia..<node.endPositionBeforeTrailingTrivia)
259-
let testItem = TestItem(
260-
id: (parentTypeNames + typeNames).joined(separator: "/"),
261-
label: attributeData?.displayName ?? typeNames.last!,
262-
disabled: (attributeData?.isDisabled ?? false) || allTestsDisabled,
263-
isExtension: node is ExtensionDeclSyntax,
264-
style: TestStyle.swiftTesting,
265-
location: Location(uri: snapshot.uri, range: range),
266-
children: memberScanner.result,
267-
tags: attributeData?.tags.map(TestTag.init(id:)) ?? []
252+
// Members wont 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)
268264
)
269265
result.append(testItem)
270266
return .skipChildren
@@ -311,15 +307,17 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
311307
node.name.text + "(" + node.signature.parameterClause.parameters.map { "\($0.firstName.text):" }.joined() + ")"
312308

313309
let range = snapshot.range(of: node.positionAfterSkippingLeadingTrivia..<node.endPositionBeforeTrailingTrivia)
314-
let testItem = TestItem(
315-
id: (parentTypeNames + [name]).joined(separator: "/"),
316-
label: attributeData.displayName ?? name,
317-
disabled: attributeData.isDisabled || allTestsDisabled,
318-
isExtension: isScanningExtension,
319-
style: TestStyle.swiftTesting,
320-
location: Location(uri: snapshot.uri, range: range),
321-
children: [],
322-
tags: attributeData.tags.map(TestTag.init(id:))
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
323321
)
324322
result.append(testItem)
325323
return .visitChildren

Sources/SourceKitLSP/Swift/SyntacticTestIndex.swift

Lines changed: 5 additions & 3 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: [TestItem]
54+
let tests: [AnnotatedTestItem]
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 -> [TestItem] {
66+
fileprivate func testItems(in url: URL) async -> [AnnotatedTestItem] {
6767
guard url.pathExtension == "swift" else {
6868
return []
6969
}
@@ -79,6 +79,8 @@ fileprivate func testItems(in url: URL) async -> [TestItem] {
7979
syntaxTreeManager: syntaxTreeManager
8080
)
8181
async let xcTests = SyntacticSwiftXCTestScanner.findTestSymbols(in: snapshot, syntaxTreeManager: syntaxTreeManager)
82+
.map { AnnotatedTestItem(testItem: $0, isExtension: false) }
83+
8284
return await swiftTestingTests + xcTests
8385
}
8486

@@ -206,7 +208,7 @@ actor SyntacticTestIndex {
206208
/// Gets all the tests in the syntactic index.
207209
///
208210
/// This waits for any pending document updates to be indexed before returning a result.
209-
nonisolated func tests() async -> [TestItem] {
211+
nonisolated func tests() async -> [AnnotatedTestItem] {
210212
let readTask = indexingQueue.async(metadata: .read) {
211213
return await self.indexedTests.values.flatMap { $0.tests }
212214
}

0 commit comments

Comments
 (0)