public BinaryUnityFileCache(Lifetime lifetime, ISolution solution, IPersistentIndexManager persistentIndexManager, IShellLocks locks, ChangeManager changeManager) : base(lifetime, persistentIndexManager, BinaryFileCacheItem.Marshaller) { myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherOnSaveEvent", TimeSpan.FromMilliseconds(500), Rgc.Guarded, () => { var changedFiles = new JetHashSet <IPsiSourceFile>(myChangedFiles); myChangedFiles.Clear(); if (changedFiles.Count > 0) { locks.ExecuteWithWriteLock(() => changeManager.ExecuteAfterChange(() => { var builder = new PsiModuleChangeBuilder(); foreach (var file in changedFiles) { if (file.IsValid()) { builder.AddFileChange(file, PsiModuleChange.ChangeType.Modified); } } changeManager.OnProviderChanged(solution, builder.Result, SimpleTaskExecutor.Instance); })); } }); myChangedFiles = new JetHashSet <IPsiSourceFile>(); }
public UnityCacheUpdater(Lifetime lifetime, ISolution solution, UnityYamlSupport unityYamlSupport, IShellLocks locks, ChangeManager changeManager, UnityExternalFilesModuleFactory factory) { var module = factory.PsiModule; if (module != null) { unityYamlSupport.IsUnityYamlParsingEnabled.Change.Advise_NoAcknowledgement(lifetime, (handler) => { if (handler.HasNew && handler.HasOld && handler.New == handler.Old) { return; } locks.ExecuteOrQueueReadLockEx(lifetime, "YamlParsingStateChange", () => { var psiSourceFiles = module.SourceFiles.ToList(); if (psiSourceFiles.Any()) { locks.ExecuteWithWriteLock(() => changeManager.ExecuteAfterChange(() => { var changeBuilder = new PsiModuleChangeBuilder(); foreach (var sourceFile in psiSourceFiles) { if (sourceFile.IsValid()) { changeBuilder.AddFileChange(sourceFile, PsiModuleChange.ChangeType.Modified); } } changeManager.OnProviderChanged(solution, changeBuilder.Result, SimpleTaskExecutor.Instance); })); } }); }); } }
private void AddFile([NotNull] IProjectFile projectFile, [NotNull] PsiModuleChangeBuilder changeBuilder) { ISolution solution = projectFile.GetSolution(); // creates a new T4PsiModule for the file LifetimeDefinition lifetimeDefinition = Lifetimes.Define(_lifetime, "[T4]" + projectFile.Name); var psiModule = new T4PsiModule( lifetimeDefinition.Lifetime, solution.GetComponent <PsiModuleManager>(), solution.GetComponent <DocumentManager>(), _changeManager, solution.GetComponent <IAssemblyFactory>(), _shellLocks, projectFile, solution.GetComponent <T4FileDataCache>(), _t4Environment, solution.GetComponent <OutputAssembliesCache>()); _modules[projectFile] = new ModuleWrapper(psiModule, lifetimeDefinition); changeBuilder.AddModuleChange(psiModule, PsiModuleChange.ChangeType.ADDED); changeBuilder.AddFileChange(psiModule.SourceFile, PsiModuleChange.ChangeType.ADDED); // Invalidate files that had this specific files as an include, // and whose IPsiSourceFile was previously managed by T4OutsideSolutionSourceFileManager. // Those files will be reparsed with the new source file. var fileManager = solution.GetComponent <T4OutsideSolutionSourceFileManager>(); FileSystemPath location = projectFile.Location; if (fileManager.HasSourceFile(location)) { fileManager.DeleteSourceFile(location); InvalidateFilesHavingInclude(location, solution.GetPsiServices()); } }
private void RemoveFile([NotNull] IProjectFile projectFile, [NotNull] PsiModuleChangeBuilder changeBuilder, ModuleWrapper moduleWrapper) { _modules.Remove(projectFile); changeBuilder.AddFileChange(moduleWrapper.Module.SourceFile, PsiModuleChange.ChangeType.Removed); changeBuilder.AddModuleChange(moduleWrapper.Module, PsiModuleChange.ChangeType.Removed); moduleWrapper.LifetimeDefinition.Terminate(); }
private void AddFile([NotNull] IProjectFile projectFile, [NotNull] PsiModuleChangeBuilder changeBuilder) { ISolution solution = projectFile.GetSolution(); // creates a new T4PsiModule for the file var lifetimeDefinition = Lifetime.Define(_lifetime, T4FilePsiModule.Prefix + projectFile.Name); var psiModule = new T4FilePsiModule( lifetimeDefinition.Lifetime, projectFile, _changeManager, _shellLocks, _t4Environment, PrimaryTargetFrameworkId ); _modules[projectFile] = new ModuleWrapper(psiModule, lifetimeDefinition); psiModule.AddBaseReferences(); changeBuilder.AddModuleChange(psiModule, PsiModuleChange.ChangeType.Added); changeBuilder.AddFileChange(psiModule.SourceFile, PsiModuleChange.ChangeType.Added); // Invalidate files that had this specific files as an include, // and whose IPsiSourceFile was previously managed by T4OutsideSolutionSourceFileManager. // Those files will be reparsed with the new source file. var fileManager = solution.GetComponent <T4OutsideSolutionSourceFileManager>(); VirtualFileSystemPath location = projectFile.Location; if (fileManager.HasSourceFile(location)) { fileManager.DeleteSourceFile(location); } }
public void OnProjectFileChanged(IProjectFile projectFile, PsiModuleChange.ChangeType changeType, PsiModuleChangeBuilder changeBuilder, FileSystemPath oldLocation) { if (projectFile == null) { return; } var module = myModuleFactory.PsiModule; if (module == null) { return; } switch (changeType) { case PsiModuleChange.ChangeType.Added: case PsiModuleChange.ChangeType.Removed: // Do nothing. We only add/remove source files if the underlying file itself has been removed, which is // handled by UnityExternalFilesModuleProcessor and a file system watcher break; case PsiModuleChange.ChangeType.Modified: if (module.TryGetFileByPath(projectFile.Location, out var sourceFile)) { changeBuilder.AddFileChange(sourceFile, changeType); } break; } }
private void RemoveFile([NotNull] IProjectFile projectFile, [NotNull] PsiModuleChangeBuilder changeBuilder, ModuleWrapper moduleWrapper) { _modules.Remove(projectFile); changeBuilder.AddFileChange(moduleWrapper.Module.SourceFile, PsiModuleChange.ChangeType.REMOVED); changeBuilder.AddModuleChange(moduleWrapper.Module, PsiModuleChange.ChangeType.REMOVED); InvalidateFilesHavingInclude(projectFile.Location, moduleWrapper.Module.GetPsiServices()); moduleWrapper.LifetimeDefinition.Terminate(); }
public override void OnProjectFileChanged(IProjectFile projectFile, FileSystemPath oldLocation, PsiModuleChange.ChangeType changeType, PsiModuleChangeBuilder changeBuilder) { var extension = projectFile.Location.ExtensionWithDot; if (!CppProjectFileType.ALL_HLSL_EXTENSIONS.Contains(extension) && !ShaderLabProjectFileType.SHADERLAB_EXTENSION.Equals(extension)) { base.OnProjectFileChanged(projectFile, oldLocation, changeType, changeBuilder); return; } if (changeType == PsiModuleChange.ChangeType.Removed) { if (myModule.Files.TryGetValue(projectFile, out var psiFile)) { myModule.Files.Remove(projectFile); changeBuilder.AddFileChange(psiFile, PsiModuleChange.ChangeType.Removed); } } else if (changeType == PsiModuleChange.ChangeType.Added) { var sourceFile = new PsiProjectFile(myModule, projectFile, (file, sf) => sf.GetLocation().ExtensionWithDot.Equals(ShaderLabProjectFileType.SHADERLAB_EXTENSION) ? myShaderLabProperties : myCppProperties, (file, sf) => myModule.Files.ContainsKey(file), myDocumentManager, BaseHandler.PrimaryModule.GetResolveContextEx(projectFile)); myModule.Files.Add(projectFile, sourceFile); changeBuilder.AddFileChange(sourceFile, PsiModuleChange.ChangeType.Added); } else if (changeType == PsiModuleChange.ChangeType.Modified) { if (myModule.Files.TryGetValue(projectFile, out var psiFile)) { changeBuilder.AddFileChange(psiFile, PsiModuleChange.ChangeType.Modified); } } }
public void OnProjectFileChanged(IProjectFile projectFile, PsiModuleChange.ChangeType changeType, PsiModuleChangeBuilder changeBuilder, FileSystemPath oldLocation) { if (projectFile == null) { return; } var module = myModuleFactory.PsiModule; if (module == null) { return; } switch (changeType) { case PsiModuleChange.ChangeType.Added: if (projectFile.Location.IsInterestingAsset() && myAssetSerializationMode.IsForceText && !module.ContainsPath(projectFile.Location)) { // Create the PsiSourceFile, add it to the module, add the change to the builder var psiSourceFile = myPsiSourceFileFactory.CreatePsiProjectFile(module, projectFile); module.Add(projectFile.Location, psiSourceFile, null); changeBuilder.AddFileChange(psiSourceFile, PsiModuleChange.ChangeType.Added); } break; case PsiModuleChange.ChangeType.Removed: // Do nothing. We only remove source files if the underlying file itself has been removed, which is // handled by UnityExternalFilesModuleProcessor and a file system watcher break; case PsiModuleChange.ChangeType.Modified: if (module.TryGetFileByPath(projectFile.Location, out var sourceFile)) { changeBuilder.AddFileChange(sourceFile, changeType); } break; } }
private void AddMetaPsiSourceFile(PsiModuleChangeBuilder builder, FileSystemPath path) { Assertion.AssertNotNull(myModuleFactory.PsiModule, "myModuleFactory.PsiModule != null"); if (myModuleFactory.PsiModule.ContainsPath(path)) { return; } var sourceFile = myPsiSourceFileFactory.CreateExternalPsiSourceFile(myModuleFactory.PsiModule, path); builder.AddFileChange(sourceFile, PsiModuleChange.ChangeType.Added); }
private static void ModifyFile([NotNull] PsiModuleChangeBuilder changeBuilder, ModuleWrapper moduleWrapper) { changeBuilder.AddFileChange(moduleWrapper.Module.SourceFile, PsiModuleChange.ChangeType.MODIFIED); }
private void ProcessFileSystemChangeDelta(FileSystemChangeDelta delta, PsiModuleChangeBuilder builder, List <FileSystemPath> projectFilesToAdd) { var module = myModuleFactory.PsiModule; if (module == null) { return; } IPsiSourceFile sourceFile; switch (delta.ChangeType) { case FileSystemChangeType.ADDED: if (delta.NewPath.IsInterestingAsset()) { if (!IsKnownBinaryAsset(delta.NewPath) && !IsAssetExcludedByName(delta.NewPath)) { projectFilesToAdd.Add(delta.NewPath); } } else if (delta.NewPath.IsInterestingMeta()) { AddMetaPsiSourceFile(builder, delta.NewPath); } break; case FileSystemChangeType.DELETED: sourceFile = GetYamlPsiSourceFile(module, delta.OldPath); if (sourceFile != null) { builder.AddFileChange(sourceFile, PsiModuleChange.ChangeType.Removed); } break; case FileSystemChangeType.CHANGED: sourceFile = GetYamlPsiSourceFile(module, delta.NewPath); if (sourceFile != null) { // Make sure we update the cached file system data, or all of our files will have stale // timestamps and never get updated by ICache implementations! if (sourceFile is PsiSourceFileFromPath psiSourceFileFromPath) { psiSourceFileFromPath.GetCachedFileSystemData().Refresh(delta.NewPath); } // Has the file flipped from binary back to text? if (myBinaryUnityFileCache.IsBinaryFile(sourceFile) && sourceFile.GetLocation().SniffYamlHeader()) { myBinaryUnityFileCache.Invalidate(sourceFile); } builder.AddFileChange(sourceFile, PsiModuleChange.ChangeType.Modified); } break; case FileSystemChangeType.SUBTREE_CHANGED: case FileSystemChangeType.RENAMED: case FileSystemChangeType.UNKNOWN: break; } foreach (var child in delta.GetChildren()) { ProcessFileSystemChangeDelta(child, builder, projectFilesToAdd); } }