Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Utilities;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer;

Expand Down Expand Up @@ -170,7 +171,7 @@ await source.UpdateIfEverExpandedAsync(cancellationToken)
var source = new RootSymbolTreeItemCollectionSource(this, item);
lock (_filePathToCollectionSources)
{
AddToDictionary(currentFilePath, source);
_filePathToCollectionSources.MultiAdd(currentFilePath, source);
}

// Register to hear about if this hierarchy is disposed. We'll stop watching it if so.
Expand All @@ -186,7 +187,7 @@ void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
// event for the IsDisposed property. When this fires, we remove the filePath->sourcce mapping we're holding.
lock (_filePathToCollectionSources)
{
RemoveFromDictionary(currentFilePath, source);
_filePathToCollectionSources.MultiRemove(currentFilePath, source);
}

item.PropertyChanged -= OnItemPropertyChanged;
Expand All @@ -200,8 +201,8 @@ void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{

// Unlink the oldPath->source mapping, and add a new line for the newPath->source.
RemoveFromDictionary(currentFilePath, source);
AddToDictionary(newPath, source);
_filePathToCollectionSources.MultiRemove(currentFilePath, source);
_filePathToCollectionSources.MultiAdd(newPath, source);

// Keep track of the 'newPath'.
currentFilePath = newPath;
Expand All @@ -216,29 +217,5 @@ void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
}
}
}

void AddToDictionary(string currentFilePath, RootSymbolTreeItemCollectionSource source)
{
if (!_filePathToCollectionSources.TryGetValue(currentFilePath, out var sources))
{
sources = [];
_filePathToCollectionSources[currentFilePath] = sources;
}

sources.Add(source);
}

void RemoveFromDictionary(string currentFilePath, RootSymbolTreeItemCollectionSource source)
{
if (_filePathToCollectionSources.TryGetValue(currentFilePath, out var sources))
{
sources.Remove(source);

if (sources.Count == 0)
{
_filePathToCollectionSources.Remove(currentFilePath);
}
}
}
}
}
Loading