-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expose Go To Impl and Spell Check to Razor #74978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be helpful to include try catch block in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for our purposes we're better off letting the exception bubble out of the ExternalAccess layer here, and if necessary then we can handle it in Razor. If we handled the exceptions here it would go through Roslyn's exception reporting and telemetry, which might make it harder to get in front of the right team. |
||
{ | ||
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(); | ||
} | ||
} |
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assuming you intentionally dropped
async
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it would be a compiler warning if I left it in place.
If an async method only has a single
await
at the end, it is usually better to remove it, and theasync
modifier, and just return theTask
directly. This avoids the creation of a state machine and so gives a slight perf bump. It does however change the call stack for exceptions that might be thrown so I wouldn't say its a hard and fast rule.