public Task OnReferenceFoundAsync(
     SymbolAndProjectId definition, ReferenceLocation reference)
 {
     return _service.Rpc.InvokeAsync(nameof(OnReferenceFoundAsync),
         SerializableSymbolAndProjectId.Dehydrate(definition),
         SerializableReferenceLocation.Dehydrate(reference));
 }
        private static ISymbol GetEnclosingMethodOrPropertyOrField(
            SemanticModel semanticModel,
            ReferenceLocation reference)
        {
            var enclosingSymbol = semanticModel.GetEnclosingSymbol(reference.Location.SourceSpan.Start);

            for (var current = enclosingSymbol; current != null; current = current.ContainingSymbol)
            {
                if (current.Kind == SymbolKind.Field)
                {
                    return current;
                }

                if (current.Kind == SymbolKind.Property)
                {
                    return current;
                }

                if (current.Kind == SymbolKind.Method)
                {
                    var method = (IMethodSymbol)current;
                    if (method.IsAccessor())
                    {
                        return method.AssociatedSymbol;
                    }

                    if (method.MethodKind != MethodKind.AnonymousFunction)
                    {
                        return method;
                    }
                }
            }

            return null;
        }
        public Task OnReferenceFoundAsync(SymbolAndProjectId definition, ReferenceLocation location)
        {
            lock (_gate)
            {
                _symbolToLocations[definition].Add(location);
            }

            return _underlyingProgress.OnReferenceFoundAsync(definition, location);
        }
            public void OnReferenceFound(ISymbol definition, ReferenceLocation location)
            {
                var referenceItem = location.TryCreateSourceReferenceItem(
                    GetDefinitionItem(definition));

                if (referenceItem != null)
                {
                    _context.OnReferenceFound(referenceItem);
                }
            }
            public async Task OnReferenceFoundAsync(SymbolAndProjectId definition, ReferenceLocation location)
            {
                // Ignore duplicate locations.  We don't want to clutter the UI with them.
                if (location.IsDuplicateReferenceLocation)
                {
                    return;
                }

                var referenceItem = location.TryCreateSourceReferenceItem(
                    GetDefinitionItem(definition), includeHiddenLocations: false);

                if (referenceItem != null)
                {
                    await _context.OnReferenceFoundAsync(referenceItem).ConfigureAwait(false);
                }
            }
Exemplo n.º 6
0
 private void HandleLocation(ISymbol symbol, ReferenceLocation location)
 {
     _foundReferences.GetOrAdd(symbol, s_createSymbolLocations).Add(location);
     _progress.OnReferenceFound(symbol, location);
 }
