Move all MS.VS.LS.Protocol extension methods into VsLspExtensions

This commit is contained in:
Dustin Campbell 2024-07-22 13:00:52 -07:00
Родитель 425009a282
Коммит c23484eb12
55 изменённых файлов: 364 добавлений и 293 удалений

Просмотреть файл

@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol.Debugging;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Debugging;

Просмотреть файл

@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.Debugging;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Debugging;

Просмотреть файл

@ -483,7 +483,7 @@ internal class RazorTranslateDiagnosticsService(IRazorDocumentMappingService doc
// For `Error` Severity diagnostics we still show the diagnostics to
// the user, however we set the range to an undefined range to ensure
// clicking on the diagnostic doesn't cause errors.
originalRange = RangeExtensions.UndefinedRange;
originalRange = VsLspFactory.UndefinedRange;
}
return true;

Просмотреть файл

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using TextSpan = Microsoft.CodeAnalysis.Text.TextSpan;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting;

Просмотреть файл

@ -8,8 +8,8 @@ using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting;

Просмотреть файл

@ -16,6 +16,7 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Threading;
namespace Microsoft.AspNetCore.Razor.LanguageServer;

Просмотреть файл

@ -44,7 +44,7 @@ internal sealed class InlayHintService(IRazorDocumentMappingService documentMapp
// the results, much like folding ranges.
var delegatedRequest = new DelegatedInlayHintParams(
Identifier: documentContext.Identifier,
ProjectedRange: projectedLinePositionSpan.ToLspRange(),
ProjectedRange: projectedLinePositionSpan.ToRange(),
ProjectedKind: RazorLanguageKind.CSharp
);

Просмотреть файл

@ -62,7 +62,7 @@ internal class LinkedEditingRangeEndpoint : IRazorRequestHandler<LinkedEditingRa
if (LinkedEditingRangeHelper.GetLinkedSpans(request.Position.ToLinePosition(), codeDocument, _logger) is { } linkedSpans && linkedSpans.Length == 2)
{
var ranges = new Range[2] { linkedSpans[0].ToLspRange(), linkedSpans[1].ToLspRange() };
var ranges = new Range[2] { linkedSpans[0].ToRange(), linkedSpans[1].ToRange() };
return new LinkedEditingRanges
{

Просмотреть файл

@ -374,7 +374,7 @@ internal sealed class MapCodeEndpoint(
// We convert the URI to the C# generated document URI later on in
// LanguageServer.Client since we're unable to retrieve it here.
Uri = potentialLocation.Uri,
Range = generatedDocumentRange.ToLspRange()
Range = generatedDocumentRange.ToRange()
};
csharpLocations.Add(csharpLocation);

Просмотреть файл

@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.MapCode.Mappers;

Просмотреть файл

@ -9,8 +9,8 @@ using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Mapping;
@ -65,7 +65,7 @@ internal sealed class RazorMapToDocumentRangesEndpoint :
!_documentMappingService.TryMapToHostDocumentRange(codeDocument.GetCSharpDocument(), projectedRange, request.MappingBehavior, out var originalRange))
{
// All language queries on unsupported documents return Html. This is equivalent to what pre-VSCode Razor was capable of.
ranges[i] = RangeExtensions.UndefinedRange;
ranges[i] = VsLspFactory.UndefinedRange;
continue;
}

Просмотреть файл

@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
@ -34,7 +35,7 @@ internal class LSPCSharpSemanticTokensProvider(LanguageServerFeatureOptions lang
using var _ = ListPool<Range>.GetPooledObject(out var csharpRangeList);
foreach (var span in csharpSpans)
{
csharpRangeList.Add(span.ToLspRange());
csharpRangeList.Add(span.ToRange());
}
var csharpRanges = csharpRangeList.ToArray();

Просмотреть файл

@ -66,35 +66,35 @@ internal static class IRazorDocumentMappingServiceExtensions
public static bool TryMapToHostDocumentRange(this IRazorDocumentMappingService service, IRazorGeneratedDocument generatedDocument, Range generatedDocumentRange, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Range? hostDocumentRange)
{
var result = service.TryMapToHostDocumentRange(generatedDocument, generatedDocumentRange.ToLinePositionSpan(), mappingBehavior, out var hostDocumentLinePositionSpan);
hostDocumentRange = result ? hostDocumentLinePositionSpan.ToLspRange() : null;
hostDocumentRange = result ? hostDocumentLinePositionSpan.ToRange() : null;
return result;
}
public static bool TryMapToGeneratedDocumentRange(this IRazorDocumentMappingService service, IRazorGeneratedDocument generatedDocument, Range hostDocumentRange, [NotNullWhen(true)] out Range? generatedDocumentRange)
{
var result = service.TryMapToGeneratedDocumentRange(generatedDocument, hostDocumentRange.ToLinePositionSpan(), out var generatedDocumentLinePositionSpan);
generatedDocumentRange = result ? generatedDocumentLinePositionSpan.ToLspRange() : null;
generatedDocumentRange = result ? generatedDocumentLinePositionSpan.ToRange() : null;
return result;
}
public static bool TryMapToHostDocumentPosition(this IRazorDocumentMappingService service, IRazorGeneratedDocument generatedDocument, int generatedDocumentIndex, [NotNullWhen(true)] out Position? hostDocumentPosition, out int hostDocumentIndex)
{
var result = service.TryMapToHostDocumentPosition(generatedDocument, generatedDocumentIndex, out var hostDocumentLinePosition, out hostDocumentIndex);
hostDocumentPosition = result ? hostDocumentLinePosition.ToLspPosition() : null;
hostDocumentPosition = result ? hostDocumentLinePosition.ToPosition() : null;
return result;
}
public static bool TryMapToGeneratedDocumentPosition(this IRazorDocumentMappingService service, IRazorGeneratedDocument generatedDocument, int hostDocumentIndex, [NotNullWhen(true)] out Position? generatedPosition, out int generatedIndex)
{
var result = service.TryMapToGeneratedDocumentPosition(generatedDocument, hostDocumentIndex, out var generatedLinePosition, out generatedIndex);
generatedPosition = result ? generatedLinePosition.ToLspPosition() : null;
generatedPosition = result ? generatedLinePosition.ToPosition() : null;
return result;
}
public static bool TryMapToGeneratedDocumentOrNextCSharpPosition(this IRazorDocumentMappingService service, IRazorGeneratedDocument generatedDocument, int hostDocumentIndex, [NotNullWhen(true)] out Position? generatedPosition, out int generatedIndex)
{
var result = service.TryMapToGeneratedDocumentOrNextCSharpPosition(generatedDocument, hostDocumentIndex, out var generatedLinePosition, out generatedIndex);
generatedPosition = result ? generatedLinePosition.ToLspPosition() : null;
generatedPosition = result ? generatedLinePosition.ToPosition() : null;
return result;
}
@ -106,6 +106,6 @@ internal static class IRazorDocumentMappingServiceExtensions
public static async Task<(Uri MappedDocumentUri, Range MappedRange)> MapToHostDocumentUriAndRangeAsync(this IRazorDocumentMappingService service, Uri generatedDocumentUri, Range generatedDocumentRange, CancellationToken cancellationToken)
{
var result = await service.MapToHostDocumentUriAndRangeAsync(generatedDocumentUri, generatedDocumentRange.ToLinePositionSpan(), cancellationToken).ConfigureAwait(false);
return (result.MappedDocumentUri, result.MappedRange.ToLspRange());
return (result.MappedDocumentUri, result.MappedRange.ToRange());
}
}

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using RLSP = Roslyn.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Text;
@ -12,12 +11,6 @@ internal static class LinePositionExtensions
public static void Deconstruct(this LinePosition linePosition, out int line, out int character)
=> (line, character) = (linePosition.Line, linePosition.Character);
public static Position ToLspPosition(this LinePosition linePosition)
=> new(linePosition.Line, linePosition.Character);
public static Range ToCollapsedLspRange(this LinePosition position)
=> new() { Start = position.ToLspPosition(), End = position.ToLspPosition() };
public static bool TryGetAbsoluteIndex(this LinePosition position, SourceText text, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(position, out absoluteIndex);

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.VisualStudio.LanguageServer.Protocol;
using RLSP = Roslyn.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Text;
@ -14,13 +13,6 @@ internal static class LinePositionSpanExtensions
public static void Deconstruct(this LinePositionSpan linePositionSpan, out int startLine, out int startCharacter, out int endLine, out int endCharacter)
=> (startLine, startCharacter, endLine, endCharacter) = (linePositionSpan.Start.Line, linePositionSpan.Start.Character, linePositionSpan.End.Line, linePositionSpan.End.Character);
public static Range ToLspRange(this LinePositionSpan linePositionSpan)
=> new()
{
Start = linePositionSpan.Start.ToLspPosition(),
End = linePositionSpan.End.ToLspPosition()
};
public static RLSP.Range ToRLSPRange(this LinePositionSpan linePositionSpan)
=> new RLSP.Range
{

Просмотреть файл

@ -8,8 +8,6 @@ using System.Linq;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
@ -149,111 +147,6 @@ internal static class RazorSyntaxNodeExtensions
}
}
public static Range GetRange(this SyntaxNode node, RazorSourceDocument source)
{
if (node is null)
{
throw new ArgumentNullException(nameof(node));
}
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
var lineSpan = node.GetLinePositionSpan(source);
var range = new Range
{
Start = new Position(lineSpan.Start.Line, lineSpan.Start.Character),
End = new Position(lineSpan.End.Line, lineSpan.End.Character)
};
return range;
}
public static Range? GetRangeWithoutWhitespace(this SyntaxNode node, RazorSourceDocument source)
{
if (node is null)
{
throw new ArgumentNullException(nameof(node));
}
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
var tokens = node.GetTokens();
SyntaxToken? firstToken = null;
for (var i = 0; i < tokens.Count; i++)
{
var token = tokens[i];
if (!token.IsWhitespace())
{
firstToken = token;
break;
}
}
SyntaxToken? lastToken = null;
for (var i = tokens.Count - 1; i >= 0; i--)
{
var token = tokens[i];
if (!token.IsWhitespace())
{
lastToken = token;
break;
}
}
if (firstToken is null && lastToken is null)
{
return null;
}
var startPositionSpan = GetLinePositionSpan(firstToken, source, node.SpanStart);
var endPositionSpan = GetLinePositionSpan(lastToken, source, node.SpanStart);
var range = new Range
{
Start = new Position(startPositionSpan.Start.Line, startPositionSpan.Start.Character),
End = new Position(endPositionSpan.End.Line, endPositionSpan.End.Character)
};
return range;
// This is needed because SyntaxToken positions taken from GetTokens
// are relative to their parent node and not to the document.
static LinePositionSpan GetLinePositionSpan(SyntaxNode? node, RazorSourceDocument source, int parentStart)
{
if (node is null)
{
throw new ArgumentNullException(nameof(node));
}
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
var sourceText = source.Text;
var start = node.Position + parentStart;
var end = node.EndPosition + parentStart;
if (start == sourceText.Length && node.FullWidth == 0)
{
// Marker symbol at the end of the document.
var location = node.GetSourceLocation(source);
var position = location.ToLinePosition();
return new LinePositionSpan(position, position);
}
return sourceText.GetLinePositionSpan(start, end);
}
}
/// <summary>
/// Finds the innermost SyntaxNode for a given location in source, within a given node.
/// </summary>

Просмотреть файл

@ -7,9 +7,6 @@ using System.Collections.Immutable;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
@ -42,19 +39,4 @@ internal static class RazorSyntaxTreeExtensions
var statements = syntaxTree.Root.DescendantNodes().OfType<CSharpStatementSyntax>().ToList();
return statements;
}
public static SyntaxNode? FindInnermostNode(
this RazorSyntaxTree syntaxTree,
SourceText sourceText,
Position position,
ILogger logger,
bool includeWhitespace = false)
{
if (!sourceText.TryGetAbsoluteIndex(position, logger, out var absoluteIndex))
{
return default;
}
return syntaxTree.Root.FindInnermostNode(absoluteIndex, includeWhitespace);
}
}

