-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74978 from davidwengier/CohostImplemenationAndSpe…
…llCheck Expose Go To Impl and Spell Check to Razor
- Loading branch information
Showing
5 changed files
with
87 additions
and
13 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
39 changes: 39 additions & 0 deletions
39
src/Tools/ExternalAccess/Razor/Cohost/Handlers/DocumentSpellCheck.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,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.LanguageServer; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Microsoft.CodeAnalysis.SpellCheck; | ||
using Roslyn.LanguageServer.Protocol; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers; | ||
|
||
internal static class SpellCheck | ||
{ | ||
public readonly record struct SpellCheckSpan(int StartIndex, int Length, VSInternalSpellCheckableRangeKind Kind); | ||
|
||
public static async Task<ImmutableArray<SpellCheckSpan>> GetSpellCheckSpansAsync(Document document, CancellationToken cancellationToken) | ||
{ | ||
var service = document.GetLanguageService<ISpellCheckSpanService>(); | ||
if (service is null) | ||
{ | ||
return []; | ||
} | ||
|
||
var spans = await service.GetSpansAsync(document, cancellationToken).ConfigureAwait(false); | ||
|
||
using var _ = ArrayBuilder<SpellCheckSpan>.GetInstance(spans.Length, out var razorSpans); | ||
foreach (var span in spans) | ||
{ | ||
var kind = ProtocolConversions.SpellCheckSpanKindToSpellCheckableRangeKind(span.Kind); | ||
razorSpans.Add(new SpellCheckSpan(span.TextSpan.Start, span.TextSpan.Length, kind)); | ||
} | ||
|
||
return razorSpans.ToImmutable(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Tools/ExternalAccess/Razor/Cohost/Handlers/GoToImplementation.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,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.LanguageServer.Handler; | ||
using Microsoft.CodeAnalysis.Classification; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers; | ||
|
||
using Location = Roslyn.LanguageServer.Protocol.Location; | ||
|
||
internal static class GoToImplementation | ||
{ | ||
public static Task<Location[]> FindImplementationsAsync(Document document, LinePosition linePosition, bool supportsVisualStudioExtensions, CancellationToken cancellationToken) | ||
{ | ||
var globalOptions = document.Project.Solution.Services.ExportProvider.GetService<IGlobalOptionService>(); | ||
var classificationOptions = globalOptions.GetClassificationOptionsProvider(); | ||
|
||
return FindImplementationsHandler.FindImplementationsAsync(document, linePosition, classificationOptions, supportsVisualStudioExtensions, cancellationToken); | ||
} | ||
} |