Skip to content

Commit 03e2b4f

Browse files
committed
Document mergeTestsInExtensions()
1 parent 7b31568 commit 03e2b4f

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
@@ -463,8 +463,19 @@ extension TestItem {
463463
}
464464

465465
extension Collection where Element == TestItem {
466-
/// Walks the TestItem tree of each item in the collection and merges orphaned leaf nodes
467-
/// into their parent, if a parent exists.
466+
/// When the test scanners discover tests in extensions they are captured in their own parent `TestItem`, not the
467+
/// `TestItem` generated from the class/struct's definition. This is largely because of the syntatic nature of the
468+
/// test scanners as they are today, which only know about tests within the context of the current file. Extensions
469+
/// defined in separate files must be organized in their own `TestItem` since at the time of their creation there
470+
/// isn't enough information to connect them back to the tests defined in the main type definition.
471+
///
472+
/// This is a more syntatic than semantic view of the `TestItem` hierarchy than the end user likely wants.
473+
/// If we think of the enclosing class or struct as the test suite, then extensions on that class or struct should be
474+
/// additions to that suite, just like extensions on types are, from the user's perspective, transparently added to
475+
/// their type.
476+
///
477+
/// This method walks the `TestItem` tree produced by the test scanners and merges in the tests defined in extensions
478+
/// into the `TestItem` that represents the type definition.
468479
///
469480
/// A node's parent is identified by the node's ID with the last component dropped.
470481
func mergeTestsInExtensions() -> [TestItem] {

0 commit comments

Comments
 (0)