Exemplo n.º 7
0
 private Task HandleLocationAsync(SymbolAndProjectId symbolAndProjectId, ReferenceLocation location)
 {
     return _progress.OnReferenceFoundAsync(symbolAndProjectId, location);
 }
            internal static async Task<IEnumerable<RenameLocation>> GetRenamableReferenceLocationsAsync(ISymbol referencedSymbol, ISymbol originalSymbol, ReferenceLocation location, Solution solution, CancellationToken cancellationToken)
            {
                var shouldIncludeSymbol = await ShouldIncludeSymbolAsync(referencedSymbol, originalSymbol, solution, true, cancellationToken).ConfigureAwait(false);
                if (!shouldIncludeSymbol)
                {
                    return SpecializedCollections.EmptyEnumerable<RenameLocation>();
                }

                // Implicit references are things like a foreach referencing GetEnumerator. We don't
                // want to consider those as part of the set
                if (location.IsImplicit)
                {
                    return SpecializedCollections.EmptyEnumerable<RenameLocation>();
                }

                var results = new List<RenameLocation>();

                // If we were originally naming an alias, then we'll only use the location if was
                // also bound through the alias
                if (originalSymbol.Kind == SymbolKind.Alias)
                {
                    if (originalSymbol.Equals(location.Alias))
                    {
                        results.Add(new RenameLocation(location, location.Document.Id));

                        // We also need to add the location of the alias
                        // itself
                        var aliasLocation = location.Alias.Locations.Single();
                        results.Add(new RenameLocation(aliasLocation, solution.GetDocument(aliasLocation.SourceTree).Id));
                    }
                }
                else
                {
                    // If we bound through an alias, we'll only rename if the alias's name matches
                    // the name of symbol it points to. We do this because it's common to see things
                    // like "using Foo = System.Foo" where people want to import a single type
                    // rather than a whole namespace of stuff.
                    if (location.Alias != null)
                    {
                        if (location.Alias.Name == referencedSymbol.Name)
                        {
                            results.Add(new RenameLocation(location.Location, location.Document.Id,
                                isCandidateLocation: location.IsCandidateLocation, isRenamableAliasUsage: true, isWrittenTo: location.IsWrittenTo));

                            // We also need to add the location of the alias itself
                            var aliasLocation = location.Alias.Locations.Single();
                            results.Add(new RenameLocation(aliasLocation, solution.GetDocument(aliasLocation.SourceTree).Id));
                        }
                    }
                    else
                    {
                        // The simple case, so just the single location and we're done
                        results.Add(new RenameLocation(
                            location.Location,
                            location.Document.Id,
                            isWrittenTo: location.IsWrittenTo,
                            isCandidateLocation: location.IsCandidateLocation,
                            isMethodGroupReference: location.IsCandidateLocation && location.CandidateReason == CandidateReason.MemberGroup,
                            isRenamableAccessor: await IsPropertyAccessorOrAnOverride(referencedSymbol, solution, cancellationToken).ConfigureAwait(false)));
                    }
                }

                return results;
            }
Exemplo n.º 9
0
 public static SerializableReferenceLocation Dehydrate(
     ReferenceLocation referenceLocation)
 {
     return new SerializableReferenceLocation
     {
         Document = SerializableDocumentId.Dehydrate(referenceLocation.Document),
         Alias = SerializableSymbolAndProjectId.Dehydrate(referenceLocation.Alias, referenceLocation.Document),
         Location = SerializableTextSpan.Dehydrate(referenceLocation.Location.SourceSpan),
         IsImplicit = referenceLocation.IsImplicit,
         IsWrittenTo = referenceLocation.IsWrittenTo,
         CandidateReason = referenceLocation.CandidateReason
     };
 }
        private void RemoveAwaitFromCallerIfPresent(
            SyntaxEditor editor, ISyntaxFactsService syntaxFacts, 
            SyntaxNode root, ReferenceLocation referenceLocation,
            CancellationToken cancellationToken)
        {
            if (referenceLocation.IsImplicit)
            {
                return;
            }

            var location = referenceLocation.Location;
            var token = location.FindToken(cancellationToken);

            var nameNode = token.Parent;
            if (nameNode == null)
            {
                return;
            }

            // Look for the following forms:
            //  await M(...)
            //  await <expr>.M(...)
            //  await M(...).ConfigureAwait(...)
            //  await <expr>.M(...).ConfigureAwait(...)

            var expressionNode = nameNode;
            if (syntaxFacts.IsNameOfMemberAccessExpression(nameNode))
            {
                expressionNode = nameNode.Parent;
            }

            if (!syntaxFacts.IsExpressionOfInvocationExpression(expressionNode))
            {
                return;
            }

            // We now either have M(...) or <expr>.M(...)

            var invocationExpression = expressionNode.Parent;
            Debug.Assert(syntaxFacts.IsInvocationExpression(invocationExpression));

            if (syntaxFacts.IsExpressionOfAwaitExpression(invocationExpression))
            {
                // Handle the case where we're directly awaited.  
                var awaitExpression = invocationExpression.Parent;
                editor.ReplaceNode(awaitExpression, (currentAwaitExpression, generator) =>
                    syntaxFacts.GetExpressionOfAwaitExpression(currentAwaitExpression)
                               .WithTriviaFrom(currentAwaitExpression));
            }
            else if (syntaxFacts.IsExpressionOfMemberAccessExpression(invocationExpression))
            {
                // Check for the .ConfigureAwait case.
                var parentMemberAccessExpression = invocationExpression.Parent;
                var parentMemberAccessExpressionNameNode = syntaxFacts.GetNameOfMemberAccessExpression(
                    parentMemberAccessExpression);

                var parentMemberAccessExpressionName = syntaxFacts.GetIdentifierOfSimpleName(parentMemberAccessExpressionNameNode).ValueText;
                if (parentMemberAccessExpressionName == nameof(Task.ConfigureAwait))
                {
                    var parentExpression = parentMemberAccessExpression.Parent;
                    if (syntaxFacts.IsExpressionOfAwaitExpression(parentExpression))
                    {
                        var awaitExpression = parentExpression.Parent;
                        editor.ReplaceNode(awaitExpression, (currentAwaitExpression, generator) =>
                        {
                            var currentConfigureAwaitInvocation = syntaxFacts.GetExpressionOfAwaitExpression(currentAwaitExpression);
                            var currentMemberAccess = syntaxFacts.GetExpressionOfInvocationExpression(currentConfigureAwaitInvocation);
                            var currentInvocationExpression = syntaxFacts.GetExpressionOfMemberAccessExpression(currentMemberAccess);
                            return currentInvocationExpression.WithTriviaFrom(currentAwaitExpression);
                        });
                    }
                }
            }
        }
