@@ -7,31 +7,41 @@ public override void Write(VerifyJsonWriter writer, Location value)
7
7
{
8
8
var lineSpan = value . GetMappedLineSpan ( ) ;
9
9
10
+ WriteSourceTree ( writer , value , lineSpan ) ;
11
+
12
+ writer . Serialize ( lineSpan ) ;
13
+ }
14
+
15
+ static void WriteSourceTree ( VerifyJsonWriter writer , Location value , FileLinePositionSpan lineSpan )
16
+ {
10
17
// Pretty-print the error with the source code snippet.
11
- if ( value . SourceTree is { } source )
18
+ if ( value . SourceTree is not { } source )
12
19
{
13
- var comment = new StringBuilder ( ) . AppendLine ( ) ;
14
- var lines = source . GetText ( ) . Lines ;
15
- var startLine = Math . Max ( lineSpan . StartLinePosition . Line - contextLines , 0 ) ;
16
- var endLine = Math . Min ( lineSpan . EndLinePosition . Line + contextLines , lines . Count - 1 ) ;
17
- for ( var lineIdx = startLine ; lineIdx <= endLine ; lineIdx ++ )
20
+ return ;
21
+ }
22
+
23
+ var comment = new StringBuilder ( ) ;
24
+ comment . AppendLine ( ) ;
25
+ var lines = source . GetText ( ) . Lines ;
26
+ var startLine = Math . Max ( lineSpan . StartLinePosition . Line - contextLines , 0 ) ;
27
+ var endLine = Math . Min ( lineSpan . EndLinePosition . Line + contextLines , lines . Count - 1 ) ;
28
+ for ( var index = startLine ; index <= endLine ; index ++ )
29
+ {
30
+ var line = lines [ index ] ;
31
+ // print the source line
32
+ comment . AppendLine ( line . ToString ( ) ) ;
33
+ // print squiggly line highlighting the location
34
+ if ( line . Span . Intersection ( value . SourceSpan ) is not { } intersection )
18
35
{
19
- var line = lines [ lineIdx ] ;
20
- // print the source line
21
- comment . AppendLine ( line . ToString ( ) ) ;
22
- // print squiggly line highlighting the location
23
- if ( line . Span . Intersection ( value . SourceSpan ) is { } intersection )
24
- {
25
- comment
26
- . Append ( ' ' , intersection . Start - line . Start )
27
- . Append ( '^' , intersection . Length )
28
- . AppendLine ( ) ;
29
- }
36
+ continue ;
30
37
}
31
- writer . WriteComment ( comment . ToString ( ) ) ;
32
- writer . WriteWhitespace ( "\n " ) ;
38
+
39
+ comment . Append ( ' ' , intersection . Start - line . Start ) ;
40
+ comment . Append ( '^' , intersection . Length ) ;
41
+ comment . AppendLine ( ) ;
33
42
}
34
43
35
- writer . Serialize ( lineSpan ) ;
44
+ writer . WriteComment ( comment . ToString ( ) ) ;
45
+ writer . WriteWhitespace ( "\n " ) ;
36
46
}
37
- }
47
+ }
0 commit comments