@@ -25,6 +25,9 @@ public struct GroupedDiagnostics {
25
25
/// The syntax tree for the source file.
26
26
let tree : SourceFileSyntax
27
27
28
+ /// The source location converter for this source file.
29
+ let sourceLocationConverter : SourceLocationConverter
30
+
28
31
/// The human-readable name to use to identify this source file.
29
32
let displayName : String
30
33
@@ -64,17 +67,24 @@ public struct GroupedDiagnostics {
64
67
@discardableResult
65
68
public mutating func addSourceFile(
66
69
tree: SourceFileSyntax ,
70
+ sourceLocationConverter: SourceLocationConverter ? = nil ,
67
71
displayName: String ,
68
72
parent: ( SourceFileID , AbsolutePosition ) ? = nil ,
69
73
diagnostics: [ Diagnostic ] = [ ]
70
74
) -> SourceFileID {
71
75
// Determine the ID this source file will have.
72
76
let id = SourceFileID ( id: sourceFiles. count)
73
-
77
+ let slc =
78
+ sourceLocationConverter
79
+ ?? SourceLocationConverter (
80
+ fileName: displayName,
81
+ tree: tree
82
+ )
74
83
sourceFiles. append (
75
84
SourceFile (
76
85
id: id,
77
86
tree: tree,
87
+ sourceLocationConverter: slc,
78
88
displayName: displayName,
79
89
parent: parent,
80
90
diagnostics: diagnostics
@@ -167,10 +177,7 @@ extension GroupedDiagnostics {
167
177
indentString: String
168
178
) -> String {
169
179
let sourceFile = sourceFiles [ sourceFileID. id]
170
- let slc = SourceLocationConverter (
171
- fileName: sourceFile. displayName,
172
- tree: sourceFile. tree
173
- )
180
+ let slc = sourceFile. sourceLocationConverter
174
181
let diagnosticDecorator = formatter. diagnosticDecorator
175
182
176
183
let childPadding = String ( slc. sourceLines. count + 1 ) . count + 1 ;
@@ -195,7 +202,7 @@ extension GroupedDiagnostics {
195
202
if isRoot {
196
203
// If there's a primary diagnostic, print it first.
197
204
if let ( primaryDiagSourceFile, primaryDiag) = findPrimaryDiagnostic ( in: sourceFile) {
198
- let primaryDiagSLC = SourceLocationConverter ( fileName : primaryDiagSourceFile. displayName , tree : primaryDiagSourceFile . tree )
205
+ let primaryDiagSLC = primaryDiagSourceFile. sourceLocationConverter
199
206
let location = primaryDiag. location ( converter: primaryDiagSLC)
200
207
201
208
// Display file/line/column and diagnostic text for the primary diagnostic.
0 commit comments