protected override void QueueAfterCommit() { if (CommitStage == T4CommitStage.DependencyInvalidation) { return; } CommitStage = T4CommitStage.DependencyInvalidation; try { using (WriteLockCookie.Create()) { // Filter just in case a miracle happens and the file gets deleted before being marked as dirty foreach (var file in IndirectDependencies.Where(file => file.IsValid())) { Services.Files.MarkAsDirty(file); Services.Caches.MarkAsDirty(file); } } IndirectDependencies.Clear(); Services.Files.CommitAllDocuments(); } finally { CommitStage = T4CommitStage.UserChangeApplication; } }
public T4FileDependencyInvalidator( Lifetime lifetime, [NotNull] IT4FileGraphNotifier notifier, [NotNull] IPsiServices services, [NotNull] ISolution solution, [NotNull] IPsiServices psiServices ) { Solution = solution; PsiServices = psiServices; services.Files.ObserveAfterCommit(lifetime, () => { if (CommitStage == T4CommitStage.DependencyInvalidation) { return; } CommitStage = T4CommitStage.DependencyInvalidation; try { using (WriteLockCookie.Create()) { // Filter just in case a miracle happens and the file gets deleted before being marked as dirty foreach (var file in IndirectDependencies.Where(file => file.IsValid())) { services.Files.MarkAsDirty(file); services.Caches.MarkAsDirty(file); } } IndirectDependencies.Clear(); services.Files.CommitAllDocuments(); } finally { CommitStage = T4CommitStage.UserChangeApplication; } }); notifier.OnFilesIndirectlyAffected += paths => { if (CommitStage == T4CommitStage.DependencyInvalidation) { return; } // We want all files that were included before the update // and all the files that have become included now // to be updated, so we'll mark them as dirty later IndirectDependencies.AddRange(paths .Distinct() .SelectMany(Solution.FindProjectItemsByLocation) .OfType <IProjectFile>() .Select(PsiServices.Modules.GetPsiSourceFilesFor) .SelectMany(sourceFiles => sourceFiles.AsEnumerable())); }; }