diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionListProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionListProvider.cs index 35ffb1fba6a..900b1fcc39b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionListProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionListProvider.cs @@ -39,7 +39,7 @@ public DelegatedCompletionListProvider( IClientConnection clientConnection, CompletionListCache completionListCache) { - _responseRewriters = responseRewriters.OrderBy(rewriter => rewriter.Order).ToImmutableArray(); + _responseRewriters = responseRewriters.OrderByAsArray(static x => x.Order); _documentMappingService = documentMappingService; _clientConnection = clientConnection; _completionListCache = completionListCache; @@ -57,7 +57,9 @@ public DelegatedCompletionListProvider( Guid correlationId, CancellationToken cancellationToken) { - var positionInfo = await _documentMappingService.GetPositionInfoAsync(documentContext, absoluteIndex, cancellationToken).ConfigureAwait(false); + var positionInfo = await _documentMappingService + .GetPositionInfoAsync(documentContext, absoluteIndex, cancellationToken) + .ConfigureAwait(false); if (positionInfo.LanguageKind == RazorLanguageKind.Razor) { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionListProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionListProviderTest.cs index faf9392f1f1..20845191b36 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionListProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/DelegatedCompletionListProviderTest.cs @@ -9,12 +9,15 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; +using Moq; using Xunit; using Xunit.Abstractions; @@ -284,15 +287,16 @@ public async Task ShouldIncludeSnippets(string input, bool shouldIncludeSnippets var codeDocument = CreateCodeDocument(code); var documentContext = TestDocumentContext.From("C:/path/to/file.cshtml", codeDocument, hostDocumentVersion: 1337); - var documentMappingService = new TestDocumentMappingService() - { - LanguageKind = RazorLanguageKind.Html, - GeneratedPosition = new LinePosition(0, cursorPosition) - }; + var generatedPosition = new LinePosition(0, cursorPosition); + + var documentMappingServiceMock = new StrictMock(); + documentMappingServiceMock + .Setup(x => x.TryMapToGeneratedDocumentPosition(It.IsAny(), It.IsAny(), out generatedPosition, out It.Ref.IsAny)) + .Returns(true); var completionProvider = new DelegatedCompletionListProvider( - Array.Empty(), - documentMappingService, + responseRewriters: [], + documentMappingServiceMock.Object, clientConnection, new CompletionListCache()); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/TestDocumentMappingService.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/TestDocumentMappingService.cs deleted file mode 100644 index 2dd5836ce16..00000000000 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/TestDocumentMappingService.cs +++ /dev/null @@ -1,66 +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; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.Razor.DocumentMapping; -using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; - -internal class TestDocumentMappingService : IDocumentMappingService -{ - public RazorLanguageKind LanguageKind { get; set; } - public LinePosition? GeneratedPosition { get; set; } - public int GeneratedIndex { get; set; } - - public IEnumerable GetHostDocumentEdits(IRazorGeneratedDocument generatedDocument, ImmutableArray generatedDocumentEdits) - => []; - - public RazorLanguageKind GetLanguageKind(RazorCodeDocument codeDocument, int hostDocumentIndex, bool rightAssociative) - => LanguageKind; - - public Task<(Uri MappedDocumentUri, LinePositionSpan MappedRange)> MapToHostDocumentUriAndRangeAsync(Uri generatedDocumentUri, LinePositionSpan generatedDocumentRange, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public bool TryMapToGeneratedDocumentOrNextCSharpPosition(IRazorGeneratedDocument generatedDocument, int hostDocumentIndex, out LinePosition generatedPosition, out int generatedIndex) - { - throw new NotImplementedException(); - } - - public bool TryMapToGeneratedDocumentPosition(IRazorGeneratedDocument generatedDocument, int hostDocumentIndex, out LinePosition generatedPosition, out int generatedIndex) - { - if (GeneratedPosition is null) - { - generatedPosition = default; - generatedIndex = default; - return false; - } - - generatedPosition = GeneratedPosition.Value; - generatedIndex = GeneratedIndex; - return true; - } - - public bool TryMapToGeneratedDocumentRange(IRazorGeneratedDocument generatedDocument, LinePositionSpan hostDocumentRange, out LinePositionSpan generatedDocumentRange) - { - throw new NotImplementedException(); - } - - public bool TryMapToHostDocumentPosition(IRazorGeneratedDocument generatedDocument, int generatedDocumentIndex, out LinePosition hostDocumentPosition, out int hostDocumentIndex) - { - throw new NotImplementedException(); - } - - public bool TryMapToHostDocumentRange(IRazorGeneratedDocument generatedDocument, LinePositionSpan generatedDocumentRange, MappingBehavior mappingBehavior, out LinePositionSpan hostDocumentRange) - { - throw new NotImplementedException(); - } -}