Skip to content

Commit 3583517

Browse files
author
Kapil Borle
committed
Update method to normalize range
1 parent b0a40c9 commit 3583517

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

Engine/Range.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ public Range Shift(int lineDelta, int columnDelta)
4343
return new Range(newStart, newEnd);
4444
}
4545

46-
public static Range Normalize(Range refRange, Range range)
46+
public static Range Normalize(Position refPosition, Range range)
4747
{
48-
if (refRange == null)
48+
if (refPosition == null)
4949
{
50-
throw new ArgumentNullException(nameof(refRange));
50+
throw new ArgumentNullException(nameof(refPosition));
5151
}
5252

5353
if (range == null)
5454
{
5555
throw new ArgumentNullException(nameof(range));
5656
}
5757

58-
if (refRange.Start > range.Start)
58+
if (refPosition > range.Start)
5959
{
6060
throw new ArgumentException("reference range should start before range");
6161
}
6262

6363
return range.Shift(
64-
1 - refRange.Start.Line,
65-
range.Start.Line == refRange.Start.Line ? 1 - refRange.Start.Column : 0);
64+
1 - refPosition.Line,
65+
range.Start.Line == refPosition.Line ? 1 - refPosition.Column : 0);
6666
}
6767
}
6868
}

rules/UseSupportsShouldProcess.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,10 @@ private List<CorrectionExtent> GetCorrections(
193193
});
194194

195195
var editableText = new EditableText(funcDefnAst.Extent.Text);
196+
var funcDefAstStartPos = funcDefnAst.Extent.ToRange().Start;
196197
foreach (var correctionExtent in correctionExtents)
197198
{
198-
var shiftedCorrectionExtent = Normalize(funcDefnAst.Extent, correctionExtent);
199+
var shiftedCorrectionExtent = Normalize(funcDefAstStartPos, correctionExtent);
199200
editableText = editableText.ApplyEdit1(shiftedCorrectionExtent);
200201
}
201202

@@ -281,13 +282,10 @@ private static CorrectionExtent GetCorrectionToRemoveFuncParamDecl(
281282

282283
// doesn't seem right. The arguments should be of same type.
283284
private CorrectionExtent Normalize(
284-
IScriptExtent referenceExtent,
285+
Position refPosition,
285286
CorrectionExtent correctionExtent)
286287
{
287-
var shiftedRange = Range.Normalize(referenceExtent.ToRange(), correctionExtent);
288-
289-
// TODO Add a method to TextEdit class that takes in range and text
290-
// TODO Add a method to CorrectionExtent that takes in range and all other stuff
288+
var shiftedRange = Range.Normalize(refPosition, (Range)correctionExtent);
291289
return new CorrectionExtent(
292290
shiftedRange.Start.Line,
293291
shiftedRange.End.Line,

0 commit comments

Comments
 (0)