Skip to content

Commit 68422c6

Browse files
added start and end index to errors
1 parent 43ed584 commit 68422c6

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

rctc/Program.cs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private static void Main(string[] args)
107107
SyntaxTree[] syntaxTrees = new SyntaxTree[sourcePaths.Count];
108108
List<ReCTAttachment> attachments = new List<ReCTAttachment>();
109109
string code = "";
110+
string mainCode = "";
110111

111112
for (int pathIndex = 0; pathIndex < sourcePaths.Count; pathIndex++)
112113
{
@@ -119,7 +120,7 @@ private static void Main(string[] args)
119120
}
120121

121122
code = File.ReadAllText(sourcePaths[pathIndex]);
122-
123+
mainCode = code;
123124

124125
if (useFlags)
125126
{
@@ -134,7 +135,7 @@ private static void Main(string[] args)
134135
if (parserDiagnostics.Length != 0)
135136
{
136137
if (jsonError)
137-
outputJSONDiagnostics(parserDiagnostics, attachments.ToArray());
138+
outputJSONDiagnostics(parserDiagnostics, mainCode, attachments.ToArray());
138139
else
139140
{
140141
Console.ForegroundColor = ConsoleColor.Red;
@@ -172,7 +173,7 @@ private static void Main(string[] args)
172173
if (diagnostics.Length != 0)
173174
{
174175
if (jsonError)
175-
outputJSONDiagnostics(diagnostics, attachments.ToArray());
176+
outputJSONDiagnostics(diagnostics, mainCode, attachments.ToArray());
176177
else
177178
{
178179
Console.ForegroundColor = ConsoleColor.Red;
@@ -488,7 +489,7 @@ static List<ReCTAttachment> evaluateFlags(ref string code, ref List<string> file
488489
return attachments;
489490
}
490491

491-
static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttachment[] attachments)
492+
static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, string mainCode, ReCTAttachment[] attachments)
492493
{
493494
List<ReCTError> errors = new List<ReCTError>();
494495

@@ -520,12 +521,15 @@ static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttac
520521

521522

522523
var attachment = "";
524+
ReCTAttachment attachmentObject = null;
523525

524526
foreach(var att in attachments)
525527
if (span.Start >= att.startingIndex && span.End < att.startingIndex + att.Length)
526528
{
527529
attachment = "[File '" + att.Name + "']\n";
528530
startLine = att.Code.Substring(0, span.Start - att.startingIndex).Split('\n').Length;
531+
endLine = startLine + lineDifference;
532+
attachmentObject = att;
529533
break;
530534
}
531535

@@ -542,8 +546,47 @@ static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttac
542546
}
543547

544548
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);
545586
}
546587

588+
if (startingIndex != -1 && endingIndex == -1)
589+
endingIndex = startingIndex + 1;
547590

548591
ReCTError newError = new ReCTError()
549592
{
@@ -553,8 +596,11 @@ static void outputJSONDiagnostics(IEnumerable<Diagnostic> diagnostics, ReCTAttac
553596
startLine = startLine,
554597
startChar = startCharacter,
555598

556-
endLine = startLine + lineDifference,
557-
endChar = endCharacter
599+
endLine = endLine,
600+
endChar = endCharacter,
601+
602+
startIndex = startingIndex,
603+
endIndex = endingIndex
558604

559605
};
560606
errors.Add(newError);
@@ -798,6 +844,8 @@ class ReCTError
798844
public int startChar {get; set;}
799845
public int endLine {get; set;}
800846
public int endChar {get; set;}
847+
public int startIndex {get; set;}
848+
public int endIndex {get; set;}
801849
}
802850

803851
[System.Serializable]

0 commit comments

Comments
 (0)