@@ -28,7 +28,7 @@ public struct GroupedDiagnostics {
28
28
let id : SourceFileID
29
29
30
30
/// The syntax tree for the source file.
31
- let tree : SourceFileSyntax
31
+ let tree : Syntax
32
32
33
33
/// The source location converter for this source file.
34
34
let sourceLocationConverter : SourceLocationConverter
@@ -55,7 +55,7 @@ public struct GroupedDiagnostics {
55
55
56
56
/// Mapping from the root source file syntax nodes to the corresponding
57
57
/// source file IDs.
58
- var rootIndexes : [ SourceFileSyntax : SourceFileID ] = [ : ]
58
+ var rootIndexes : [ Syntax : SourceFileID ] = [ : ]
59
59
60
60
public init ( ) { }
61
61
@@ -71,12 +71,13 @@ public struct GroupedDiagnostics {
71
71
/// - Returns: The unique ID for this source file.
72
72
@discardableResult
73
73
public mutating func addSourceFile(
74
- tree: SourceFileSyntax ,
74
+ tree: some SyntaxProtocol ,
75
75
sourceLocationConverter: SourceLocationConverter ? = nil ,
76
76
displayName: String ,
77
77
parent: ( SourceFileID , AbsolutePosition ) ? = nil ,
78
78
diagnostics: [ Diagnostic ] = [ ]
79
79
) -> SourceFileID {
80
+ let tree = Syntax ( tree)
80
81
// Determine the ID this source file will have.
81
82
let id = SourceFileID ( id: sourceFiles. count)
82
83
let slc =
@@ -108,11 +109,7 @@ public struct GroupedDiagnostics {
108
109
109
110
/// Find the ID of the source file containing this syntax node.
110
111
func findSourceFileContaining( _ node: Syntax ) -> SourceFileID ? {
111
- guard let rootSourceFile = node. root. as ( SourceFileSyntax . self) else {
112
- return nil
113
- }
114
-
115
- return rootIndexes [ rootSourceFile]
112
+ return rootIndexes [ node. root]
116
113
}
117
114
118
115
/// Add a diagnostic to the set of grouped diagnostics.
0 commit comments