Просмотреть файл

@ -3,15 +3,11 @@
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
internal static class SourceSpanExtensions
{
public static Range ToRange(this SourceSpan span, SourceText text)
=> text.GetLspRange(span);
public static LinePositionSpan ToLinePositionSpan(this SourceSpan span, SourceText text)
=> text.GetLinePositionSpan(span);

Просмотреть файл

@ -8,8 +8,6 @@ using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.CodeAnalysis.Text;
@ -65,27 +63,9 @@ internal static class SourceTextExtensions
return text.Lines.GetPosition(position);
}
public static int GetPosition(this SourceText text, Position position)
=> text.GetPosition(position.ToLinePosition());
public static int GetPosition(this SourceText text, int line, int character)
=> text.GetPosition(new LinePosition(line, character));
public static Position GetLspPosition(this SourceText text, int position)
=> text.GetLinePosition(position).ToLspPosition();
public static Range GetLspRange(this SourceText text, TextSpan span)
=> text.GetLinePositionSpan(span).ToLspRange();
public static Range GetLspRange(this SourceText text, SourceSpan span)
=> text.GetLinePositionSpan(span).ToLspRange();
public static Range GetLspRange(this SourceText text, int start, int end)
=> text.GetLinePositionSpan(start, end).ToLspRange();
public static Range GetCollapsedLspRange(this SourceText text, int position)
=> text.GetLinePosition(position).ToCollapsedLspRange();
public static string GetSubTextString(this SourceText text, TextSpan span)
{
ArgHelper.ThrowIfNull(text);
@ -216,12 +196,6 @@ internal static class SourceTextExtensions
public static bool TryGetAbsoluteIndex(this SourceText text, LinePosition position, ILogger logger, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(position.Line, position.Character, logger, out absoluteIndex);
public static bool TryGetAbsoluteIndex(this SourceText text, Position position, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(position.Line, position.Character, out absoluteIndex);
public static bool TryGetAbsoluteIndex(this SourceText text, Position position, ILogger logger, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(position.Line, position.Character, logger, out absoluteIndex);
public static bool TryGetAbsoluteIndex(this SourceText text, int line, int character, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(line, character, logger: null, out absoluteIndex);
@ -273,12 +247,6 @@ internal static class SourceTextExtensions
public static int GetRequiredAbsoluteIndex(this SourceText text, LinePosition position, ILogger logger)
=> text.GetRequiredAbsoluteIndex(position.Line, position.Character, logger);
public static int GetRequiredAbsoluteIndex(this SourceText text, Position position)
=> text.GetRequiredAbsoluteIndex(position.Line, position.Character);
public static int GetRequiredAbsoluteIndex(this SourceText text, Position position, ILogger logger)
=> text.GetRequiredAbsoluteIndex(position.Line, position.Character, logger);
public static int GetRequiredAbsoluteIndex(this SourceText text, int line, int character)
=> text.TryGetAbsoluteIndex(line, character, out var absolutionPosition)
? absolutionPosition
@ -289,9 +257,6 @@ internal static class SourceTextExtensions
? absolutionPosition
: ThrowHelper.ThrowInvalidOperationException<int>($"({line},{character}) matches or exceeds SourceText boundary {text.Lines.Count}.");
public static TextSpan GetTextSpan(this SourceText text, Range range)
=> text.GetTextSpan(range.Start.Line, range.Start.Character, range.End.Line, range.End.Character);
public static TextSpan GetTextSpan(this SourceText text, int startLine, int startCharacter, int endLine, int endCharacter)
{
ArgHelper.ThrowIfNull(text);
@ -318,9 +283,6 @@ internal static class SourceTextExtensions
public static bool TryGetSourceLocation(this SourceText text, LinePosition position, ILogger logger, out SourceLocation location)
=> text.TryGetSourceLocation(position.Line, position.Character, logger, out location);
public static bool TryGetSourceLocation(this SourceText text, Position position, ILogger logger, out SourceLocation location)
=> text.TryGetSourceLocation(position.Line, position.Character, logger, out location);
public static bool TryGetSourceLocation(this SourceText text, int line, int character, ILogger logger, out SourceLocation location)
{
if (text.TryGetAbsoluteIndex(line, character, logger, out var absoluteIndex))

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Text;
@ -22,7 +21,4 @@ internal static class TextSpanExtensions
return span;
}
public static Range ToRange(this TextSpan span, SourceText text)
=> text.GetLinePositionSpan(span).ToLspRange();
}

Просмотреть файл

@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static Position ToPosition(this LinePosition linePosition)
=> new(linePosition.Line, linePosition.Character);
public static Range ToCollapsedRange(this LinePosition position)
=> new() { Start = position.ToPosition(), End = position.ToPosition() };
}

Просмотреть файл

@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static Range ToRange(this LinePositionSpan linePositionSpan)
=> new()
{
Start = linePositionSpan.Start.ToPosition(),
End = linePositionSpan.End.ToPosition()
};
}

Просмотреть файл

@ -7,10 +7,13 @@ using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using RLSP = Roslyn.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class PositionExtensions
internal static partial class VsLspExtensions
{
public static void Deconstruct(this Position position, out int line, out int character)
=> (line, character) = (position.Line, position.Character);
public static LinePosition ToLinePosition(this Position position)
=> new(position.Line, position.Character);

Просмотреть файл

@ -3,19 +3,23 @@
using Microsoft.AspNetCore.Razor;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
using RLSP = Roslyn.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class RangeExtensions
internal static partial class VsLspExtensions
{
public static readonly Range UndefinedRange = new()
{
Start = new Position(-1, -1),
End = new Position(-1, -1)
};
public static void Deconstruct(this Range range, out Position start, out Position end)
=> (start, end) = (range.Start, range.End);
public static void Deconstruct(this Range range, out int startLine, out int startCharacter, out int endLine, out int endCharacter)
=> (startLine, startCharacter, endLine, endCharacter) = (range.Start.Line, range.Start.Character, range.End.Line, range.End.Character);
public static LinePositionSpan ToLinePositionSpan(this Range range)
=> new(range.Start.ToLinePosition(), range.End.ToLinePosition());
public static LinePositionSpan ToLinePositionSpan(this RLSP.Range range)
=> new LinePositionSpan(range.Start.ToLinePosition(), range.End.ToLinePosition());
public static bool IntersectsOrTouches(this Range range, Range other)
{
@ -33,10 +37,10 @@ internal static class RangeExtensions
}
private static bool IsBefore(this Range range, Range other) =>
range.End.Line < other.Start.Line || range.End.Line == other.Start.Line && range.End.Character < other.Start.Character;
range.End.Line < other.Start.Line || (range.End.Line == other.Start.Line && range.End.Character < other.Start.Character);
private static bool IsAfter(this Range range, Range other) =>
other.End.Line < range.Start.Line || other.End.Line == range.Start.Line && other.End.Character < range.Start.Character;
other.End.Line < range.Start.Line || (other.End.Line == range.Start.Line && other.End.Character < range.Start.Character);
public static bool OverlapsWith(this Range range, Range other)
{
@ -81,17 +85,11 @@ internal static class RangeExtensions
return range.Start.Line != range.End.Line;
}
public static LinePositionSpan ToLinePositionSpan(this Range range)
=> new(range.Start.ToLinePosition(), range.End.ToLinePosition());
public static LinePositionSpan ToLinePositionSpan(this RLSP.Range range)
=> new LinePositionSpan(range.Start.ToLinePosition(), range.End.ToLinePosition());
public static bool IsUndefined(this Range range)
{
ArgHelper.ThrowIfNull(range);
return range == UndefinedRange;
return range == VsLspFactory.UndefinedRange;
}
public static int CompareTo(this Range range1, Range range2)

Просмотреть файл

@ -0,0 +1,28 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static SyntaxNode? FindInnermostNode(
this RazorSyntaxTree syntaxTree,
SourceText sourceText,
Position position,
ILogger logger,
bool includeWhitespace = false)
{
if (!sourceText.TryGetAbsoluteIndex(position, logger, out var absoluteIndex))
{
return default;
}
return syntaxTree.Root.FindInnermostNode(absoluteIndex, includeWhitespace);
}
}

Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static Range ToRange(this SourceSpan span, SourceText text)
=> text.GetLspRange(span);
}

Просмотреть файл

@ -0,0 +1,47 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static int GetPosition(this SourceText text, Position position)
=> text.GetPosition(position.ToLinePosition());
public static Position GetLspPosition(this SourceText text, int position)
=> text.GetLinePosition(position).ToPosition();
public static Range GetLspRange(this SourceText text, TextSpan span)
=> text.GetLinePositionSpan(span).ToRange();
public static Range GetLspRange(this SourceText text, SourceSpan span)
=> text.GetLinePositionSpan(span).ToRange();
public static Range GetLspRange(this SourceText text, int start, int end)
=> text.GetLinePositionSpan(start, end).ToRange();
public static Range GetCollapsedLspRange(this SourceText text, int position)
=> text.GetLinePosition(position).ToCollapsedRange();
public static bool TryGetAbsoluteIndex(this SourceText text, Position position, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(position.Line, position.Character, out absoluteIndex);
public static bool TryGetAbsoluteIndex(this SourceText text, Position position, ILogger logger, out int absoluteIndex)
=> text.TryGetAbsoluteIndex(position.Line, position.Character, logger, out absoluteIndex);
public static int GetRequiredAbsoluteIndex(this SourceText text, Position position)
=> text.GetRequiredAbsoluteIndex(position.Line, position.Character);
public static int GetRequiredAbsoluteIndex(this SourceText text, Position position, ILogger logger)
=> text.GetRequiredAbsoluteIndex(position.Line, position.Character, logger);
public static TextSpan GetTextSpan(this SourceText text, Range range)
=> text.GetTextSpan(range.Start.Line, range.Start.Character, range.End.Line, range.End.Character);
public static bool TryGetSourceLocation(this SourceText text, Position position, ILogger logger, out SourceLocation location)
=> text.TryGetSourceLocation(position.Line, position.Character, logger, out location);
}

Просмотреть файл

@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.AspNetCore.Razor;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class SumTypeExtensions
internal static partial class VsLspExtensions
{
internal static int Count(this SumType<TextDocumentEdit[], SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]> sumType)
{
@ -15,14 +15,13 @@ internal static class SumTypeExtensions
{
return textDocumentEdit.Length;
}
else if (sumType.TryGetSecond(out var edits))
if (sumType.TryGetSecond(out var edits))
{
return edits.Length;
}
else
{
throw new NotImplementedException("Shouldn't be possible");
}
return Assumed.Unreachable<int>();
}
internal static SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile> ElementAt(this SumType<TextDocumentEdit[], SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]> sumType, int elementIndex)
@ -31,14 +30,13 @@ internal static class SumTypeExtensions
{
return textDocumentEdits[elementIndex];
}
else if (sumType.TryGetSecond(out var edits))
if (sumType.TryGetSecond(out var edits))
{
return edits[elementIndex];
}
else
{
throw new NotImplementedException("Shouldn't be possible");
}
return Assumed.Unreachable<SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>();
}
internal static SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[] ToArray(this SumType<TextDocumentEdit[], SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]> sumType)
@ -47,14 +45,13 @@ internal static class SumTypeExtensions
{
return textDocumentEdit.Select(s => (SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>)s).ToArray();
}
else if (sumType.TryGetSecond(out var edits))
if (sumType.TryGetSecond(out var edits))
{
return edits.ToArray();
}
else
{
throw new NotImplementedException("Shouldn't be possible");
}
return Assumed.Unreachable<SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]>();
}
internal static SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile> First(this SumType<TextDocumentEdit[], SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]> sumType)
@ -63,14 +60,13 @@ internal static class SumTypeExtensions
{
return textDocumentEdits.First();
}
else if (sumType.TryGetSecond(out var edits))
if (sumType.TryGetSecond(out var edits))
{
return edits.First();
}
else
{
throw new NotImplementedException("Shouldn't be possible");
}
return Assumed.Unreachable<SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>();
}
internal static SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile> Last(this SumType<TextDocumentEdit[], SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]> sumType)
@ -79,13 +75,12 @@ internal static class SumTypeExtensions
{
return textDocumentEdits.Last();
}
else if (sumType.TryGetSecond(out var edits))
if (sumType.TryGetSecond(out var edits))
{
return edits.Last();
}
else
{
throw new NotImplementedException("Shouldn't be possible");
}
return Assumed.Unreachable<SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>();
}
}

