@@ -107,6 +107,7 @@ private static void Main(string[] args)
107
107
SyntaxTree [ ] syntaxTrees = new SyntaxTree [ sourcePaths . Count ] ;
108
108
List < ReCTAttachment > attachments = new List < ReCTAttachment > ( ) ;
109
109
string code = "" ;
110
+ string mainCode = "" ;
110
111
111
112
for ( int pathIndex = 0 ; pathIndex < sourcePaths . Count ; pathIndex ++ )
112
113
{
@@ -119,7 +120,7 @@ private static void Main(string[] args)
119
120
}
120
121
121
122
code = File . ReadAllText ( sourcePaths [ pathIndex ] ) ;
122
-
123
+ mainCode = code ;
123
124
124
125
if ( useFlags )
125
126
{
@@ -134,7 +135,7 @@ private static void Main(string[] args)
134
135
if ( parserDiagnostics . Length != 0 )
135
136
{
136
137
if ( jsonError )
137
- outputJSONDiagnostics ( parserDiagnostics , attachments . ToArray ( ) ) ;
138
+ outputJSONDiagnostics ( parserDiagnostics , mainCode , attachments . ToArray ( ) ) ;
138
139
else
139
140
{
140
141
Console . ForegroundColor = ConsoleColor . Red ;
@@ -172,7 +173,7 @@ private static void Main(string[] args)
172
173
if ( diagnostics . Length != 0 )
173
174
{
174
175
if ( jsonError )
175
- outputJSONDiagnostics ( diagnostics , attachments . ToArray ( ) ) ;
176
+ outputJSONDiagnostics ( diagnostics , mainCode , attachments . ToArray ( ) ) ;
176
177
else
177
178
{
178
179
Console . ForegroundColor = ConsoleColor . Red ;
@@ -488,7 +489,7 @@ static List<ReCTAttachment> evaluateFlags(ref string code, ref List<string> file
488
489
return attachments ;
489
490
}
490
491
491
- static void outputJSONDiagnostics ( IEnumerable < Diagnostic > diagnostics , ReCTAttachment [ ] attachments )
492
+ static void outputJSONDiagnostics ( IEnumerable < Diagnostic > diagnostics , string mainCode , ReCTAttachment [ ] attachments )
492
493
{
493
494
List < ReCTError > errors = new List < ReCTError > ( ) ;
494
495
@@ -520,12 +521,15 @@ static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttac
520
521
521
522
522
523
var attachment = "" ;
524
+ ReCTAttachment attachmentObject = null ;
523
525
524
526
foreach ( var att in attachments )
525
527
if ( span . Start >= att . startingIndex && span . End < att . startingIndex + att . Length )
526
528
{
527
529
attachment = "[File '" + att . Name + "']\n " ;
528
530
startLine = att . Code . Substring ( 0 , span . Start - att . startingIndex ) . Split ( '\n ' ) . Length ;
531
+ endLine = startLine + lineDifference ;
532
+ attachmentObject = att ;
529
533
break ;
530
534
}
531
535
@@ -542,8 +546,47 @@ static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttac
542
546
}
543
547
544
548
startLine = startLine - goBackBy + attLines ;
549
+ endLine = startLine + lineDifference ;
550
+ }
551
+
552
+ // figure out start and end index
553
+ String code = mainCode ;
554
+ if ( attachmentObject != null )
555
+ code = attachmentObject . Code ;
556
+
557
+ int startingIndex = - 1 ;
558
+ int endingIndex = - 1 ;
559
+
560
+ int lineNum = 1 ;
561
+ int charNum = 0 ;
562
+
563
+ //Console.WriteLine("-[ " + diagnostic.Message + " ]--------");
564
+
565
+ for ( int i = 0 ; i < code . Length ; i ++ )
566
+ {
567
+ charNum ++ ;
568
+
569
+ if ( code [ i ] == '\n ' )
570
+ {
571
+ // in case the end is in some unreachable location but still this line
572
+ if ( lineNum == endLine )
573
+ endingIndex = i - 1 ;
574
+
575
+ lineNum ++ ;
576
+ charNum = 1 ;
577
+ }
578
+
579
+ if ( lineNum == startLine && charNum == startCharacter )
580
+ startingIndex = i ;
581
+
582
+ if ( lineNum == endLine && charNum == endCharacter )
583
+ endingIndex = i ;
584
+
585
+ //Console.WriteLine("LINE: " + lineNum + "; ENDLINE: " + endLine + "; ENDCHAR: " + endCharacter + "; CHAR: " + i);
545
586
}
546
587
588
+ if ( startingIndex != - 1 && endingIndex == - 1 )
589
+ endingIndex = startingIndex + 1 ;
547
590
548
591
ReCTError newError = new ReCTError ( )
549
592
{
@@ -553,8 +596,11 @@ static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttac
553
596
startLine = startLine ,
554
597
startChar = startCharacter ,
555
598
556
- endLine = startLine + lineDifference ,
557
- endChar = endCharacter
599
+ endLine = endLine ,
600
+ endChar = endCharacter ,
601
+
602
+ startIndex = startingIndex ,
603
+ endIndex = endingIndex
558
604
559
605
} ;
560
606
errors . Add ( newError ) ;
@@ -798,6 +844,8 @@ class ReCTError
798
844
public int startChar { get ; set ; }
799
845
public int endLine { get ; set ; }
800
846
public int endChar { get ; set ; }
847
+ public int startIndex { get ; set ; }
848
+ public int endIndex { get ; set ; }
801
849
}
802
850
803
851
[ System . Serializable ]
0 commit comments