Repository: dotnet/roslyn
File: src/Workspaces/Core/Portable/FindSymbols/ReferenceLocationExtensions.cs (C#)

Code before:
                foreach (var documentGroup in projectGroup)
                {
                    var document = documentGroup.Key;
                    var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
                    AddSymbols(semanticModel, documentGroup, result);
                }

                // Keep compilation alive so that GetSemanticModelAsync remains cheap
                GC.KeepAlive(compilation);
            }
        }

        return result;
    }

    private static void AddSymbols(
        SemanticModel semanticModel,
        IEnumerable<ReferenceLocation> references,
        Dictionary<ISymbol, List<Location>> result)
    {
        foreach (var reference in references)
        {
            // Filter out name-only references (e.g. nameof expressions, typeof expressions)
            // This fixes the most common Call Hierarchy false positives
            if (reference.SymbolUsageInfo.ValueUsageInfoOpt?.IsNameOnly() == true)
                continue;
            var containingSymbol = GetEnclosingMethodOrPropertyOrField(semanticModel, reference);
            if (containingSymbol != null)
            {
                if (!result.TryGetValue(containingSymbol, out var locations))
                {
                    locations = [];
                    result.Add(containingSymbol, locations);
                }

                locations.Add(reference.Location);
            }
        }
    }

    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;

Review comment (suggestion):
Prefer an empty line following if statements. This acts as a visual break in the code. This bit of code up here does this and now we are going to do something else down here.
```suggestion
                continue;

```

Code after:
                foreach (var documentGroup in projectGroup)
                {
                    var document = documentGroup.Key;
                    var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
                    AddSymbols(semanticModel, documentGroup, result);
                }

                // Keep compilation alive so that GetSemanticModelAsync remains cheap
                GC.KeepAlive(compilation);
            }
        }

        return result;
    }

    private static void AddSymbols(
        SemanticModel semanticModel,
        IEnumerable<ReferenceLocation> references,
        Dictionary<ISymbol, List<Location>> result)
    {
        foreach (var reference in references)
        {
            // Filter out name-only references (e.g. nameof expressions, typeof expressions)
            // This fixes the most common Call Hierarchy false positives
            if (reference.SymbolUsageInfo.ValueUsageInfoOpt?.IsNameOnly() == true)
                continue;

            var containingSymbol = GetEnclosingMethodOrPropertyOrField(semanticModel, reference);
            if (containingSymbol != null)
            {
                if (!result.TryGetValue(containingSymbol, out var locations))
                {
                    locations = [];
                    result.Add(containingSymbol, locations);
                }

                locations.Add(reference.Location);
            }
        }
    }

    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)
            {