Просмотреть файл

@ -0,0 +1,97 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static Range GetRange(this SyntaxNode node, RazorSourceDocument source)
{
ArgHelper.ThrowIfNull(node);
ArgHelper.ThrowIfNull(source);
var lineSpan = node.GetLinePositionSpan(source);
var range = new Range
{
Start = new Position(lineSpan.Start.Line, lineSpan.Start.Character),
End = new Position(lineSpan.End.Line, lineSpan.End.Character)
};
return range;
}
public static Range? GetRangeWithoutWhitespace(this SyntaxNode node, RazorSourceDocument source)
{
ArgHelper.ThrowIfNull(node);
ArgHelper.ThrowIfNull(source);
var tokens = node.GetTokens();
SyntaxToken? firstToken = null;
for (var i = 0; i < tokens.Count; i++)
{
var token = tokens[i];
if (!token.IsWhitespace())
{
firstToken = token;
break;
}
}
SyntaxToken? lastToken = null;
for (var i = tokens.Count - 1; i >= 0; i--)
{
var token = tokens[i];
if (!token.IsWhitespace())
{
lastToken = token;
break;
}
}
if (firstToken is null && lastToken is null)
{
return null;
}
var startPositionSpan = GetLinePositionSpan(firstToken, source, node.SpanStart);
var endPositionSpan = GetLinePositionSpan(lastToken, source, node.SpanStart);
var range = new Range
{
Start = new Position(startPositionSpan.Start.Line, startPositionSpan.Start.Character),
End = new Position(endPositionSpan.End.Line, endPositionSpan.End.Character)
};
return range;
// This is needed because SyntaxToken positions taken from GetTokens
// are relative to their parent node and not to the document.
static LinePositionSpan GetLinePositionSpan(SyntaxNode? node, RazorSourceDocument source, int parentStart)
{
ArgHelper.ThrowIfNull(node);
ArgHelper.ThrowIfNull(source);
var sourceText = source.Text;
var start = node.Position + parentStart;
var end = node.EndPosition + parentStart;
if (start == sourceText.Length && node.FullWidth == 0)
{
// Marker symbol at the end of the document.
var location = node.GetSourceLocation(source);
var position = location.ToLinePosition();
return new LinePositionSpan(position, position);
}
return sourceText.GetLinePositionSpan(start, end);
}
}
}

