Skip to content

Commit

Permalink
Rename method to match the one in PositionExtensions
Browse files Browse the repository at this point in the history
(which I eventually want to remove and just have it call the new one)
  • Loading branch information
davidwengier committed Sep 13, 2023
1 parent 5ee99ea commit ae876c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public static TextSpan AsTextSpan(this Range range, SourceText sourceText)
throw new ArgumentNullException(nameof(sourceText));
}

var start = GetAbsolutePosition(range.Start, sourceText);
var end = GetAbsolutePosition(range.End, sourceText);
var start = GetAbsoluteIndex(range.Start, sourceText);
var end = GetAbsoluteIndex(range.End, sourceText);

var length = end - start;
if (length < 0)
Expand All @@ -140,11 +140,11 @@ public static TextSpan AsTextSpan(this Range range, SourceText sourceText)

return new TextSpan(start, length);

static int GetAbsolutePosition(Position position, SourceText sourceText, [CallerArgumentExpression(nameof(position))] string? argName = null)
static int GetAbsoluteIndex(Position position, SourceText sourceText, [CallerArgumentExpression(nameof(position))] string? argName = null)
{
var line = position.Line;
var character = position.Character;
if (!sourceText.TryGetAbsolutePosition(line, character, out var absolutePosition))
if (!sourceText.TryGetAbsoluteIndex(line, character, out var absolutePosition))
{
throw new ArgumentOutOfRangeException($"{argName} ({line},{character}) matches or exceeds SourceText boundary {sourceText.Lines.Count}.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public static bool NonWhitespaceContentEquals(this SourceText source, SourceText
return null;
}

public static bool TryGetAbsolutePosition(this SourceText sourceText, int line, int character, out int absolutePosition)
public static bool TryGetAbsoluteIndex(this SourceText sourceText, int line, int character, out int absoluteIndex)
{
absolutePosition = 0;
absoluteIndex = 0;
var lineCount = sourceText.Lines.Count;
if (line > lineCount ||
(line == lineCount && character > 0))
Expand All @@ -215,11 +215,11 @@ public static bool TryGetAbsolutePosition(this SourceText sourceText, int line,
// LSP spec allowed a Range to end one line past the end, and character 0. SourceText does not, so we adjust to the final char position
if (line == lineCount)
{
absolutePosition = sourceText.Length;
absoluteIndex = sourceText.Length;
}
else
{
absolutePosition = sourceText.Lines[line].Start + character;
absoluteIndex = sourceText.Lines[line].Start + character;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ static void AppendData(

// length

if (!sourceText.TryGetAbsolutePosition(currentRange.StartLine, currentRange.StartCharacter, out var startPosition) ||
!sourceText.TryGetAbsolutePosition(currentRange.EndLine, currentRange.EndCharacter, out var endPosition))
if (!sourceText.TryGetAbsoluteIndex(currentRange.StartLine, currentRange.StartCharacter, out var startPosition) ||
!sourceText.TryGetAbsoluteIndex(currentRange.EndLine, currentRange.EndCharacter, out var endPosition))
{
throw new ArgumentOutOfRangeException($"Range: All or part of {currentRange} was outside the bounds of the document.");
}
Expand Down

0 comments on commit ae876c4

Please sign in to comment.