示例#1
0
        public Task <(IList <SerializableImportCompletionItem>, StatisticCounter)> GetUnimportedExtensionMethodsAsync(
            DocumentId documentId,
            int position,
            string receiverTypeSymbolKeyData,
            string[] namespaceInScope,
            bool forceIndexCreation,
            CancellationToken cancellationToken)
        {
            return(RunServiceAsync(async() =>
            {
                using (UserOperationBooster.Boost())
                {
                    var solution = await GetSolutionAsync(cancellationToken).ConfigureAwait(false);
                    var document = solution.GetDocument(documentId) !;
                    var compilation = (await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false));
                    var symbol = SymbolKey.ResolveString(receiverTypeSymbolKeyData, compilation, cancellationToken: cancellationToken).GetAnySymbol();

                    if (symbol is ITypeSymbol receiverTypeSymbol)
                    {
                        var syntaxFacts = document.GetRequiredLanguageService <ISyntaxFactsService>();
                        var namespaceInScopeSet = new HashSet <string>(namespaceInScope, syntaxFacts.StringComparer);

                        var(items, counter) = await ExtensionMethodImportCompletionHelper.GetUnimportedExtensionMethodsInCurrentProcessAsync(
                            document, position, receiverTypeSymbol, namespaceInScopeSet, forceIndexCreation, cancellationToken).ConfigureAwait(false);
                        return ((IList <SerializableImportCompletionItem>)items, counter);
                    }

                    return (Array.Empty <SerializableImportCompletionItem>(), new StatisticCounter());
                }
            }, cancellationToken));
        }
        protected override async Task InitializeServiceForOpenedDocumentAsync(Document document)
        {
            // Only pre-populate cache if import completion is enabled
            if (GlobalOptions.GetOption(CompletionOptionsStorage.ShowItemsFromUnimportedNamespaces, LanguageNames.CSharp) != true)
            {
                return;
            }

            var service = document.GetRequiredLanguageService <ITypeImportCompletionService>();

            service.QueueCacheWarmUpTask(document.Project);
            await ExtensionMethodImportCompletionHelper.WarmUpCacheAsync(document.Project, CancellationToken.None).ConfigureAwait(false);
        }