private async Task <ProjectMap> CreateProjectMapAsync(ConcurrentSet <SymbolGroup> symbolGroups, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.FindReference_CreateProjectMapAsync, cancellationToken)) { var projectMap = new ProjectMap(); var scope = _documents?.Select(d => d.Project).ToImmutableHashSet(); foreach (var symbolGroup in symbolGroups) { foreach (var symbol in symbolGroup.Symbols) { cancellationToken.ThrowIfCancellationRequested(); var projects = await DependentProjectsFinder.GetDependentProjectsAsync( _solution, symbol, scope, cancellationToken).ConfigureAwait(false); foreach (var project in projects.Distinct().WhereNotNull()) { if (scope == null || scope.Contains(project)) { projectMap.MultiAdd(project, symbol); } } } } Contract.ThrowIfTrue(projectMap.Any(kvp => kvp.Value.Count != kvp.Value.ToSet().Count)); return(projectMap); } }