Positions { get; }
@@ -17,6 +18,8 @@ internal readonly struct TestCode
public TestCode(string input, bool treatPositionIndicatorsAsCode = false)
{
+ OriginalInput = input;
+
if (treatPositionIndicatorsAsCode)
{
TestFileMarkupParser.GetSpans(input, treatPositionIndicatorsAsCode, out var text, out var nameToSpanMap);
diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentSpellCheckEndpointTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentSpellCheckEndpointTest.cs
new file mode 100644
index 00000000000..6711a4bdc2b
--- /dev/null
+++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentSpellCheckEndpointTest.cs
@@ -0,0 +1,100 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the MIT license. See License.txt in the project root for license information.
+
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Razor;
+using Microsoft.AspNetCore.Razor.Test.Common;
+using Microsoft.CodeAnalysis.Text;
+using Roslyn.Test.Utilities;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
+
+public class CohostDocumentSpellCheckEndpointTest(ITestOutputHelper testOutputHelper) : CohostEndpointTestBase(testOutputHelper)
+{
+ [Fact]
+ public async Task Handle()
+ {
+ var input = """
+ @page [|"this is csharp"|]
+
+ [|
+
+ Eat more chickin.
+
+ |]
+
+
+
+
+
+ @{ var [|x|] = [|"csharp"|];
+
+ @*[| Eat more chickin. |]*@
+
+
+
+ @code
+ {
+ void [|M|]()
+ {
+ [|// Eat more chickin|]
+ }
+ }
+ """;
+
+ await VerifySemanticTokensAsync(input);
+ }
+
+ private async Task VerifySemanticTokensAsync(TestCode input)
+ {
+ var document = CreateProjectAndRazorDocument(input.Text);
+ var sourceText = await document.GetTextAsync(DisposalToken);
+
+ var endpoint = new CohostDocumentSpellCheckEndpoint(RemoteServiceInvoker);
+
+ var span = new LinePositionSpan(new(0, 0), new(sourceText.Lines.Count, 0));
+
+ var result = await endpoint.GetTestAccessor().HandleRequestAsync(document, DisposalToken);
+
+ var ranges = result.First().Ranges.AssumeNotNull();
+
+ // To make for easier test failure analysis, we convert the ranges back to the test input, so we can show a diff
+ // rather than "Expected 23, got 53" and leave the developer to deal with what that means.
+ // As a bonus, this also ensures the ranges array has the right number of elements (ie, multiple of 3)
+ var absoluteRanges = new List<(int Start, int End)>();
+ var absoluteStart = 0;
+ for (var i = 0; i < ranges.Length; i += 3)
+ {
+ var kind = ranges[i];
+ var start = ranges[i + 1];
+ var length = ranges[i + 2];
+
+ absoluteStart += start;
+ absoluteRanges.Add((absoluteStart, absoluteStart + length));
+ absoluteStart += length;
+ }
+
+ // Make sure the response is sorted correctly, or the IDE will complain
+ Assert.True(absoluteRanges.SequenceEqual(absoluteRanges.OrderBy(r => r.Start)), "Results are not in order!");
+
+ absoluteRanges.Reverse();
+
+ var actual = input.Text;
+ foreach (var (start, end) in absoluteRanges)
+ {
+ actual = actual.Insert(end, "|]").Insert(start, "[|");
+ }
+
+ AssertEx.EqualOrDiff(input.OriginalInput, actual);
+ }
+}
diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs
index b39ca778abe..7a1e3d913f3 100644
--- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs
+++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostOnTypeFormattingEndpointTest.cs
@@ -12,7 +12,6 @@
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Razor.Settings;
-using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.Threading;
using Roslyn.Test.Utilities;
using Xunit;