Skip to content

Commit 047a7d8

Browse files
committed
Document mergeTestsInExtensions()
1 parent a4384fd commit 047a7d8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sources/SourceKitLSP/TestDiscovery.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,19 @@ extension TestItem {
437437
}
438438

439439
extension Collection where Element == TestItem {
440-
/// Walks the TestItem tree of each item in the collection and merges orphaned leaf nodes
441-
/// into their parent, if a parent exists.
440+
/// When the test scanners discover tests in extensions they are captured in their own parent `TestItem`, not the
441+
/// `TestItem` generated from the class/struct's definition. This is largely because of the syntatic nature of the
442+
/// test scanners as they are today, which only know about tests within the context of the current file. Extensions
443+
/// defined in separate files must be organized in their own `TestItem` since at the time of their creation there
444+
/// isn't enough information to connect them back to the tests defined in the main type definition.
445+
///
446+
/// This is a more syntatic than semantic view of the `TestItem` hierarchy than the end user likely wants.
447+
/// If we think of the enclosing class or struct as the test suite, then extensions on that class or struct should be
448+
/// additions to that suite, just like extensions on types are, from the user's perspective, transparently added to
449+
/// their type.
450+
///
451+
/// This method walks the `TestItem` tree produced by the test scanners and merges in the tests defined in extensions
452+
/// into the `TestItem` that represents the type definition.
442453
///
443454
/// A node's parent is identified by the node's ID with the last component dropped.
444455
func mergeTestsInExtensions() -> [TestItem] {

0 commit comments

Comments
 (0)