private void UpdateDependenciesSnapshot( ImmutableDictionary <ITargetFramework, IDependenciesChanges> changes, IProjectCatalogSnapshot catalogs, ITargetFramework activeTargetFramework, CancellationToken token) { IImmutableSet <string> projectItemSpecs = GetProjectItemSpecsFromSnapshot(); TryUpdateSnapshot( snapshot => DependenciesSnapshot.FromChanges( _commonServices.Project.FullPath, snapshot, changes, catalogs, activeTargetFramework, _snapshotFilters.ToImmutableValueArray(), _subTreeProviders.ToValueDictionary(p => p.ProviderType), projectItemSpecs), token); return; // Gets the set of items defined directly the project, and not included by imports. IImmutableSet <string> GetProjectItemSpecsFromSnapshot() { // We don't have catalog snapshot, we're likely updating because one of our project // dependencies changed. Just return 'no data' if (catalogs == null) { return(null); } ImmutableHashSet <string> .Builder itemSpecs = ImmutableHashSet.CreateBuilder(StringComparer.OrdinalIgnoreCase); foreach (ProjectItemInstance item in catalogs.Project.ProjectInstance.Items) { if (item.IsImported()) { continue; } // Returns unescaped evaluated include string itemSpec = item.EvaluatedInclude; if (itemSpec.Length != 0) { itemSpecs.Add(itemSpec); } } return(itemSpecs.ToImmutable()); } }
private void UpdateDependenciesSnapshot( ImmutableDictionary <ITargetFramework, IDependenciesChanges> changes, IProjectCatalogSnapshot catalogs, ITargetFramework activeTargetFramework, CancellationToken token) { IImmutableSet <string> projectItemSpecs = GetProjectItemSpecsFromSnapshot(); bool anyChanges = false; // Note: we are updating existing snapshot, not receiving a complete new one. Thus we must // ensure incremental updates are done in the correct order. This lock ensures that here. lock (_snapshotLock) { var updatedSnapshot = DependenciesSnapshot.FromChanges( _commonServices.Project.FullPath, _currentSnapshot, changes, catalogs, activeTargetFramework, _snapshotFilters.ToImmutableValueArray(), _subTreeProviders.ToValueDictionary(p => p.ProviderType), projectItemSpecs); if (!ReferenceEquals(_currentSnapshot, updatedSnapshot)) { _currentSnapshot = updatedSnapshot; anyChanges = true; } } if (anyChanges) { // avoid unnecessary tree updates ScheduleDependenciesUpdate(token); } return; // Gets the set of items defined directly the project, and not included by imports. IImmutableSet <string> GetProjectItemSpecsFromSnapshot() { // We don't have catalog snapshot, we're likely updating because one of our project // dependencies changed. Just return 'no data' if (catalogs == null) { return(null); } ImmutableHashSet <string> .Builder itemSpecs = ImmutableHashSet.CreateBuilder(StringComparer.OrdinalIgnoreCase); foreach (ProjectItemInstance item in catalogs.Project.ProjectInstance.Items) { if (item.IsImported()) { continue; } // Returns unescaped evaluated include string itemSpec = item.EvaluatedInclude; if (itemSpec.Length != 0) { itemSpecs.Add(itemSpec); } } return(itemSpecs.ToImmutable()); } }