Просмотреть файл

@ -1,20 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class TextChangeExtensions
internal static partial class VsLspExtensions
{
public static TextEdit ToTextEdit(this TextChange textChange, SourceText sourceText)
{
if (sourceText is null)
{
throw new ArgumentNullException(nameof(sourceText));
}
ArgHelper.ThrowIfNull(textChange);
ArgHelper.ThrowIfNull(sourceText);
var range = textChange.Span.ToRange(sourceText);

Просмотреть файл

@ -1,11 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
internal static class TextDocumentIdentifierExtensions
internal static partial class VsLspExtensions
{
public static VSProjectContext? GetProjectContext(this TextDocumentIdentifier textDocumentIdentifier)
=> textDocumentIdentifier is VSTextDocumentIdentifier vsIdentifier

Просмотреть файл

@ -3,11 +3,10 @@
using Microsoft.AspNetCore.Razor;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class TextEditExtensions
internal static partial class VsLspExtensions
{
public static TextChange ToTextChange(this TextEdit textEdit, SourceText text)
{

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static partial class VsLspExtensions
{
public static Range ToRange(this TextSpan span, SourceText text)
=> text.GetLinePositionSpan(span).ToRange();
}

Просмотреть файл

@ -1,11 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
internal static class VSInternalClientCapabilitiesExtensions
internal static partial class VsLspExtensions
{
internal static VSInternalClientCapabilities ToVSInternalClientCapabilities(this ClientCapabilities clientCapabilities)
{

Просмотреть файл

@ -2,11 +2,10 @@
// Licensed under the MIT license. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class VSProjectContextExtensions
internal static partial class VsLspExtensions
{
internal static ProjectKey ToProjectKey(this VSProjectContext projectContext)
{

Просмотреть файл

@ -3,11 +3,10 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class WorkspaceEditExtensions
internal static partial class VsLspExtensions
{
public static bool TryGetDocumentChanges(this WorkspaceEdit workspaceEdit, [NotNullWhen(true)] out TextDocumentEdit[]? documentChanges)
{

Просмотреть файл

@ -0,0 +1,35 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using System.Diagnostics;
namespace Microsoft.VisualStudio.LanguageServer.Protocol;
internal static class VsLspFactory
{
private static readonly Position s_undefinedPosition = new(-1, -1);
private static readonly Range s_undefinedRange = new()
{
Start = s_undefinedPosition,
End = s_undefinedPosition
};
public static Range UndefinedRange
{
get
{
var undefinedRange = s_undefinedRange;
// Since Range is mutable, it's possible that something might modify it. If that happens, we should know!
Debug.Assert(
undefinedRange.Start.Line == -1 &&
undefinedRange.Start.Character == -1 &&
undefinedRange.End.Line == -1 &&
undefinedRange.End.Character == -1,
$"{nameof(VsLspFactory)}.{nameof(UndefinedRange)} has been corrupted. Current value: {undefinedRange.ToDisplayString()}");
return undefinedRange;
}
}
}

Просмотреть файл

@ -3,7 +3,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;

Просмотреть файл

@ -21,7 +21,7 @@ internal readonly record struct RemoteDocumentHighlight(
public static VsDocumentHighlight ToLspDocumentHighlight(RemoteDocumentHighlight r)
=> new VsDocumentHighlight
{
Range = r.Position.ToLspRange(),
Range = r.Position.ToRange(),
Kind = r.Kind
};
}

Просмотреть файл

@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Razor.Remote;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Response = Microsoft.CodeAnalysis.Razor.Remote.RemoteResponse<Microsoft.CodeAnalysis.Razor.Protocol.DocumentHighlight.RemoteDocumentHighlight[]?>;
namespace Microsoft.CodeAnalysis.Remote.Razor;

Просмотреть файл

@ -68,7 +68,7 @@ internal class CohostLinkedEditingRangeEndpoint(IRemoteServiceInvoker remoteServ
{
return new LinkedEditingRanges
{
Ranges = [span1.ToLspRange(), span2.ToLspRange()],
Ranges = [span1.ToRange(), span2.ToRange()],
WordPattern = LinkedEditingRangeHelper.WordPattern
};
}

Просмотреть файл

@ -65,9 +65,9 @@ internal class CohostUriPresentationEndpoint(
private async Task<WorkspaceEdit?> HandleRequestAsync(VSInternalUriPresentationParams request, TextDocument razorDocument, CancellationToken cancellationToken)
{
var data = await _remoteServiceInvoker.TryInvokeAsync<IRemoteUriPresentationService, RemoteResponse<TextChange?>>(
razorDocument.Project.Solution,
(service, solutionInfo, cancellationToken) => service.GetPresentationAsync(solutionInfo, razorDocument.Id, request.Range.ToLinePositionSpan(), request.Uris, cancellationToken),
cancellationToken).ConfigureAwait(false);
razorDocument.Project.Solution,
(service, solutionInfo, cancellationToken) => service.GetPresentationAsync(solutionInfo, razorDocument.Id, request.Range.ToLinePositionSpan(), request.Uris, cancellationToken),
cancellationToken).ConfigureAwait(false);
// If we got a response back, then we're good to go
if (data.Result is { } textChange)

Просмотреть файл

@ -9,7 +9,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.Completion;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Razor.LanguageClient.Extensions;

Просмотреть файл

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.Diagnostics;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Razor.LanguageClient.Extensions;

Просмотреть файл

@ -8,7 +8,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.Folding;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Razor.LanguageClient.Extensions;
using StreamJsonRpc;

Просмотреть файл

@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Razor.LanguageClient.DocumentMapping;
using Microsoft.VisualStudio.Text;

Просмотреть файл

@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Xunit;
using Xunit.Abstractions;

Просмотреть файл

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Xunit;
using Xunit.Abstractions;

Просмотреть файл

@ -16,6 +16,7 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Roslyn.Test.Utilities;
using Xunit;
using Xunit.Abstractions;

Просмотреть файл

@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using Xunit;
using Xunit.Abstractions;

Просмотреть файл

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Xunit;
using Xunit.Abstractions;

Просмотреть файл

@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Xunit;
using Xunit.Abstractions;
@ -96,7 +95,7 @@ public class RazorMapToDocumentRangesEndpointTest : LanguageServerTestBase
// Assert
Assert.NotNull(response);
Assert.Equal(RangeExtensions.UndefinedRange, response!.Ranges[0]);
Assert.Equal(VsLspFactory.UndefinedRange, response!.Ranges[0]);
Assert.Equal(1337, response.HostDocumentVersion);
}
@ -129,7 +128,7 @@ public class RazorMapToDocumentRangesEndpointTest : LanguageServerTestBase
// Assert
Assert.NotNull(response);
Assert.Equal(RangeExtensions.UndefinedRange, response!.Ranges[0]);
Assert.Equal(VsLspFactory.UndefinedRange, response!.Ranges[0]);
Assert.Equal(1337, response.HostDocumentVersion);
}
@ -162,7 +161,7 @@ public class RazorMapToDocumentRangesEndpointTest : LanguageServerTestBase
// Assert
Assert.NotNull(response);
Assert.Equal(RangeExtensions.UndefinedRange, response!.Ranges[0]);
Assert.Equal(VsLspFactory.UndefinedRange, response!.Ranges[0]);
Assert.Equal(1337, response.HostDocumentVersion);
}
@ -248,7 +247,7 @@ public class RazorMapToDocumentRangesEndpointTest : LanguageServerTestBase
// Assert
Assert.NotNull(response);
Assert.Equal(RangeExtensions.UndefinedRange, response!.Ranges[0]);
Assert.Equal(VsLspFactory.UndefinedRange, response!.Ranges[0]);
Assert.Equal(1337, response.HostDocumentVersion);
}

Просмотреть файл

@ -1140,14 +1140,14 @@ public partial class SemanticTokensTest(ITestOutputHelper testOutput) : TagHelpe
=> new()
{
TextDocument = new TextDocumentIdentifier { Uri = uri },
Ranges = ranges.Select(s => s.ToLspRange()).ToArray()
Ranges = ranges.Select(s => s.ToRange()).ToArray()
};
private static SemanticTokensRangeParams CreateVSSemanticTokensRangeParams(LinePositionSpan range, Uri uri)
=> new()
{
TextDocument = new TextDocumentIdentifier { Uri = uri },
Range = range.ToLspRange()
Range = range.ToRange()
};
private static void GenerateSemanticBaseline(string actualFileContents, string baselineFileName)

Просмотреть файл

@ -142,7 +142,7 @@ public class RazorLSPSpanMappingServiceTest : ToolingTestBase
{
// Arrange
var sourceTextRazor = SourceText.From("");
var response = new RazorMapToDocumentRangesResponse { Ranges = new Range[] { RangeExtensions.UndefinedRange } };
var response = new RazorMapToDocumentRangesResponse { Ranges = new Range[] { VsLspFactory.UndefinedRange } };
// Act
var results = RazorLSPSpanMappingService.GetMappedSpanResults(_mockDocumentUri.LocalPath, sourceTextRazor, response);

Просмотреть файл

@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Razor.LanguageClient.DocumentMapping;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.VisualStudio.Razor.LanguageClient;