-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
583 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../Microsoft.AspNetCore.Razor.LanguageServer/SpellCheck/LspCSharpSpellCheckRangeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// 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.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Razor.Language; | ||
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; | ||
using Microsoft.AspNetCore.Razor.PooledObjects; | ||
using Microsoft.CodeAnalysis.Razor.ProjectSystem; | ||
using Microsoft.CodeAnalysis.Razor.Protocol; | ||
using Microsoft.CodeAnalysis.Razor.SpellCheck; | ||
using Microsoft.CodeAnalysis.Razor.Workspaces; | ||
using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
|
||
namespace Microsoft.AspNetCore.Razor.LanguageServer.SpellCheck; | ||
|
||
internal sealed class LspCSharpSpellCheckRangeProvider( | ||
LanguageServerFeatureOptions languageServerFeatureOptions, | ||
IClientConnection clientConnection) : ICSharpSpellCheckRangeProvider | ||
{ | ||
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; | ||
private readonly IClientConnection _clientConnection = clientConnection; | ||
|
||
public async Task<ImmutableArray<SpellCheckRange>> GetCSharpSpellCheckRangesAsync(DocumentContext documentContext, CancellationToken cancellationToken) | ||
{ | ||
if (!_languageServerFeatureOptions.SingleServerSupport) | ||
{ | ||
return []; | ||
} | ||
|
||
var delegatedParams = new DelegatedSpellCheckParams(documentContext.GetTextDocumentIdentifierAndVersion()); | ||
var delegatedResponse = await _clientConnection.SendRequestAsync<DelegatedSpellCheckParams, VSInternalSpellCheckableRangeReport[]?>( | ||
CustomMessageNames.RazorSpellCheckEndpoint, | ||
delegatedParams, | ||
cancellationToken).ConfigureAwait(false); | ||
|
||
if (delegatedResponse is not [_, ..] response) | ||
{ | ||
return []; | ||
} | ||
|
||
// Most common case is we'll get one report back from Roslyn, so we'll use that as the initial capacity. | ||
var initialCapacity = response[0].Ranges?.Length ?? 4; | ||
|
||
using var ranges = new PooledArrayBuilder<SpellCheckRange>(initialCapacity); | ||
foreach (var report in delegatedResponse) | ||
{ | ||
if (report.Ranges is not { } csharpRanges) | ||
{ | ||
continue; | ||
} | ||
|
||
// Since we get C# tokens that have relative starts, we need to convert them back to absolute indexes | ||
// so we can sort them with the Razor tokens later | ||
var absoluteCSharpStartIndex = 0; | ||
for (var i = 0; i < csharpRanges.Length; i += 3) | ||
{ | ||
var kind = csharpRanges[i]; | ||
var start = csharpRanges[i + 1]; | ||
var length = csharpRanges[i + 2]; | ||
|
||
absoluteCSharpStartIndex += start; | ||
|
||
ranges.Add(new(kind, absoluteCSharpStartIndex, length)); | ||
|
||
absoluteCSharpStartIndex += length; | ||
} | ||
} | ||
|
||
return ranges.DrainToImmutable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/IRemoteSpellCheckService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.ExternalAccess.Razor; | ||
|
||
namespace Microsoft.CodeAnalysis.Razor.Remote; | ||
|
||
internal interface IRemoteSpellCheckService | ||
{ | ||
ValueTask<int[]> GetSpellCheckRangeTriplesAsync( | ||
RazorPinnedSolutionInfoWrapper solutionInfo, | ||
DocumentId razorDocumentId, | ||
CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
.../src/Microsoft.CodeAnalysis.Razor.Workspaces/SpellCheck/ICSharpSpellCheckRangeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Razor.ProjectSystem; | ||
|
||
namespace Microsoft.CodeAnalysis.Razor.SpellCheck; | ||
|
||
internal interface ICSharpSpellCheckRangeProvider | ||
{ | ||
Task<ImmutableArray<SpellCheckRange>> GetCSharpSpellCheckRangesAsync(DocumentContext documentContext, CancellationToken cancellationToken); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SpellCheck/ISpellCheckService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Razor.ProjectSystem; | ||
|
||
namespace Microsoft.CodeAnalysis.Razor.SpellCheck; | ||
|
||
internal interface ISpellCheckService | ||
{ | ||
Task<int[]> GetSpellCheckRangeTriplesAsync(DocumentContext documentContext, CancellationToken cancellationToken); | ||
} |
Oops, something went wrong.