protected override Task <ImmutableArray <Document> > DetermineDocumentsToSearchAsync(
            IMethodSymbol symbol,
            Project project,
            IImmutableSet <Document>?documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            return(FindDocumentsAsync(project, documents, async(d, c) =>
            {
                var index = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
                if (index.ContainsBaseConstructorInitializer)
                {
                    return true;
                }

                if (index.ProbablyContainsIdentifier(symbol.ContainingType.Name))
                {
                    if (index.ContainsThisConstructorInitializer)
                    {
                        return true;
                    }
                    else if (project.Language == LanguageNames.VisualBasic && index.ProbablyContainsIdentifier("New"))
                    {
                        // "New" can be explicitly accessed in xml doc comments to reference a constructor.
                        return true;
                    }
                }

                return false;
            }, cancellationToken));
        }
Example #2
0
        protected override Task <ImmutableArray <Document> > DetermineDocumentsToSearchAsync(
            IMethodSymbol symbol,
            Project project,
            IImmutableSet <Document> documents,
            FindReferencesSearchOptions options,
            CancellationToken cancellationToken)
        {
            return(FindDocumentsAsync(project, documents, async(d, c) =>
            {
                var index = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
                if (index.ContainsBaseConstructorInitializer)
                {
                    return true;
                }

                if (index.ProbablyContainsIdentifier(symbol.ContainingType.Name))
                {
                    if (index.ContainsThisConstructorInitializer)
                    {
                        return true;
                    }
                }

                return false;
            }, cancellationToken));
        }
Example #3
0
        public static async ValueTask <SyntaxTreeIndex> GetSyntaxTreeIndexAsync(this Document document, CancellationToken cancellationToken)
        {
            var result = await SyntaxTreeIndex.GetIndexAsync(document, loadOnly : false, cancellationToken).ConfigureAwait(false);

            Contract.ThrowIfNull(result);
            return(result);
        }
 private Task <ImmutableArray <Document> > FindDocumentWithElementAccessExpressionsAsync(
     Project project, IImmutableSet <Document> documents, CancellationToken cancellationToken)
 {
     return(FindDocumentsAsync(project, documents, async(d, c) =>
     {
         var info = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
         return info.ContainsElementAccessExpression;
     }, cancellationToken));
 }
Example #5
0
 protected Task <ImmutableArray <Document> > FindDocumentsAsync(
     Project project,
     IImmutableSet <Document> documents,
     PredefinedType predefinedType,
     CancellationToken cancellationToken)
 {
     return(FindDocumentsAsync(project, documents, async(d, c) =>
     {
         var info = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
         return info.ContainsPredefinedType(predefinedType);
     }, cancellationToken));
 }
Example #6
0
        /// <summary>
        /// Finds all the documents in the provided project that contain the requested string
        /// values
        /// </summary>
        protected Task <ImmutableArray <Document> > FindDocumentsAsync(Project project, IImmutableSet <Document> documents, CancellationToken cancellationToken, params string[] values)
        {
            return(FindDocumentsAsync(project, documents, async(d, c) =>
            {
                var info = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
                foreach (var value in values)
                {
                    if (!info.ProbablyContainsIdentifier(value))
                    {
                        return false;
                    }
                }

                return true;
            }, cancellationToken));
        }
Example #7
0
        protected Task <ImmutableArray <Document> > FindDocumentsAsync(
            Project project,
            IImmutableSet <Document> documents,
            PredefinedOperator op,
            CancellationToken cancellationToken)
        {
            if (op == PredefinedOperator.None)
            {
                return(SpecializedTasks.EmptyImmutableArray <Document>());
            }

            return(FindDocumentsAsync(project, documents, async(d, c) =>
            {
                var info = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
                return info.ContainsPredefinedOperator(op);
            }, cancellationToken));
        }
Example #8
0
            private async Task AddDocumentsWithPotentialConflicts(IEnumerable <Document> documents)
            {
                try
                {
                    foreach (var document in documents)
                    {
                        if (_documentsIdsToBeCheckedForConflict.Contains(document.Id))
                        {
                            continue;
                        }

                        var info = await SyntaxTreeIndex.GetIndexAsync(document, CancellationToken.None).ConfigureAwait(false);

                        if (info.ProbablyContainsEscapedIdentifier(_originalText))
                        {
                            _documentsIdsToBeCheckedForConflict.Add(document.Id);
                            continue;
                        }

                        if (info.ProbablyContainsIdentifier(_replacementText))
                        {
                            _documentsIdsToBeCheckedForConflict.Add(document.Id);
                            continue;
                        }

                        foreach (var replacementName in _possibleNameConflicts)
                        {
                            if (info.ProbablyContainsIdentifier(replacementName))
                            {
                                _documentsIdsToBeCheckedForConflict.Add(document.Id);
                                break;
                            }
                        }
                    }
                }
                catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
Example #9
0
 public static Task <SyntaxTreeIndex> GetSyntaxTreeIndexAsync(this Document document, bool loadOnly, CancellationToken cancellationToken)
 => SyntaxTreeIndex.GetIndexAsync(document, loadOnly, cancellationToken);
Example #10
0
 public static ValueTask <SyntaxTreeIndex> GetSyntaxTreeIndexAsync(this Document document, CancellationToken cancellationToken)
 => SyntaxTreeIndex.GetIndexAsync(document, loadOnly: false, cancellationToken);