Exemplo n.º 11
0
        private static async Task<IAliasSymbol> GetAliasSymbolAsync(
            Document document,
            ReferenceLocation location,
            CancellationToken cancellationToken)
        {
            if (location.Location.IsInSource)
            {
                var tree = location.Location.SourceTree;
                var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
                var token = root.FindToken(location.Location.SourceSpan.Start);
                var node = token.Parent;

                var syntaxFacts = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
                if (syntaxFacts.IsRightSideOfQualifiedName(node))
                {
                    node = node.Parent;
                }

                if (syntaxFacts.IsUsingDirectiveName(node))
                {
                    var directive = node.Parent;
                    var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
                    var aliasSymbol = semanticModel.GetDeclaredSymbol(directive, cancellationToken) as IAliasSymbol;
                    if (aliasSymbol != null)
                    {
                        return aliasSymbol;
                    }
                }
            }

            return null;
        }
Exemplo n.º 12
0
 public void OnReferenceFound(ISymbol symbol, ReferenceLocation location)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Exclude the following kind of symbols:
 ///  1. Implicitly declared symbols (such as implicit fields backing properties)
 ///  2. Symbols that can't be referenced by name (such as property getters and setters).
 ///  3. Metadata only symbols, i.e. symbols with no location in source.
 /// </summary>
 private static bool FilterReference(ISymbol queriedSymbol, ISymbol definition, ReferenceLocation reference)
 {
     var isImplicitlyDeclared = definition.IsImplicitlyDeclared || definition.IsAccessor();
     // FindRefs treats a constructor invocation as a reference to the constructor symbol and to the named type symbol that defines it.
     // While we need to count the cascaded symbol definition from the named type to its constructor, we should not double count the
     // reference location for the invocation while computing references count for the named type symbol. 
     var isImplicitReference = queriedSymbol.Kind == SymbolKind.NamedType &&
                               (definition as IMethodSymbol)?.MethodKind == MethodKind.Constructor;
     return isImplicitlyDeclared ||
            isImplicitReference ||
            (!definition.Locations.Any(loc => loc.IsInSource) && !reference.Location.IsInSource);
 }
Exemplo n.º 14
0
        public void OnReferenceFound(ISymbol symbol, ReferenceLocation location)
        {
            if (FilterReference(_queriedSymbol, symbol, location))
            {
                return;
            }

            _locations.Add(location.Location);

            if (SearchCapReached)
            {
                _aggregateCancellationTokenSource.Cancel();
            }
        }
 public Task OnReferenceFoundAsync(SymbolAndProjectId symbolAndProjectId, ReferenceLocation location)
 {
     _progress.OnReferenceFound(symbolAndProjectId.Symbol, location);
     return SpecializedTasks.EmptyTask;
 }
 public Task OnReferenceFoundAsync(SymbolAndProjectId symbol, ReferenceLocation location) => SpecializedTasks.EmptyTask;