<commit_before>﻿// 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.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.SignatureHelp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.SignatureHelp;
using Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api;

namespace Microsoft.CodeAnalysis.ExternalAccess.Pythia
{
    /// <summary>
    /// Ensure this is ordered before the regular invocation signature help provider.
    /// We must replace the entire list of results, including both Pythia and non-Pythia recommendations.
    /// </summary>
    [ExportSignatureHelpProvider("PythiaSignatureHelpProvider", LanguageNames.CSharp), Shared]
    [ExtensionOrder(Before = "InvocationExpressionSignatureHelpProvider")]
    internal sealed class PythiaSignatureHelpProvider : InvocationExpressionSignatureHelpProviderBase
    {
        private readonly IPythiaSignatureHelpProviderImplementation _implementation;

        [ImportingConstructor]
        public PythiaSignatureHelpProvider(IPythiaSignatureHelpProviderImplementation implementation)
        {
            _implementation = implementation;
        }

        internal async override Task<(ImmutableArray<SignatureHelpItem> items, int? selectedItemIndex)> GetMethodGroupItemsAndSelectionAsync(
            ImmutableArray<IMethodSymbol> accessibleMethods,
            Document document,
            InvocationExpressionSyntax invocationExpression,
            SemanticModel semanticModel,
            SymbolInfo currentSymbol,
            CancellationToken cancellationToken)
        {
            var (items, selectedItemIndex) = await _implementation.GetMethodGroupItemsAndSelectionAsync(accessibleMethods, document, invocationExpression, semanticModel, currentSymbol, cancellationToken).ConfigureAwait(false);
            return (items.SelectAsArray(item => item.UnderlyingObject), selectedItemIndex);
        }
    }
}
<commit_msg>Load Pythia SignatureHelpProvider lazily (#42144)<commit_after>﻿// 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.

#nullable enable

using System.Collections.Immutable;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.SignatureHelp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.SignatureHelp;
using Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api;
using System;

namespace Microsoft.CodeAnalysis.ExternalAccess.Pythia
{
    /// <summary>
    /// Ensure this is ordered before the regular invocation signature help provider.
    /// We must replace the entire list of results, including both Pythia and non-Pythia recommendations.
    /// </summary>
    [ExportSignatureHelpProvider("PythiaSignatureHelpProvider", LanguageNames.CSharp), Shared]
    [ExtensionOrder(Before = "InvocationExpressionSignatureHelpProvider")]
    internal sealed class PythiaSignatureHelpProvider : InvocationExpressionSignatureHelpProviderBase
    {
        private readonly Lazy<IPythiaSignatureHelpProviderImplementation> _lazyImplementation;

        [ImportingConstructor]
        public PythiaSignatureHelpProvider(Lazy<IPythiaSignatureHelpProviderImplementation> implementation)
        {
            _lazyImplementation = implementation;
        }

        internal async override Task<(ImmutableArray<SignatureHelpItem> items, int? selectedItemIndex)> GetMethodGroupItemsAndSelectionAsync(
            ImmutableArray<IMethodSymbol> accessibleMethods,
            Document document,
            InvocationExpressionSyntax invocationExpression,
            SemanticModel semanticModel,
            SymbolInfo currentSymbol,
            CancellationToken cancellationToken)
        {
            var (items, selectedItemIndex) = await _lazyImplementation.Value.GetMethodGroupItemsAndSelectionAsync(accessibleMethods, document, invocationExpression, semanticModel, currentSymbol, cancellationToken).ConfigureAwait(false);
            return (items.SelectAsArray(item => item.UnderlyingObject), selectedItemIndex);
        }
    }
}

{'fraction_non_alphanumeric': 0.06552191595119747, 'fraction_numerical': 0.0011296882060551287, 'mean_word_length': 4.23905325443787, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7154119', 'n_tokens_mistral': 1038, 'n_tokens_neox': 996, 'n_words': 274}