Repository: dotnet/roslyn
File: src/VisualStudio/Core/Impl/SolutionExplorer/SymbolTree/RootSymbolTreeItemSourceProvider.cs (C#)

Code before:
        // Update all the affected documents in parallel.
        await Parallel.ForEachAsync(
            sources,
            cancellationToken,
            async (source, cancellationToken) =>
            {
                await source.UpdateIfEverBeenAskedToComputeAsync(cancellationToken)
                    .ReportNonFatalErrorUnlessCancelledAsync(cancellationToken)
                    .ConfigureAwait(false);
            }).ConfigureAwait(false);
    }

    protected override IAttachedCollectionSource? CreateCollectionSource(IVsHierarchyItem item, string relationshipName)
    {
        if (item == null ||
            item.IsDisposed ||
            item.HierarchyIdentity == null ||
            item.HierarchyIdentity.NestedHierarchy == null ||
            relationshipName != KnownRelationships.Contains)
        {
            return null;
        }

        // Important: currentFilePath is mutable state captured *AND UPDATED* in the local function  
        // OnItemPropertyChanged below.  It allows us to know the file path of the item *prior* to
        // it being changed *when* we hear the update about it having changed (since hte event doesn't
        // contain the old value).  
        if (item.CanonicalName is not string currentFilePath)
            return null;

        if (item.HierarchyIdentity.NestedHierarchy.GetGuidProperty(
                item.HierarchyIdentity.ItemID,
                (int)__VSHPROPID.VSHPROPID_TypeGuid,
                out var guid) != VSConstants.S_OK)
        {
            return null;
        }

        // We only support this for real files that we'll then have roslyn Documents for.  All the other
        // things in a project (like folders, nested projects, etc) are not supported.
        if (guid != VSConstants.ItemTypeGuid.PhysicalFile_guid)
            return null;

        var source = new RootSymbolTreeItemCollectionSource(this, item);
        lock (_filePathToCollectionSources)
        {
            _filePathToCollectionSources.MultiAdd(currentFilePath, source);
        }

        // Register to hear about if this hierarchy is disposed. We'll stop watching it if so.
        item.PropertyChanged += OnItemPropertyChanged;

Review comment (suggestion):
```suggestion
        // it being changed *when* we hear the update about it having changed (since the event doesn't
```

Code after:
        // Update all the affected documents in parallel.
        await Parallel.ForEachAsync(
            sources,
            cancellationToken,
            async (source, cancellationToken) =>
            {
                await source.UpdateIfEverBeenAskedToComputeAsync(cancellationToken)
                    .ReportNonFatalErrorUnlessCancelledAsync(cancellationToken)
                    .ConfigureAwait(false);
            }).ConfigureAwait(false);
    }

    protected override IAttachedCollectionSource? CreateCollectionSource(IVsHierarchyItem item, string relationshipName)
    {
        if (item == null ||
            item.IsDisposed ||
            item.HierarchyIdentity == null ||
            item.HierarchyIdentity.NestedHierarchy == null ||
            relationshipName != KnownRelationships.Contains)
        {
            return null;
        }

        // Important: currentFilePath is mutable state captured *AND UPDATED* in the local function  
        // OnItemPropertyChanged below.  It allows us to know the file path of the item *prior* to
        // it being changed *when* we hear the update about it having changed (since the event doesn't
        // contain the old value).  
        if (item.CanonicalName is not string currentFilePath)
            return null;

        if (item.HierarchyIdentity.NestedHierarchy.GetGuidProperty(
                item.HierarchyIdentity.ItemID,
                (int)__VSHPROPID.VSHPROPID_TypeGuid,
                out var guid) != VSConstants.S_OK)
        {
            return null;
        }

        // We only support this for real files that we'll then have Roslyn Documents for.  All the other
        // things in a project (like folders, nested projects, etc) are not supported.
        if (guid != VSConstants.ItemTypeGuid.PhysicalFile_guid)
            return null;

        var source = new RootSymbolTreeItemCollectionSource(this, item);
        lock (_filePathToCollectionSources)
        {
            _filePathToCollectionSources.MultiAdd(currentFilePath, source);
        }

        // Register to hear about if this hierarchy is disposed. We'll stop watching it if so.
        item.PropertyChanged += OnItemPropertyChanged;