@@ -36,28 +36,32 @@ export function serializeTargetRange(
36
36
const lines : string [ ] = [ ] ;
37
37
38
38
codeLines . forEach ( ( codeLine , lineNumber ) => {
39
- // Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"`
40
- lines . push (
41
- codeLine . length > 0 ? `${ lineNumber } | ${ codeLine } ` : `${ lineNumber } |` ,
42
- ) ;
43
-
39
+ let annotationLine : string | undefined ;
44
40
if ( lineNumber === start . line ) {
45
41
const prefix = fill ( " " , start . character + 2 ) + ">" ;
46
42
if ( start . line === end . line ) {
47
- lines . push ( prefix + fill ( "-" , end . character - start . character ) + "<" ) ;
43
+ annotationLine =
44
+ prefix + fill ( "-" , end . character - start . character ) + "<" ;
48
45
} else {
49
- lines . push ( prefix + fill ( "-" , codeLine . length - start . character ) ) ;
46
+ annotationLine = prefix + fill ( "-" , codeLine . length - start . character ) ;
50
47
}
51
48
} else if ( lineNumber > start . line && lineNumber < end . line ) {
52
49
if ( codeLine . length > 0 ) {
53
- lines . push ( " " + fill ( "-" , codeLine . length ) ) ;
50
+ annotationLine = " " + fill ( "-" , codeLine . length ) ;
54
51
} else {
55
- lines . push ( "" ) ;
52
+ annotationLine = "" ;
56
53
}
57
54
} else if ( lineNumber === end . line ) {
58
- lines . push ( " " + fill ( "-" , end . character ) + "<" ) ;
59
- } else {
60
- lines . push ( "" ) ;
55
+ annotationLine = " " + fill ( "-" , end . character ) + "<" ;
56
+ }
57
+
58
+ if ( annotationLine != null ) {
59
+ // Only output anything if there is an annotation line
60
+ lines . push (
61
+ // Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"`
62
+ codeLine . length > 0 ? `${ lineNumber } | ${ codeLine } ` : `${ lineNumber } |` ,
63
+ annotationLine ,
64
+ ) ;
61
65
}
62
66
} ) ;
63
67
0 commit comments