Migrate razor/formatDoc/Range requests to new delegation APIs.

- Updated the tests to reflect the new dependency on document snapshots and their virtual documents.

Part of #5017
This commit is contained in:
N. Taylor Mullen 2021-10-18 16:47:00 -07:00
Родитель 9161a0d89e
Коммит 05febb544c
2 изменённых файлов: 9 добавлений и 6 удалений

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

@ -211,13 +211,15 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
Options = request.Options
};
var textBuffer = htmlDocument.Snapshot.TextBuffer;
var edits = await _requestInvoker.ReinvokeRequestOnServerAsync<DocumentFormattingParams, TextEdit[]>(
textBuffer,
Methods.TextDocumentFormattingName,
languageServerName,
formattingParams,
cancellationToken).ConfigureAwait(false);
response.Edits = edits.Result ?? Array.Empty<TextEdit>();
response.Edits = edits?.Response ?? Array.Empty<TextEdit>();
return response;
}
@ -260,13 +262,15 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
Options = request.Options
};
var textBuffer = csharpDocument.Snapshot.TextBuffer;
var edits = await _requestInvoker.ReinvokeRequestOnServerAsync<DocumentRangeFormattingParams, TextEdit[]>(
textBuffer,
Methods.TextDocumentRangeFormattingName,
languageServerName,
formattingParams,
cancellationToken).ConfigureAwait(false);
response.Edits = edits.Result ?? Array.Empty<TextEdit>();
response.Edits = edits?.Response ?? Array.Empty<TextEdit>();
return response;
}

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

@ -8,7 +8,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic.Models;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp;
@ -34,7 +33,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
private ITextBuffer TextBuffer { get; }
private JoinableTaskContext JoinableTaskContext { get; }
private readonly ILanguageClient _languageClient = Mock.Of<ILanguageClient>(MockBehavior.Strict);
[Fact]
public void UpdateCSharpBuffer_CannotLookupDocument_NoopsGracefully()
@ -153,7 +151,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
// Arrange
var filePath = "c:/Some/path/to/file.razor";
var uri = new Uri(filePath);
var virtualDocument = new CSharpVirtualDocumentSnapshot(new Uri($"{filePath}.g.cs"), Mock.Of<ITextSnapshot>(MockBehavior.Strict), 1);
var virtualDocument = new CSharpVirtualDocumentSnapshot(new Uri($"{filePath}.g.cs"), TextBuffer.CurrentSnapshot, 1);
LSPDocumentSnapshot document = new TestLSPDocumentSnapshot(uri, 1, new[] { virtualDocument });
var documentManager = new Mock<TrackingLSPDocumentManager>(MockBehavior.Strict);
documentManager.Setup(manager => manager.TryGetDocument(It.IsAny<Uri>(), out document))
@ -167,11 +165,12 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
var requestInvoker = new Mock<LSPRequestInvoker>(MockBehavior.Strict);
requestInvoker
.Setup(r => r.ReinvokeRequestOnServerAsync<DocumentRangeFormattingParams, TextEdit[]>(
TextBuffer,
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DocumentRangeFormattingParams>(),
It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(new ReinvokeResponse<TextEdit[]>(_languageClient, new[] { expectedEdit })));
.Returns(Task.FromResult(new ReinvocationResponse<TextEdit[]>("languageClient", new[] { expectedEdit })));
var uIContextManager = new Mock<RazorUIContextManager>(MockBehavior.Strict);
var disposable = new Mock<IDisposable>(MockBehavior.Strict);