Skip to content

Commit b551211

Browse files
author
Kapil Borle
committed
Handle valid extent offsets in GetOffsetArray
1 parent 518287a commit b551211

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

Engine/Helper.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,46 +1386,48 @@ private Tuple<int,int>[] GetOffsetArray(List<DiagnosticRecord> diagnostics)
13861386
{
13871387
Func<int,int,Tuple<int,int>> GetTuple = (x, y) => new Tuple<int, int>(x, y);
13881388
Func<Tuple<int, int>> GetDefaultTuple = () => GetTuple(0, 0);
1389-
13901389
var offsets = new Tuple<int, int>[diagnostics.Count];
13911390
for (int k = 0; k < diagnostics.Count; k++)
13921391
{
13931392
var ext = diagnostics[k].Extent;
13941393
if (ext.StartOffset == 0 && ext.EndOffset == 0)
13951394
{
1396-
// check if line and column number do not correspond to 0 offsets
1395+
// check if line and column number correspond to 0 offsets
13971396
if (ext.StartLineNumber == 1
13981397
&& ext.StartColumnNumber == 1
13991398
&& ext.EndLineNumber == 1
14001399
&& ext.EndColumnNumber == 1)
14011400
{
14021401
offsets[k] = GetDefaultTuple();
1402+
continue;
14031403
}
1404-
else
1404+
// created using the ScriptExtent constructor, which sets
1405+
// StartOffset and EndOffset to 0
1406+
// find the token the corresponding start line and column number
1407+
var startToken = Tokens.Where(x
1408+
=> x.Extent.StartLineNumber == ext.StartLineNumber
1409+
&& x.Extent.StartColumnNumber == ext.StartColumnNumber)
1410+
.FirstOrDefault();
1411+
if (startToken == null)
14051412
{
1406-
// created using the ScriptExtent constructor, which sets
1407-
// StartOffset and EndOffset to 0
1408-
// find the token the corresponding start line and column number
1409-
var startToken = Tokens.Where(x
1410-
=> x.Extent.StartLineNumber == ext.StartLineNumber
1411-
&& x.Extent.StartColumnNumber == ext.StartColumnNumber)
1412-
.FirstOrDefault();
1413-
if (startToken == null)
1414-
{
1415-
offsets[k] = GetDefaultTuple();
1416-
continue;
1417-
}
1418-
var endToken = Tokens.Where(x
1419-
=> x.Extent.EndLineNumber == ext.EndLineNumber
1420-
&& x.Extent.EndColumnNumber == ext.EndColumnNumber)
1421-
.FirstOrDefault();
1422-
if (endToken == null)
1423-
{
1424-
offsets[k] = GetDefaultTuple();
1425-
continue;
1426-
}
1427-
offsets[k] = GetTuple(startToken.Extent.StartOffset, endToken.Extent.EndOffset);
1413+
offsets[k] = GetDefaultTuple();
1414+
continue;
1415+
}
1416+
var endToken = Tokens.Where(x
1417+
=> x.Extent.EndLineNumber == ext.EndLineNumber
1418+
&& x.Extent.EndColumnNumber == ext.EndColumnNumber)
1419+
.FirstOrDefault();
1420+
if (endToken == null)
1421+
{
1422+
offsets[k] = GetDefaultTuple();
1423+
continue;
14281424
}
1425+
offsets[k] = GetTuple(startToken.Extent.StartOffset, endToken.Extent.EndOffset);
1426+
}
1427+
else
1428+
{
1429+
// Extent has valid offsets
1430+
offsets[k] = GetTuple(ext.StartOffset, ext.EndOffset);
14291431
}
14301432
}
14311433
return offsets;

0 commit comments

Comments
 (0)