From b69b08cbe384704540f6040493839cd301167988 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Fri, 6 Sep 2024 11:51:32 +1000 Subject: [PATCH] PR Feedback --- .../Extensions/IServiceCollectionExtensions.cs | 1 - .../SpellCheck/LspCSharpSpellCheckRangeProvider.cs | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index 91ecc7a562..ce813c77da 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -165,7 +165,6 @@ internal static class IServiceCollectionExtensions services.AddHandler(); } - services.AddHandlerWithCapabilities(); services.AddHandler(); services.AddHandler(); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SpellCheck/LspCSharpSpellCheckRangeProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SpellCheck/LspCSharpSpellCheckRangeProvider.cs index 97cf038f3c..f0181c75da 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SpellCheck/LspCSharpSpellCheckRangeProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SpellCheck/LspCSharpSpellCheckRangeProvider.cs @@ -39,12 +39,15 @@ internal sealed class LspCSharpSpellCheckRangeProvider( delegatedParams, cancellationToken).ConfigureAwait(false); - if (delegatedResponse is null) + if (delegatedResponse is not [_, ..] response) { return []; } - using var ranges = new PooledArrayBuilder(); + // 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(initialCapacity); foreach (var report in delegatedResponse) { if (report.Ranges is not { } csharpRanges) @@ -69,6 +72,6 @@ internal sealed class LspCSharpSpellCheckRangeProvider( } } - return ranges.ToImmutable(); + return ranges.DrainToImmutable(); } }