Remove leftover shims for Omnisharp (#6483)

* Remove OmniSharp Shims
This commit is contained in:
Ryan Brandenburg 2022-06-06 13:41:34 -07:00 коммит произвёл GitHub
Родитель 3a8659bfdd
Коммит 5a043689dd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
42 изменённых файлов: 328 добавлений и 603 удалений

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

@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
InsertSpaces = true
};
var range = TextSpan.FromBounds(0, DocumentText.Length).AsVSRange(DocumentText);
var range = TextSpan.FromBounds(0, DocumentText.Length).AsRange(DocumentText);
var edits = await RazorFormattingService.FormatAsync(DocumentUri, DocumentSnapshot, range, options, CancellationToken.None);
#if DEBUG

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

@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
return codeAction;
}
if (!_documentMappingService.TryMapFromProjectedDocumentVSRange(codeDocument, textEdit.Range, MappingBehavior.Inclusive, out var originalRange))
if (!_documentMappingService.TryMapFromProjectedDocumentRange(codeDocument, textEdit.Range, MappingBehavior.Inclusive, out var originalRange))
{
// Text edit failed to map
return codeAction;

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

@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
// Internal for testing
internal async Task<IEnumerable<RazorVSInternalCodeAction>> GetCSharpCodeActionsFromLanguageServerAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
{
if (!_documentMappingService.TryMapToProjectedDocumentVSRange(
if (!_documentMappingService.TryMapToProjectedDocumentRange(
context.CodeDocument,
context.Request.Range,
out var projectedRange))
@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var newContext = context.Request.Context;
if (context.Request.Context is VSInternalCodeActionContext omniSharpContext &&
omniSharpContext.SelectionRange is not null &&
_documentMappingService.TryMapToProjectedDocumentVSRange(
_documentMappingService.TryMapToProjectedDocumentRange(
context.CodeDocument,
omniSharpContext.SelectionRange,
out var selectionRange))

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

@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var startTagTextEdit = new TextEdit
{
Range = startTag.Name.GetVSRange(context.CodeDocument.Source),
Range = startTag.Name.GetRange(context.CodeDocument.Source),
NewText = newTagName,
};
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
var endTagTextEdit = new TextEdit
{
Range = endTag.Name.GetVSRange(context.CodeDocument.Source),
Range = endTag.Name.GetRange(context.CodeDocument.Source),
NewText = newTagName,
};

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

@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation
var languageKind = _documentMappingService.GetLanguageKind(codeDocument, absoluteIndex, rightAssociative: false);
if (languageKind == RazorLanguageKind.CSharp)
{
if (_documentMappingService.TryMapToProjectedDocumentVSPosition(codeDocument, absoluteIndex, out var mappedPosition, out _))
if (_documentMappingService.TryMapToProjectedDocumentPosition(codeDocument, absoluteIndex, out var mappedPosition, out _))
{
// For C# locations, we attempt to return the corresponding position
// within the projected document

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

@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Debugging
// Now map that new C# location back to the host document
var mappingBehavior = GetMappingBehavior(documentSnapshot);
if (!_documentMappingService.TryMapFromProjectedDocumentVSRange(codeDocument, projectedRange, mappingBehavior, out var hostDocumentRange))
if (!_documentMappingService.TryMapFromProjectedDocumentRange(codeDocument, projectedRange, mappingBehavior, out var hostDocumentRange))
{
return null;
}

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

@ -13,8 +13,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using Omni = OmniSharp.Extensions.LanguageServer.Protocol.Models;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer
{
@ -37,9 +36,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
public DefaultRazorDocumentMappingService() { }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public override VS.TextEdit[] GetProjectedDocumentEdits(RazorCodeDocument codeDocument, VS.TextEdit[] edits)
public override TextEdit[] GetProjectedDocumentEdits(RazorCodeDocument codeDocument, TextEdit[] edits)
{
var projectedEdits = new List<VS.TextEdit>();
var projectedEdits = new List<TextEdit>();
var csharpSourceText = codeDocument.GetCSharpSourceText();
var lastNewLineAddedToLine = 0;
@ -58,8 +57,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
break;
}
var mappedStart = this.TryMapFromProjectedDocumentVSPosition(codeDocument, startIndex, out var hostDocumentStart, out _);
var mappedEnd = this.TryMapFromProjectedDocumentVSPosition(codeDocument, endIndex, out var hostDocumentEnd, out _);
var mappedStart = this.TryMapFromProjectedDocumentPosition(codeDocument, startIndex, out var hostDocumentStart, out _);
var mappedEnd = this.TryMapFromProjectedDocumentPosition(codeDocument, endIndex, out var hostDocumentEnd, out _);
// Ideal case, both start and end can be mapped so just return the edit
if (mappedStart && mappedEnd)
@ -68,10 +67,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// between this edit and the previous one, because the normalization will have swallowed it. See
// below for a more info.
var newText = (lastNewLineAddedToLine == range.Start.Line ? " " : "") + edit.NewText;
projectedEdits.Add(new VS.TextEdit()
projectedEdits.Add(new TextEdit()
{
NewText = newText,
Range = new VS.Range { Start = hostDocumentStart!, End = hostDocumentEnd! },
Range = new Range { Start = hostDocumentStart!, End = hostDocumentEnd! },
});
continue;
}
@ -105,7 +104,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// so we can ignore all but the last line. This assert ensures that is true, just in case something changes in Roslyn
Debug.Assert(lastNewLine == 0 || edit.NewText.Substring(0, lastNewLine - 1).All(c => c == '\r' || c == '\n'), "We are throwing away part of an edit that has more than just empty lines!");
var proposedRange = new Omni.Range(range.End.Line, 0, range.End.Line, range.End.Character);
var proposedRange = new Range { Start = new Position(range.End.Line, 0), End = new Position(range.End.Line, range.End.Character) };
startSync = proposedRange.Start.TryGetAbsoluteIndex(csharpSourceText, _logger, out startIndex);
endSync = proposedRange.End.TryGetAbsoluteIndex(csharpSourceText, _logger, out endIndex);
if (startSync is false || endSync is false)
@ -113,15 +112,15 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
break;
}
mappedStart = this.TryMapFromProjectedDocumentVSPosition(codeDocument, startIndex, out hostDocumentStart, out _);
mappedEnd = this.TryMapFromProjectedDocumentVSPosition(codeDocument, endIndex, out hostDocumentEnd, out _);
mappedStart = this.TryMapFromProjectedDocumentPosition(codeDocument, startIndex, out hostDocumentStart, out _);
mappedEnd = this.TryMapFromProjectedDocumentPosition(codeDocument, endIndex, out hostDocumentEnd, out _);
if (mappedStart && mappedEnd)
{
projectedEdits.Add(new VS.TextEdit()
projectedEdits.Add(new TextEdit()
{
NewText = edit.NewText.Substring(lastNewLine),
Range = new VS.Range { Start = hostDocumentStart!, End = hostDocumentEnd! },
Range = new Range { Start = hostDocumentStart!, End = hostDocumentEnd! },
});
continue;
}
@ -168,27 +167,27 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Only do anything if the end of the line in question is a valid mapping point (ie, a transition)
var endOfLine = line.Span.End;
if (this.TryMapFromProjectedDocumentVSPosition(codeDocument, endOfLine, out var hostDocumentIndex, out _))
if (this.TryMapFromProjectedDocumentPosition(codeDocument, endOfLine, out var hostDocumentIndex, out _))
{
if (range.Start.Line == lastNewLineAddedToLine)
{
// If we already added a newline to this line, then we don't want to add another one, but
// we do need to add a space between this edit and the previous one, because the normalization
// will have swallowed it.
projectedEdits.Add(new VS.TextEdit()
projectedEdits.Add(new TextEdit()
{
NewText = " " + edit.NewText,
Range = new VS.Range { Start = hostDocumentIndex, End = hostDocumentIndex }
Range = new Range { Start = hostDocumentIndex, End = hostDocumentIndex }
});
}
else
{
// Otherwise, add a newline and the real content, and remember where we added it
lastNewLineAddedToLine = range.Start.Line;
projectedEdits.Add(new VS.TextEdit()
projectedEdits.Add(new TextEdit()
{
NewText = Environment.NewLine + new string(' ', range.Start.Character) + edit.NewText,
Range = new VS.Range { Start = hostDocumentIndex, End = hostDocumentIndex }
Range = new Range { Start = hostDocumentIndex, End = hostDocumentIndex }
});
}
@ -200,9 +199,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
return projectedEdits.ToArray();
}
public override bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Omni.Range projectedRange, [NotNullWhen(true)] out Omni.Range? originalRange) => TryMapFromProjectedDocumentRange(codeDocument, projectedRange, MappingBehavior.Strict, out originalRange);
public override bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, [NotNullWhen(true)] out Range? originalRange) => TryMapFromProjectedDocumentRange(codeDocument, projectedRange, MappingBehavior.Strict, out originalRange);
public override bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Omni.Range projectedRange, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Omni.Range? originalRange)
public override bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Range? originalRange)
{
if (codeDocument is null)
{
@ -232,7 +231,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
}
}
public override bool TryMapToProjectedDocumentRange(RazorCodeDocument codeDocument, Omni.Range originalRange, [NotNullWhen(true)] out Omni.Range? projectedRange)
public override bool TryMapToProjectedDocumentRange(RazorCodeDocument codeDocument, Range originalRange, [NotNullWhen(true)] out Range? projectedRange)
{
if (codeDocument is null)
{
@ -257,7 +256,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var sourceText = codeDocument.GetSourceText();
var range = originalRange;
if (!IsRangeWithinDocument(range.AsVSRange(), sourceText))
if (!IsRangeWithinDocument(range, sourceText))
{
return false;
}
@ -287,14 +286,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
return false;
}
projectedRange = new Omni.Range(
projectedStart,
projectedEnd);
projectedRange = new Range
{
Start = projectedStart,
End = projectedEnd,
};
return true;
}
public override bool TryMapFromProjectedDocumentPosition(RazorCodeDocument codeDocument, int csharpAbsoluteIndex, [NotNullWhen(true)] out Omni.Position? originalPosition, out int originalIndex)
public override bool TryMapFromProjectedDocumentPosition(RazorCodeDocument codeDocument, int csharpAbsoluteIndex, [NotNullWhen(true)] out Position? originalPosition, out int originalIndex)
{
if (codeDocument is null)
{
@ -317,7 +318,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
originalIndex = mapping.OriginalSpan.AbsoluteIndex + distanceIntoGeneratedSpan;
var originalLocation = codeDocument.Source.Lines.GetLocation(originalIndex);
originalPosition = new Omni.Position(originalLocation.LineIndex, originalLocation.CharacterIndex);
originalPosition = new Position(originalLocation.LineIndex, originalLocation.CharacterIndex);
return true;
}
}
@ -328,13 +329,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
return false;
}
public override bool TryMapToProjectedDocumentOrNextCSharpPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Omni.Position? projectedPosition, out int projectedIndex)
public override bool TryMapToProjectedDocumentOrNextCSharpPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Position? projectedPosition, out int projectedIndex)
=> TryMapToProjectedDocumentPositionInternal(codeDocument, absoluteIndex, nextCSharpPositionOnFailure: true, out projectedPosition, out projectedIndex);
public override bool TryMapToProjectedDocumentPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Omni.Position? projectedPosition, out int projectedIndex)
public override bool TryMapToProjectedDocumentPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Position? projectedPosition, out int projectedIndex)
=> TryMapToProjectedDocumentPositionInternal(codeDocument, absoluteIndex, nextCSharpPositionOnFailure: false, out projectedPosition, out projectedIndex);
private static bool TryMapToProjectedDocumentPositionInternal(RazorCodeDocument codeDocument, int absoluteIndex, bool nextCSharpPositionOnFailure, [NotNullWhen(true)] out Omni.Position? projectedPosition, out int projectedIndex)
private static bool TryMapToProjectedDocumentPositionInternal(RazorCodeDocument codeDocument, int absoluteIndex, bool nextCSharpPositionOnFailure, [NotNullWhen(true)] out Position? projectedPosition, out int projectedIndex)
{
if (codeDocument is null)
{
@ -379,11 +380,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
projectedIndex = default;
return false;
static Omni.Position GetProjectedPosition(RazorCodeDocument codeDocument, int projectedIndex)
static Position GetProjectedPosition(RazorCodeDocument codeDocument, int projectedIndex)
{
var generatedSource = codeDocument.GetCSharpSourceText();
var generatedLinePosition = generatedSource.Lines.GetLinePosition(projectedIndex);
var projectedPosition = new Omni.Position(generatedLinePosition.Line, generatedLinePosition.Character);
var projectedPosition = new Position(generatedLinePosition.Line, generatedLinePosition.Character);
return projectedPosition;
}
}
@ -501,13 +502,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
}
}
private bool TryMapFromProjectedDocumentRangeStrict(RazorCodeDocument codeDocument, Omni.Range projectedRange, out Omni.Range? originalRange)
private bool TryMapFromProjectedDocumentRangeStrict(RazorCodeDocument codeDocument, Range projectedRange, out Range? originalRange)
{
originalRange = default;
var csharpSourceText = codeDocument.GetCSharpSourceText();
var range = projectedRange;
if (!IsRangeWithinDocument(range.AsVSRange(), csharpSourceText))
if (!IsRangeWithinDocument(range, csharpSourceText))
{
return false;
}
@ -524,14 +525,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
return false;
}
originalRange = new Omni.Range(
hostDocumentStart,
hostDocumentEnd);
originalRange = new Range
{
Start = hostDocumentStart,
End = hostDocumentEnd
};
return true;
}
private bool TryMapFromProjectedDocumentRangeInclusive(RazorCodeDocument codeDocument, Omni.Range projectedRange, [NotNullWhen(returnValue: true)] out Omni.Range? originalRange)
private bool TryMapFromProjectedDocumentRangeInclusive(RazorCodeDocument codeDocument, Range projectedRange, [NotNullWhen(returnValue: true)] out Range? originalRange)
{
originalRange = default;
@ -548,7 +551,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
if (startMappedDirectly && endMappedDirectly)
{
// We strictly mapped the start/end of the projected range.
originalRange = new Omni.Range(hostDocumentStart!, hostDocumentEnd!);
originalRange = new Range
{
Start = hostDocumentStart!,
End = hostDocumentEnd!
};
return true;
}
@ -596,18 +603,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
return unchecked((uint)(position - span.AbsoluteIndex) <= (uint)span.Length);
}
static Omni.Range ConvertMapping(RazorSourceDocument sourceDocument, SourceMapping mapping)
static Range ConvertMapping(RazorSourceDocument sourceDocument, SourceMapping mapping)
{
var startLocation = sourceDocument.Lines.GetLocation(mapping.OriginalSpan.AbsoluteIndex);
var endLocation = sourceDocument.Lines.GetLocation(mapping.OriginalSpan.AbsoluteIndex + mapping.OriginalSpan.Length);
var convertedRange = new Omni.Range(
new Omni.Position(startLocation.LineIndex, startLocation.CharacterIndex),
new Omni.Position(endLocation.LineIndex, endLocation.CharacterIndex));
var convertedRange = new Range
{
Start = new Position(startLocation.LineIndex, startLocation.CharacterIndex),
End = new Position(endLocation.LineIndex, endLocation.CharacterIndex)
};
return convertedRange;
}
}
private bool TryMapFromProjectedDocumentRangeInferred(RazorCodeDocument codeDocument, Omni.Range projectedRange, [NotNullWhen(returnValue: true)] out Omni.Range? originalRange)
private bool TryMapFromProjectedDocumentRangeInferred(RazorCodeDocument codeDocument, Range projectedRange, [NotNullWhen(returnValue: true)] out Range? originalRange)
{
// Inferred mapping behavior is a superset of inclusive mapping behavior so if the range is "inclusive" lets use that mapping.
if (TryMapFromProjectedDocumentRangeInclusive(codeDocument, projectedRange, out originalRange))
@ -653,7 +662,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var originalSpanBeforeProjectedRange = mappingBeforeProjectedRange.OriginalSpan;
var originalEndBeforeProjectedRange = originalSpanBeforeProjectedRange.AbsoluteIndex + originalSpanBeforeProjectedRange.Length;
var originalEndPositionBeforeProjectedRange = sourceDocument.Lines.GetLocation(originalEndBeforeProjectedRange);
var inferredStartPosition = new Omni.Position(originalEndPositionBeforeProjectedRange.LineIndex, originalEndPositionBeforeProjectedRange.CharacterIndex);
var inferredStartPosition = new Position(originalEndPositionBeforeProjectedRange.LineIndex, originalEndPositionBeforeProjectedRange.CharacterIndex);
if (mappingAfterProjectedRange != null)
{
@ -661,9 +670,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var originalSpanAfterProjectedRange = mappingAfterProjectedRange.OriginalSpan;
var originalStartPositionAfterProjectedRange = sourceDocument.Lines.GetLocation(originalSpanAfterProjectedRange.AbsoluteIndex);
var inferredEndPosition = new Omni.Position(originalStartPositionAfterProjectedRange.LineIndex, originalStartPositionAfterProjectedRange.CharacterIndex);
var inferredEndPosition = new Position(originalStartPositionAfterProjectedRange.LineIndex, originalStartPositionAfterProjectedRange.CharacterIndex);
originalRange = new Omni.Range()
originalRange = new Range()
{
Start = inferredStartPosition,
End = inferredEndPosition,
@ -676,9 +685,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
Debug.Assert(sourceDocument.Length > 0, "Source document length should be greater than 0 here because there's a mapping before us");
var endOfDocumentLocation = sourceDocument.Lines.GetLocation(sourceDocument.Length);
var endOfDocumentPosition = new Omni.Position(endOfDocumentLocation.LineIndex, endOfDocumentLocation.CharacterIndex);
var endOfDocumentPosition = new Position(endOfDocumentLocation.LineIndex, endOfDocumentLocation.CharacterIndex);
originalRange = new Omni.Range()
originalRange = new Range()
{
Start = inferredStartPosition,
End = endOfDocumentPosition,
@ -688,7 +697,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private static bool s_haveAsserted = false;
private bool IsRangeWithinDocument(VS.Range range, SourceText sourceText)
private bool IsRangeWithinDocument(Range range, SourceText sourceText)
{
// This might happen when the document that ranges were created against was not the same as the document we're consulting.
var result = IsPositionWithinDocument(range.Start, sourceText) && IsPositionWithinDocument(range.End, sourceText);
@ -702,7 +711,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
return result;
static bool IsPositionWithinDocument(VS.Position position, SourceText sourceText)
static bool IsPositionWithinDocument(Position position, SourceText sourceText)
{
return position.Line < sourceText.Lines.Count;
}

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

@ -193,8 +193,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
return null;
}
var range = property.Identifier.Span.AsVSRange(csharpText);
if (documentMappingService.TryMapFromProjectedDocumentVSRange(codeDocument, range, out var originalRange))
var range = property.Identifier.Span.AsRange(csharpText);
if (documentMappingService.TryMapFromProjectedDocumentRange(codeDocument, range, out var originalRange))
{
return originalRange;
}

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

@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
}
var tagName = startOrEndTag is MarkupTagHelperStartTagSyntax startTag ? startTag.Name : ((MarkupTagHelperEndTagSyntax)startOrEndTag).Name;
var tagNameRange = tagName.GetVSRange(syntaxTree.Source);
var tagNameRange = tagName.GetRange(syntaxTree.Source);
if (!tagNameRange.IntersectsOrTouches(diagnostic.Range))
{
@ -586,7 +586,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
return false;
}
if (!_documentMappingService.TryMapFromProjectedDocumentVSRange(
if (!_documentMappingService.TryMapFromProjectedDocumentRange(
codeDocument,
diagnostic.Range,
MappingBehavior.Inferred,

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

@ -6,22 +6,11 @@ using Microsoft.AspNetCore.Razor.LanguageServer.RazorLS;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using OmniSharpPosition = OmniSharp.Extensions.LanguageServer.Protocol.Models.Position;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
internal static class PositionExtensions
{
public static Position AsVSPosition(this OmniSharpPosition position)
{
return new Position(position.Line, position.Character);
}
public static OmniSharpPosition AsOSharpPosition(this Position position)
{
return new OmniSharpPosition(position.Line, position.Character);
}
public static bool TryGetAbsoluteIndex(this Position position, SourceText sourceText, ILogger logger, out int absoluteIndex)
{
if (position is null)
@ -37,21 +26,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return TryGetAbsoluteIndex(position.Character, position.Line, sourceText, logger, out absoluteIndex);
}
public static bool TryGetAbsoluteIndex(this OmniSharpPosition position, SourceText sourceText, ILogger logger, out int absoluteIndex)
{
if (position is null)
{
throw new ArgumentNullException(nameof(position));
}
if (sourceText is null)
{
throw new ArgumentNullException(nameof(sourceText));
}
return TryGetAbsoluteIndex(position.Character, position.Line, sourceText, logger, out absoluteIndex);
}
public static int CompareTo(this Position position, Position other)
{
if (position is null)
@ -68,22 +42,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return result != 0 ? result : position.Character.CompareTo(other.Character);
}
public static int CompareTo(this OmniSharpPosition position, OmniSharpPosition other)
{
if (position is null)
{
throw new ArgumentNullException(nameof(position));
}
if (other is null)
{
throw new ArgumentNullException(nameof(other));
}
var result = position.Line.CompareTo(other.Line);
return result != 0 ? result : position.Character.CompareTo(other.Character);
}
public static bool IsValid(this Position position, SourceText sourceText)
{
if (position is null)

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

@ -3,31 +3,40 @@
using System;
using Microsoft.CodeAnalysis.Text;
using OSharp = OmniSharp.Extensions.LanguageServer.Protocol.Models;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
internal static class RangeExtensions
{
public static readonly OSharp.Range UndefinedRange = new()
public static readonly Range UndefinedVSRange = new()
{
Start = new OSharp.Position(-1, -1),
End = new OSharp.Position(-1, -1)
Start = new Position(-1, -1),
End = new Position(-1, -1)
};
public static readonly VS.Range UndefinedVSRange = new()
public static bool IntersectsOrTouches(this Range range, Range other)
{
Start = new VS.Position(-1, -1),
End = new VS.Position(-1, -1)
};
if (range.IsBefore(other))
{
return false;
}
public static bool IntersectsOrTouches(this VS.Range range, VS.Range other)
{
return range.AsOmniSharpRange().IntersectsOrTouches(other.AsOmniSharpRange());
if (range.IsAfter(other))
{
return false;
}
return true;
}
public static bool OverlapsWith(this VS.Range range, VS.Range other)
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;
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;
public static bool OverlapsWith(this Range range, Range other)
{
if (range is null)
{
@ -55,7 +64,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return overlapStart.CompareTo(overlapEnd) < 0;
}
public static bool LineOverlapsWith(this VS.Range range, VS.Range other)
public static bool LineOverlapsWith(this Range range, Range other)
{
if (range is null)
{
@ -82,7 +91,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return overlapStart.CompareTo(overlapEnd) <= 0;
}
public static bool Contains(this VS.Range range, VS.Range other)
public static bool Contains(this Range range, Range other)
{
if (range is null)
{
@ -97,7 +106,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return range.Start.CompareTo(other.Start) <= 0 && range.End.CompareTo(other.End) >= 0;
}
public static bool SpansMultipleLines(this VS.Range range)
public static bool SpansMultipleLines(this Range range)
{
if (range is null)
{
@ -107,7 +116,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return range.Start.Line != range.End.Line;
}
public static TextSpan AsTextSpan(this VS.Range range, SourceText sourceText)
public static TextSpan AsTextSpan(this Range range, SourceText sourceText)
{
if (range is null)
{
@ -141,41 +150,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return new TextSpan(start, length);
}
public static TextSpan AsTextSpan(this OSharp.Range range, SourceText sourceText)
{
if (range is null)
{
throw new ArgumentNullException(nameof(range));
}
if (sourceText is null)
{
throw new ArgumentNullException(nameof(sourceText));
}
if (range.Start.Line >= sourceText.Lines.Count)
{
throw new ArgumentOutOfRangeException($"Range start line {range.Start.Line} matches or exceeds SourceText boundary {sourceText.Lines.Count}.");
}
if (range.End.Line >= sourceText.Lines.Count)
{
throw new ArgumentOutOfRangeException($"Range end line {range.End.Line} matches or exceeds SourceText boundary {sourceText.Lines.Count}.");
}
var start = sourceText.Lines[range.Start.Line].Start + range.Start.Character;
var end = sourceText.Lines[range.End.Line].Start + range.End.Character;
var length = end - start;
if (length < 0)
{
throw new ArgumentOutOfRangeException($"{range} resolved to zero or negative length.");
}
return new TextSpan(start, length);
}
public static Language.Syntax.TextSpan AsRazorTextSpan(this VS.Range range, SourceText sourceText)
public static Language.Syntax.TextSpan AsRazorTextSpan(this Range range, SourceText sourceText)
{
if (range is null)
{
@ -209,7 +184,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return new Language.Syntax.TextSpan(start, length);
}
public static bool IsUndefined(this VS.Range range)
public static bool IsUndefined(this Range range)
{
if (range is null)
{
@ -218,23 +193,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
return range == UndefinedVSRange;
}
public static VS.Range AsVSRange(this OSharp.Range range)
{
return new VS.Range
{
Start = range.Start.AsVSPosition(),
End = range.End.AsVSPosition()
};
}
public static OSharp.Range AsOmniSharpRange(this VS.Range range)
{
return new OSharp.Range
{
Start = range.Start.AsOSharpPosition(),
End = range.End.AsOSharpPosition()
};
}
}
}

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

@ -1,78 +0,0 @@
// 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.CodeAnalysis;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
internal static class RazorDocumentMappingServiceExtensions
{
public static bool TryMapToProjectedDocumentRange(this RazorDocumentMappingService service, RazorCodeDocument codeDocument, Range originalRange, [NotNullWhen(true)] out Range? projectedRange)
{
var result = service.TryMapToProjectedDocumentRange(codeDocument, originalRange.AsOmniSharpRange(), out var projectedOmniSharpRange);
projectedRange = projectedOmniSharpRange?.AsVSRange();
return result;
}
public static bool TryMapFromProjectedDocumentRange(this RazorDocumentMappingService service, RazorCodeDocument codeDocument, Range originalRange, [NotNullWhen(true)] out Range? projectedRange)
{
var result = service.TryMapFromProjectedDocumentRange(codeDocument, originalRange.AsOmniSharpRange(), out var projectedOmniSharpRange);
projectedRange = projectedOmniSharpRange?.AsVSRange();
return result;
}
public static bool TryMapFromProjectedDocumentVSRange(this RazorDocumentMappingService service, RazorCodeDocument codeDocument, Range range, [NotNullWhen(true)] out Range? originalRange)
=> TryMapFromProjectedDocumentVSRange(service, codeDocument, range, MappingBehavior.Strict, out originalRange);
public static bool TryMapFromProjectedDocumentVSRange(this RazorDocumentMappingService service, RazorCodeDocument codeDocument, Range range, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Range? originalRange)
{
if (service.TryMapFromProjectedDocumentRange(codeDocument, range.AsOmniSharpRange(), mappingBehavior, out var omniOriginalRange))
{
originalRange = omniOriginalRange.AsVSRange();
return true;
}
originalRange = null;
return false;
}
public static bool TryMapToProjectedDocumentVSPosition(this RazorDocumentMappingService service, RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Position? projectedPosition, out int projectedIndex)
{
if (service.TryMapToProjectedDocumentPosition(codeDocument, absoluteIndex, out var omniProjectedPosition, out projectedIndex))
{
projectedPosition = omniProjectedPosition.AsVSPosition();
return true;
}
projectedPosition = null;
return false;
}
public static bool TryMapToProjectedDocumentVSRange(this RazorDocumentMappingService service, RazorCodeDocument razorCodeDocument, Range range, [NotNullWhen(true)] out Range? projectedRange)
{
if (service.TryMapToProjectedDocumentRange(razorCodeDocument, range.AsOmniSharpRange(), out var omniRange))
{
projectedRange = omniRange.AsVSRange();
return true;
}
projectedRange = null;
return false;
}
public static bool TryMapFromProjectedDocumentVSPosition(this RazorDocumentMappingService service, RazorCodeDocument codeDocument, int csharpAbsoluteIndex, [NotNullWhen(true)] out Position? originalPosition, out int originalIndex)
{
var result = service.TryMapFromProjectedDocumentPosition(codeDocument, csharpAbsoluteIndex, out var omniOriginalPosition, out originalIndex);
originalPosition = omniOriginalPosition?.AsVSPosition();
return result;
}
}
}

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

@ -10,8 +10,7 @@ using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.LanguageServer.Formatting;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using Omni = OmniSharp.Extensions.LanguageServer.Protocol.Models;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
@ -75,14 +74,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
public static SyntaxNode? GetOwner(
this RazorSyntaxTree syntaxTree,
SourceText sourceText,
VS.Position position,
ILogger logger) => GetOwner(syntaxTree, sourceText, position.AsOSharpPosition(), logger);
public static SyntaxNode? GetOwner(
this RazorSyntaxTree syntaxTree,
SourceText sourceText,
Omni.Position position,
ILogger logger)
Position position,
ILogger logger)
{
if (syntaxTree is null)
{
@ -115,13 +108,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
public static SyntaxNode? GetOwner(
this RazorSyntaxTree syntaxTree,
SourceText sourceText,
VS.Range range,
ILogger logger) => GetOwner(syntaxTree, sourceText, range.AsOmniSharpRange(), logger);
public static SyntaxNode? GetOwner(
this RazorSyntaxTree syntaxTree,
SourceText sourceText,
Omni.Range range,
Range range,
ILogger logger)
{
if (syntaxTree is null)

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

@ -1,24 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
#nullable disable
using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.LanguageServer.Formatting;
using Microsoft.CodeAnalysis.Text;
using VSRange = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
using VSPosition = Microsoft.VisualStudio.LanguageServer.Protocol.Position;
using OmniRange = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using OmniPosition = OmniSharp.Extensions.LanguageServer.Protocol.Models.Position;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
internal static class SyntaxNodeExtensions
{
internal static bool TryGetPreviousSibling(this SyntaxNode syntaxNode, out SyntaxNode previousSibling)
internal static bool TryGetPreviousSibling(this SyntaxNode syntaxNode, [NotNullWhen(true)] out SyntaxNode? previousSibling)
{
var syntaxNodeParent = syntaxNode.Parent;
if (syntaxNodeParent is null)
@ -109,7 +105,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
}
}
public static VSRange GetVSRange(this SyntaxNode node, RazorSourceDocument source)
public static Range GetRange(this SyntaxNode node, RazorSourceDocument source)
{
if (node is null)
{
@ -122,34 +118,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
}
var lineSpan = node.GetLinePositionSpan(source);
var range = new VSRange
var range = new Range
{
Start = new VSPosition(lineSpan.Start.Line, lineSpan.Start.Character),
End = new VSPosition(lineSpan.End.Line, lineSpan.End.Character)
Start = new Position(lineSpan.Start.Line, lineSpan.Start.Character),
End = new Position(lineSpan.End.Line, lineSpan.End.Character)
};
return range;
}
public static OmniRange 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 OmniRange(new OmniPosition(lineSpan.Start.Line, lineSpan.Start.Character), new OmniPosition(lineSpan.End.Line, lineSpan.End.Character));
return range;
}
public static OmniRange GetRangeWithoutWhitespace(this SyntaxNode node, RazorSourceDocument source)
public static Range? GetRangeWithoutWhitespace(this SyntaxNode node, RazorSourceDocument source)
{
if (node is null)
{
@ -163,7 +141,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
var tokens = node.GetTokens();
SyntaxToken firstToken = null;
SyntaxToken? firstToken = null;
for (var i = 0; i < tokens.Count; i++)
{
var token = tokens[i];
@ -174,7 +152,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
}
}
SyntaxToken lastToken = null;
SyntaxToken? lastToken = null;
for (var i = tokens.Count - 1; i >= 0; i--)
{
var token = tokens[i];
@ -193,17 +171,17 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
var startPositionSpan = GetLinePositionSpan(firstToken, source, node.SpanStart);
var endPositionSpan = GetLinePositionSpan(lastToken, source, node.SpanStart);
var range = new OmniRange
var range = new Range
{
Start = new OmniPosition(startPositionSpan.Start.Line, startPositionSpan.Start.Character),
End = new OmniPosition(endPositionSpan.End.Line, endPositionSpan.End.Character)
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)
static LinePositionSpan GetLinePositionSpan(SyntaxNode? node, RazorSourceDocument source, int parentStart)
{
if (node is null)
{

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

@ -5,8 +5,7 @@
using System;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
@ -27,20 +26,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
Range = range
};
}
public static VS.TextEdit AsVSTextEdit(this TextChange textChange, SourceText sourceText)
{
if (sourceText is null)
{
throw new ArgumentNullException(nameof(sourceText));
}
var range = textChange.Span.AsVSRange(sourceText);
return new VS.TextEdit()
{
NewText = textChange.NewText,
Range = range
};
}
}
}

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

@ -3,14 +3,13 @@
using System;
using Microsoft.CodeAnalysis.Text;
using Omni = OmniSharp.Extensions.LanguageServer.Protocol.Models;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
internal static class TextEditExtensions
{
public static TextChange AsTextChange(this Omni.TextEdit textEdit, SourceText sourceText)
public static TextChange AsTextChange(this TextEdit textEdit, SourceText sourceText)
{
if (textEdit is null)
{
@ -25,39 +24,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
var span = textEdit.Range.AsTextSpan(sourceText);
return new TextChange(span, textEdit.NewText);
}
public static TextChange AsTextChange(this VS.TextEdit textEdit, SourceText sourceText)
{
if (textEdit is null)
{
throw new ArgumentNullException(nameof(textEdit));
}
if (sourceText is null)
{
throw new ArgumentNullException(nameof(sourceText));
}
var span = textEdit.Range.AsTextSpan(sourceText);
return new TextChange(span, textEdit.NewText);
}
public static VS.TextEdit AsVSTextEdit(this Omni.TextEdit textEdit)
{
return new VS.TextEdit
{
NewText = textEdit.NewText,
Range = textEdit.Range.AsVSRange(),
};
}
public static Omni.TextEdit AsOmniSharpTextEdit(this VS.TextEdit textEdit)
{
return new Omni.TextEdit
{
NewText = textEdit.NewText,
Range = textEdit.Range.AsOmniSharpRange(),
};
}
}
}

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

@ -3,16 +3,13 @@
using System;
using Microsoft.CodeAnalysis.Text;
using VSRange = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
using VSPosition = Microsoft.VisualStudio.LanguageServer.Protocol.Position;
using OmniRange = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using OmniPosition = OmniSharp.Extensions.LanguageServer.Protocol.Models.Position;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
{
internal static class TextSpanExtensions
{
public static VSRange AsVSRange(this TextSpan span, SourceText sourceText)
public static Range AsRange(this TextSpan span, SourceText sourceText)
{
if (sourceText is null)
{
@ -21,28 +18,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions
sourceText.GetLinesAndOffsets(span, out var startLine, out var startChar, out var endLine, out var endChar);
var range = new VSRange
var range = new Range
{
Start = new VSPosition(startLine, startChar),
End = new VSPosition(endLine, endChar)
};
return range;
}
public static OmniRange AsRange(this TextSpan span, SourceText sourceText)
{
if (sourceText is null)
{
throw new ArgumentNullException(nameof(sourceText));
}
sourceText.GetLinesAndOffsets(span, out var startLine, out var startChar, out var endLine, out var endChar);
var range = new OmniRange
{
Start = new OmniPosition(startLine, startChar),
End = new OmniPosition(endLine, endChar)
Start = new Position(startLine, startChar),
End = new Position(endLine, endChar)
};
return range;

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

@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
// Formatting options will already be set in the workspace.
var changes = CodeAnalysis.Formatting.Formatter.GetFormattedTextChanges(root, spanToFormat, workspace, cancellationToken: cancellationToken);
var edits = changes.Select(c => c.AsVSTextEdit(csharpSourceText)).ToArray();
var edits = changes.Select(c => c.AsTextEdit(csharpSourceText)).ToArray();
return edits;
}

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

@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
_logger.LogTestOnly($"Generated C#:\r\n{context.CSharpSourceText}");
var finalChanges = changedText.GetTextChanges(originalText);
var finalEdits = finalChanges.Select(f => f.AsVSTextEdit(originalText)).ToArray();
var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray();
return new FormattingResult(finalEdits);
}
@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
}
// These should already be remapped.
var range = span.AsVSRange(sourceText);
var range = span.AsRange(sourceText);
var edits = await CSharpFormatter.FormatAsync(context, range, cancellationToken);
csharpEdits.AddRange(edits.Where(e => range.Contains(e.Range)));
}

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

@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
// 2. The indentation due to Razor and HTML constructs
var text = context.SourceText;
range ??= TextSpan.FromBounds(0, text.Length).AsVSRange(text);
range ??= TextSpan.FromBounds(0, text.Length).AsRange(text);
// To help with figuring out the correct indentation, first we will need the indentation
// that the C# formatter wants to apply in the following locations,

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

@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
return result;
}
textEdits = formattingChanges.Select(change => change.AsVSTextEdit(csharpText)).ToArray();
textEdits = formattingChanges.Select(change => change.AsTextEdit(csharpText)).ToArray();
_logger.LogInformation($"Received {textEdits.Length} results from C#.");
}
@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
// Apply the format on type edits sent over by the client.
var formattedText = ApplyChangesAndTrackChange(originalText, changes, out _, out var spanAfterFormatting);
var changedContext = await context.WithTextAsync(formattedText);
var rangeAfterFormatting = spanAfterFormatting.AsVSRange(formattedText);
var rangeAfterFormatting = spanAfterFormatting.AsRange(formattedText);
cancellationToken.ThrowIfCancellationRequested();
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
// Now that we have made all the necessary changes to the document. Let's diff the original vs final version and return the diff.
var finalChanges = cleanedText.GetTextChanges(originalText);
var finalEdits = finalChanges.Select(f => f.AsVSTextEdit(originalText)).ToArray();
var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray();
if (context.AutomaticallyAddUsings)
{
@ -272,7 +272,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
{
var newLineCount = change.NewText is null ? 0 : change.NewText.Split('\n').Length - 1;
var range = change.Span.AsVSRange(text);
var range = change.Span.AsRange(text);
Debug.Assert(range.Start.Line <= range.End.Line, "Invalid range.");
// For convenience, since we're already iterating through things, we also find the extremes
@ -298,14 +298,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
private static List<TextChange> CleanupDocument(FormattingContext context, Range? range = null)
{
var text = context.SourceText;
range ??= TextSpan.FromBounds(0, text.Length).AsVSRange(text);
range ??= TextSpan.FromBounds(0, text.Length).AsRange(text);
var csharpDocument = context.CodeDocument.GetCSharpDocument();
var changes = new List<TextChange>();
foreach (var mapping in csharpDocument.SourceMappings)
{
var mappingSpan = new TextSpan(mapping.OriginalSpan.AbsoluteIndex, mapping.OriginalSpan.Length);
var mappingRange = mappingSpan.AsVSRange(text);
var mappingRange = mappingSpan.AsRange(text);
if (!range.LineOverlapsWith(mappingRange))
{
// We don't care about this range. It didn't change.
@ -514,7 +514,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var changes = edits.Select(e => e.AsTextChange(originalText));
originalTextWithChanges = originalText.WithChanges(changes);
var cleanChanges = SourceTextDiffer.GetMinimalTextChanges(originalText, originalTextWithChanges, lineDiffOnly: false);
var cleanEdits = cleanChanges.Select(c => c.AsVSTextEdit(originalText)).ToArray();
var cleanEdits = cleanChanges.Select(c => c.AsTextEdit(originalText)).ToArray();
return cleanEdits;
}
}

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

@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
// Only send back the minimum edits
var minimalChanges = SourceTextDiffer.GetMinimalTextChanges(originalText, changedText, lineDiffOnly: false);
var finalEdits = minimalChanges.Select(f => f.AsVSTextEdit(originalText)).ToArray();
var finalEdits = minimalChanges.Select(f => f.AsTextEdit(originalText)).ToArray();
return finalEdits;
}
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var encompassingChange = new TextChange(spanBeforeChange, newText);
return encompassingChange.AsVSTextEdit(sourceText);
return encompassingChange.AsTextEdit(sourceText);
}
}
}

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

@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
}
var finalChanges = changedText.GetTextChanges(originalText);
var finalEdits = finalChanges.Select(f => f.AsVSTextEdit(originalText)).ToArray();
var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray();
return new FormattingResult(finalEdits);
}

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

@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
}
var span = TextSpan.FromBounds(0, codeDocument.Source.Length);
var range = span.AsVSRange(codeDocument.GetSourceText());
var range = span.AsRange(codeDocument.GetSourceText());
var edits = await _razorFormattingService.FormatAsync(request.TextDocument.Uri, document, range, request.Options, cancellationToken);
return edits;

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

@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
{
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
changedText = changedText.WithChanges(formattingChanges);
var finalChanges = changedText.GetTextChanges(originalText);
var finalEdits = finalChanges.Select(f => f.AsVSTextEdit(originalText)).ToArray();
var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray();
return new FormattingResult(finalEdits);
}
@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var start = brace.GetRange(source).Start;
var edit = new TextEdit
{
Range = new Range(start, start),
Range = new Range { Start = start, End = start },
NewText = " "
};
edits.Add(edit);
@ -354,7 +354,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var edit = new TextEdit
{
NewText = newText,
Range = new Range(openBraceRange.End, openBraceRange.End),
Range = new Range { Start = openBraceRange.End, End = openBraceRange.End },
};
edits.Add(edit);
didFormat = true;
@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var edit = new TextEdit
{
NewText = context.NewLineString,
Range = new Range(codeRange.End, codeRange.End),
Range = new Range { Start = codeRange.End, End = codeRange.End },
};
edits.Add(edit);
didFormat = true;

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

@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
{
Debug.Assert(binding.Descriptors.Any());
var range = containingTagNameToken.GetVSRange(codeDocument.Source);
var range = containingTagNameToken.GetRange(codeDocument.Source);
var result = ElementInfoToHover(binding.Descriptors, range, clientCapabilities);
return result;
@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
}
var attributeName = attribute.GetContent();
var range = attribute.GetVSRange(codeDocument.Source);
var range = attribute.GetRange(codeDocument.Source);
// Include the @ in the range
switch (attribute.Parent.Kind)

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

@ -133,7 +133,7 @@ internal class InlineCompletionEndpoint : IVSInlineCompletionEndpoint
// Map to the location in the C# document.
if (languageKind != RazorLanguageKind.CSharp ||
!_documentMappingService.TryMapToProjectedDocumentVSPosition(codeDocument, hostDocumentIndex, out var projectedPosition, out _))
!_documentMappingService.TryMapToProjectedDocumentPosition(codeDocument, hostDocumentIndex, out var projectedPosition, out _))
{
_logger.LogInformation($"Unsupported location for {request.TextDocument.Uri}.");
return null;

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

@ -1,24 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
#nullable disable
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Microsoft.AspNetCore.Razor.LanguageServer
{
public static class RazorDefaults
{
public static DocumentSelector Selector { get; } = new DocumentSelector(
new DocumentFilter()
{
Pattern = "**/*.{cshtml,razor}"
});
public static RazorConfiguration Configuration { get; } = FallbackRazorConfiguration.Latest;
public static string RootNamespace { get; } = null;
public static string? RootNamespace { get; } = null;
}
}

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

@ -4,26 +4,25 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using Omni = OmniSharp.Extensions.LanguageServer.Protocol.Models;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal abstract class RazorDocumentMappingService
{
public abstract VS.TextEdit[] GetProjectedDocumentEdits(RazorCodeDocument codeDocument, VS.TextEdit[] edits);
public abstract TextEdit[] GetProjectedDocumentEdits(RazorCodeDocument codeDocument, TextEdit[] edits);
public abstract bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Omni.Range projectedRange, [NotNullWhen(true)] out Omni.Range? originalRange);
public abstract bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, [NotNullWhen(true)] out Range? originalRange);
public abstract bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Omni.Range projectedRange, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Omni.Range? originalRange);
public abstract bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Range? originalRange);
public abstract bool TryMapToProjectedDocumentRange(RazorCodeDocument codeDocument, Omni.Range originalRange, [NotNullWhen(true)] out Omni.Range? projectedRange);
public abstract bool TryMapToProjectedDocumentRange(RazorCodeDocument codeDocument, Range originalRange, [NotNullWhen(true)] out Range? projectedRange);
public abstract bool TryMapFromProjectedDocumentPosition(RazorCodeDocument codeDocument, int csharpAbsoluteIndex, [NotNullWhen(true)] out Omni.Position? originalPosition, out int originalIndex);
public abstract bool TryMapFromProjectedDocumentPosition(RazorCodeDocument codeDocument, int csharpAbsoluteIndex, [NotNullWhen(true)] out Position? originalPosition, out int originalIndex);
public abstract bool TryMapToProjectedDocumentPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Omni.Position? projectedPosition, out int projectedIndex);
public abstract bool TryMapToProjectedDocumentPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Position? projectedPosition, out int projectedIndex);
public abstract bool TryMapToProjectedDocumentOrNextCSharpPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Omni.Position? projectedPosition, out int projectedIndex);
public abstract bool TryMapToProjectedDocumentOrNextCSharpPosition(RazorCodeDocument codeDocument, int absoluteIndex, [NotNullWhen(true)] out Position? projectedPosition, out int projectedIndex);
public abstract RazorLanguageKind GetLanguageKind(RazorCodeDocument codeDocument, int originalIndex, bool rightAssociative);
}

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

@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var languageKind = _documentMappingService.GetLanguageKind(codeDocument, hostDocumentIndex, rightAssociative: false);
if (languageKind == RazorLanguageKind.CSharp)
{
if (_documentMappingService.TryMapToProjectedDocumentVSPosition(codeDocument, hostDocumentIndex, out var projectedPosition, out var projectedIndex))
if (_documentMappingService.TryMapToProjectedDocumentPosition(codeDocument, hostDocumentIndex, out var projectedPosition, out var projectedIndex))
{
// For C# locations, we attempt to return the corresponding position
// within the projected document
@ -190,7 +190,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
var projectedRange = request.ProjectedRanges[i];
if (codeDocument.IsUnsupported() ||
!_documentMappingService.TryMapFromProjectedDocumentVSRange(codeDocument, projectedRange, request.MappingBehavior, out var originalRange))
!_documentMappingService.TryMapFromProjectedDocumentRange(codeDocument, 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.UndefinedVSRange;

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

@ -6,7 +6,7 @@
using System;
using MediatR;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer
{
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
public Uri RazorDocumentUri { get; set; }
public VS.Range[] ProjectedRanges { get; set; }
public Range[] ProjectedRanges { get; set; }
public MappingBehavior MappingBehavior { get; set; }
}

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

@ -271,7 +271,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
{
new TextEdit()
{
Range = element.StartTag.Name.GetVSRange(codeDocument.Source),
Range = element.StartTag.Name.GetRange(codeDocument.Source),
NewText = newName,
},
};
@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
{
edits.Add(new TextEdit()
{
Range = element.EndTag.Name.GetVSRange(codeDocument.Source),
Range = element.EndTag.Name.GetRange(codeDocument.Source),
NewText = newName,
});
}

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

@ -441,7 +441,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
}
var source = _razorCodeDocument.Source;
var range = node.GetVSRange(source);
var range = node.GetRange(source);
// LSP spec forbids multi-line tokens, so we need to split this up.
if (range.Start.Line != range.End.Line)
@ -476,7 +476,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
// This also stops us from returning data for " ", which seems like a nice side-effect as it's not likly to have any colorization anyway.
if (!token.ContainsOnlyWhitespace())
{
var tokenRange = token.GetVSRange(source);
var tokenRange = token.GetRange(source);
var semantic = new SemanticRange(semanticKind, tokenRange, modifier: 0);
AddRange(semantic);

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

@ -23,7 +23,6 @@ using Xunit;
using Microsoft.AspNetCore.Razor.LanguageServer.Common.Extensions;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
using Omni = OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
@ -32,7 +31,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
public class CodeActionEndpointTest : LanguageServerTestBase
{
private readonly RazorDocumentMappingService _documentMappingService = Mock.Of<RazorDocumentMappingService>(s => s.TryMapToProjectedDocumentRange(It.IsAny<RazorCodeDocument>(), It.IsAny<Omni.Range>(), out It.Ref<Omni.Range>.IsAny) == false, MockBehavior.Strict);
private readonly RazorDocumentMappingService _documentMappingService = Mock.Of<RazorDocumentMappingService>(s => s.TryMapToProjectedDocumentRange(It.IsAny<RazorCodeDocument>(), It.IsAny<Range>(), out It.Ref<Range>.IsAny) == false, MockBehavior.Strict);
private readonly DocumentResolver _emptyDocumentResolver = Mock.Of<DocumentResolver>(r => r.TryResolveDocument(It.IsAny<string>(), out It.Ref<DocumentSnapshot>.IsAny) == false, MockBehavior.Strict);
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = Mock.Of<LanguageServerFeatureOptions>(l => l.SupportsFileManipulation == true, MockBehavior.Strict);
private readonly ClientNotifierServiceBase _languageServer = Mock.Of<ClientNotifierServiceBase>(MockBehavior.Strict);
@ -582,9 +581,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var documentPath = "C:/path/to/Page.razor";
var codeDocument = CreateCodeDocument("@code {}");
var documentResolver = CreateDocumentResolver(documentPath, codeDocument);
Omni.Range projectedRange = null;
Range projectedRange = null;
var documentMappingService = Mock.Of<DefaultRazorDocumentMappingService>(
d => d.TryMapToProjectedDocumentRange(It.IsAny<RazorCodeDocument>(), It.IsAny<Omni.Range>(), out projectedRange) == false
d => d.TryMapToProjectedDocumentRange(It.IsAny<RazorCodeDocument>(), It.IsAny<Range>(), out projectedRange) == false
, MockBehavior.Strict);
var codeActionEndpoint = new CodeActionEndpoint(
documentMappingService,
@ -626,7 +625,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var codeDocument = CreateCodeDocument("@code {}");
var documentResolver = CreateDocumentResolver(documentPath, codeDocument);
var projectedRange = new Range { Start = new Position(15, 2), End = new Position(15, 2) };
var documentMappingService = CreateDocumentMappingService(projectedRange.AsOmniSharpRange());
var documentMappingService = CreateDocumentMappingService(projectedRange);
var languageServer = CreateLanguageServer();
var codeActionEndpoint = new CodeActionEndpoint(
documentMappingService,
@ -673,11 +672,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
Assert.Equal(projectedRange, diagnostics[1].Range);
}
private static DefaultRazorDocumentMappingService CreateDocumentMappingService(Omni.Range projectedRange = null)
private static DefaultRazorDocumentMappingService CreateDocumentMappingService(Range projectedRange = null)
{
projectedRange ??= new Omni.Range { Start = new Omni.Position(5, 2), End = new Omni.Position(5, 2) };
projectedRange ??= new Range { Start = new Position(5, 2), End = new Position(5, 2) };
var documentMappingService = Mock.Of<DefaultRazorDocumentMappingService>(
d => d.TryMapToProjectedDocumentRange(It.IsAny<RazorCodeDocument>(), It.IsAny<Omni.Range>(), out projectedRange) == true
d => d.TryMapToProjectedDocumentRange(It.IsAny<RazorCodeDocument>(), It.IsAny<Range>(), out projectedRange) == true
, MockBehavior.Strict);
return documentMappingService;
}

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

@ -9,10 +9,10 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
using Microsoft.AspNetCore.Razor.Language.Legacy;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Xunit;
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.AspNetCore.Razor.LanguageServer
{
@ -699,7 +699,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
new SourceMapping(new SourceSpan(0, 1), new SourceSpan(0, 1)),
new SourceMapping(new SourceSpan(16, 19), new SourceSpan(11, 19))
});
var range = new Range(new Position(1, 10), new Position(1, 13));
var range = new Range { Start = new Position(1, 10), End = new Position(1, 13) };
// Act & Assert
if (service.TryMapToProjectedDocumentRange(
@ -729,7 +729,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
new[] {
new SourceMapping(new SourceSpan(0, 1), new SourceSpan(0, 1)),
});
var range = new Range(new Position(1, 10), new Position(1, 13));
var range = new Range { Start = new Position(1, 10), End = new Position(1, 13) };
// Act
var result = service.TryMapToProjectedDocumentRange(
@ -755,7 +755,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
new SourceMapping(new SourceSpan(16, 3), new SourceSpan(11, 3)),
new SourceMapping(new SourceSpan(19, 10), new SourceSpan(5, 10))
});
var range = new Range(new Position(1, 10), new Position(1, 13));
var range = new Range { Start = new Position(1, 10), End = new Position(1, 13) };
// Act
var result = service.TryMapToProjectedDocumentRange(

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

@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
TestFileMarkupParser.GetSpan(content, out content, out var selection);
SetupDocument(out var codeDocument, out _, content);
var expectedRange = selection.AsVSRange(codeDocument.GetSourceText());
var expectedRange = selection.AsRange(codeDocument.GetSourceText());
var mappingService = new DefaultRazorDocumentMappingService(LoggerFactory);
@ -333,7 +333,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
TestFileMarkupParser.GetSpan(content, out content, out var selection);
SetupDocument(out var codeDocument, out _, content);
var expectedRange = selection.AsVSRange(codeDocument.GetSourceText());
var expectedRange = selection.AsRange(codeDocument.GetSourceText());
var mappingService = new DefaultRazorDocumentMappingService(LoggerFactory);
@ -360,7 +360,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
TestFileMarkupParser.GetSpan(content, out content, out var selection);
SetupDocument(out var codeDocument, out _, content);
var expectedRange = selection.AsVSRange(codeDocument.GetSourceText());
var expectedRange = selection.AsRange(codeDocument.GetSourceText());
var mappingService = new DefaultRazorDocumentMappingService(LoggerFactory);
@ -391,7 +391,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
TestFileMarkupParser.GetSpan(content, out content, out var selection);
SetupDocument(out var codeDocument, out _, content);
var expectedRange = selection.AsVSRange(codeDocument.GetSourceText());
var expectedRange = selection.AsRange(codeDocument.GetSourceText());
var mappingService = new DefaultRazorDocumentMappingService(LoggerFactory);

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

@ -17,7 +17,6 @@ using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using OmniSharp.Extensions.JsonRpc;
using Xunit;
using OmniSharpRange = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation
@ -90,10 +89,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation
var codeDocument = TestRazorCodeDocument.Create("@counter");
var uri = new Uri("file://path/test.razor");
var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument);
var projectedRange = It.IsAny<OmniSharpRange>();
var projectedRange = It.IsAny<Range>();
var documentMappingService = Mock.Of<RazorDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.CSharp &&
s.TryMapToProjectedDocumentRange(codeDocument, It.IsAny<OmniSharpRange>(), out projectedRange) == true, MockBehavior.Strict);
s.TryMapToProjectedDocumentRange(codeDocument, It.IsAny<Range>(), out projectedRange) == true, MockBehavior.Strict);
var responseRouterReturns = new Mock<IResponseRouterReturns>(MockBehavior.Strict);
responseRouterReturns

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

@ -18,7 +18,6 @@ using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using OmniSharp.Extensions.JsonRpc;
using Xunit;
using OmniSharpRange = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation
@ -420,10 +419,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation
var codeDocument = TestRazorCodeDocument.Create("@counter");
var uri = new Uri("file://path/test.razor");
var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument);
var projectedRange = It.IsAny<OmniSharpRange>();
var projectedRange = It.IsAny<Range>();
var documentMappingService = Mock.Of<RazorDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.CSharp &&
s.TryMapToProjectedDocumentRange(codeDocument, It.IsAny<OmniSharpRange>(), out projectedRange) == true, MockBehavior.Strict);
s.TryMapToProjectedDocumentRange(codeDocument, It.IsAny<Range>(), out projectedRange) == true, MockBehavior.Strict);
var searchEngine = Mock.Of<RazorComponentSearchEngine>(MockBehavior.Strict);
var responseRouterReturns = new Mock<IResponseRouterReturns>(MockBehavior.Strict);

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

@ -32,11 +32,10 @@ using Microsoft.WebTools.Shared;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.JsonRpc;
using Omni = OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using Xunit;
using FormattingOptions = Microsoft.VisualStudio.LanguageServer.Protocol.FormattingOptions;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
{
@ -69,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
{
var response = new RazorDocumentFormattingResponse();
response.Edits = Array.Empty<VS.TextEdit>();
response.Edits = Array.Empty<TextEdit>();
// TODO: Update WebTools dependency and call via reflection
@ -81,7 +80,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var options = @params.Options;
var response = new RazorDocumentFormattingResponse();
response.Edits = Array.Empty<VS.TextEdit>();
response.Edits = Array.Empty<TextEdit>();
var codeDocument = _documents[@params.TextDocument.Uri.GetAbsoluteOrUNCPath()];
var generatedHtml = codeDocument.GetHtmlDocument().GeneratedHtml;
@ -108,7 +107,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var applyFormatEditsHandler = Activator.CreateInstance(editHandlerType, new object[] { bufferManager, threadSwitcher, textBufferFactoryService });
// Make sure the buffer manager knows about the source document
var documentUri = Omni.DocumentUri.From($"file:///{@params.TextDocument.Uri}");
var documentUri = OmniSharp.Extensions.LanguageServer.Protocol.DocumentUri.From($"file:///{@params.TextDocument.Uri}");
var contentTypeName = HtmlContentTypeDefinition.HtmlContentType;
var initialContent = generatedHtml;
var snapshotVersionFromLSP = 0;
@ -161,7 +160,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var changes = Formatter.GetFormattedTextChanges(root, spanToFormat, csharpDocument.Project.Solution.Workspace);
response.Edits = changes.Select(c => c.AsVSTextEdit(csharpSourceText)).ToArray();
response.Edits = changes.Select(c => c.AsTextEdit(csharpSourceText)).ToArray();
}
else
{
@ -181,17 +180,17 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
#pragma warning restore IDE1006 // Naming Styles
#pragma warning restore CS0649 // Field 'name' is never assigned to, and will always have its default value
public VS.TextEdit AsTextEdit(SourceText sourceText)
public TextEdit AsTextEdit(SourceText sourceText)
{
var startLinePosition = sourceText.Lines.GetLinePosition(Position);
var endLinePosition = sourceText.Lines.GetLinePosition(Position + Length);
return new VS.TextEdit
return new TextEdit
{
Range = new VS.Range()
Range = new Range()
{
Start = new VS.Position(startLinePosition.Line, startLinePosition.Character),
End = new VS.Position(endLinePosition.Line, endLinePosition.Character),
Start = new Position(startLinePosition.Line, startLinePosition.Character),
End = new Position(endLinePosition.Line, endLinePosition.Character),
},
NewText = NewText,
};

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

@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
var span = spans.IsEmpty ? new TextSpan(0, input.Length) : spans.Single();
var source = SourceText.From(input);
var range = span.AsVSRange(source);
var range = span.AsRange(source);
var path = "file:///path/to/Document." + fileKind;
var uri = new Uri(path);

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

@ -14,7 +14,8 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Moq;
using OmniSharp.Extensions.JsonRpc;
using Xunit;
using VS = Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
{
@ -34,10 +35,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 3, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 3, Character = 0 }
};
var csharpTokens = new ProvideSemanticTokensResponse(tokens: Array.Empty<int>(), hostDocumentSyncVersion: 1);
@ -53,10 +54,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 4, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 4, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -70,10 +71,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
<!--@{var d = ""string"";@<a></a>}-->
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -87,10 +88,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
@{ var d = }
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = new ProvideSemanticTokensResponse(tokens: Array.Empty<int>(), hostDocumentSyncVersion: null);
@ -104,10 +105,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
@(DateTime.Now)
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -122,10 +123,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
@d
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 3, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 3, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -139,10 +140,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
@{ var d = }
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -156,10 +157,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
@{ var d = }
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -175,10 +176,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 4, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 4, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -196,10 +197,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
second</p>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 4, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 4, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -212,10 +213,10 @@ second</p>
var documentText = @"<str class='
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -228,10 +229,10 @@ second</p>
var documentText = @"<p attr />
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -245,10 +246,10 @@ second</p>
<input/>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -262,10 +263,10 @@ second</p>
<!-- comment with comma's -->
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -279,10 +280,10 @@ second</p>
<!-- comment
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -296,10 +297,10 @@ second</p>
<!input/>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -315,10 +316,10 @@ second</p>
@* comment
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -332,10 +333,10 @@ second</p>
<test1></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -349,10 +350,10 @@ second</p>
<test1 bool-val='true'></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -366,10 +367,10 @@ second</p>
<test1 bool-val></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -383,10 +384,10 @@ second</p>
<test1 notbound></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -400,10 +401,10 @@ second</p>
<test1 bool-val='true' class='display:none'></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -417,10 +418,10 @@ second</p>
<test1 bool-val='true' class='display:none'></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -434,10 +435,10 @@ second</p>
<p bool-val='true'></p>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -454,10 +455,10 @@ second</p>
}<NotATagHelp @minimized:something />
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -471,10 +472,10 @@ second</p>
<Component1 bool-val=""true""></Component1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -488,10 +489,10 @@ second</p>
<Component1 @test:something='Function'></Component1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -505,10 +506,10 @@ second</p>
<test1 bool-val='true'></test1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -522,10 +523,10 @@ second</p>
<Component1 @test='Function'></Component1>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -538,10 +539,10 @@ second</p>
var documentText = @"@@text
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -555,10 +556,10 @@ second</p>
<p @test='Function'></p>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -572,10 +573,10 @@ second</p>
<p></p>
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -590,10 +591,10 @@ second</p>
var documentText = @"@code {}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -611,10 +612,10 @@ second</p>
}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 6, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 6, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -627,10 +628,10 @@ second</p>
var documentText = @"@using Microsoft.AspNetCore.Razor
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -643,10 +644,10 @@ second</p>
var documentText = @"@functions {}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -672,10 +673,10 @@ second</p>
}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 14, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 14, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -690,10 +691,10 @@ second</p>
}
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 3, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 3, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -707,10 +708,10 @@ second</p>
var documentText = @"@* A comment *@
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 1, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 1, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: true);
@ -725,10 +726,10 @@ second</p>
slf*@
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -742,10 +743,10 @@ slf*@
things *@
";
var razorRange = new VS.Range
var razorRange = new Range
{
Start = new VS.Position { Line = 0, Character = 0 },
End = new VS.Position { Line = 2, Character = 0 }
Start = new Position { Line = 0, Character = 0 },
End = new Position { Line = 2, Character = 0 }
};
var csharpTokens = await GetCSharpSemanticTokensResponseAsync(documentText, razorRange, isRazorFile: false);
@ -755,7 +756,7 @@ things *@
private async Task AssertSemanticTokensAsync(
string documentText,
bool isRazorFile,
VS.Range range,
Range range,
RazorSemanticTokensInfoService? service = null,
ProvideSemanticTokensResponse? csharpTokens = null,
int? documentVersion = 0)
@ -766,7 +767,7 @@ things *@
private async Task AssertSemanticTokensAsync(
string[] documentTexts,
bool[] isRazorArray,
VS.Range range,
Range range,
RazorSemanticTokensInfoService? service = null,
ProvideSemanticTokensResponse? csharpTokens = null,
int? documentVersion = 0)
@ -810,7 +811,7 @@ things *@
var languageServer = new Mock<ClientNotifierServiceBase>(MockBehavior.Strict);
languageServer
.Setup(l => l.SendRequestAsync(LanguageServerConstants.RazorProvideSemanticTokensRangeEndpoint, It.IsAny<VS.SemanticTokensParams>()))
.Setup(l => l.SendRequestAsync(LanguageServerConstants.RazorProvideSemanticTokensRangeEndpoint, It.IsAny<SemanticTokensParams>()))
.Returns(Task.FromResult(responseRouterReturns.Object));
var documentMappingService = new DefaultRazorDocumentMappingService(TestLoggerFactory.Instance);

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

@ -23,7 +23,6 @@ using Moq;
using Newtonsoft.Json.Linq;
using Xunit;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;
using VSModels = Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.VisualStudio.LanguageServerClient.Razor
{
@ -447,11 +446,11 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
var expectedcSharpResults = new VSSemanticTokensResponse();
var requestInvoker = new Mock<LSPRequestInvoker>(MockBehavior.Strict);
requestInvoker.Setup(invoker => invoker.ReinvokeRequestOnServerAsync<VSModels.SemanticTokensRangeParams, VSSemanticTokensResponse>(
requestInvoker.Setup(invoker => invoker.ReinvokeRequestOnServerAsync<SemanticTokensRangeParams, VSSemanticTokensResponse>(
TextBuffer,
Methods.TextDocumentSemanticTokensRangeName,
LanguageServerKind.CSharp.ToLanguageServerName(),
It.IsAny<VSModels.SemanticTokensRangeParams>(),
It.IsAny<SemanticTokensRangeParams>(),
It.IsAny<CancellationToken>()
)).Returns(Task.FromResult(new ReinvocationResponse<VSSemanticTokensResponse>("languageClient", expectedcSharpResults)));