diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs index 99271765ab5..e1c6085d564 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs @@ -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) @@ -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}."); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs index 19b5124c3f6..7da71cd4b79 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs @@ -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)) @@ -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; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs index 98cce7336c8..445d651f9dd 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs @@ -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."); }