public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher, ILogger logger, IFileSystemTracker fileSystemTracker, UnityHost host, UnitySolutionTracker unitySolutionTracker) { myRefresher = refresher; myLogger = logger; if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null) { return; } unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args => { if (!args) { return; } // Rgc.Guarded - beware RIDER-15577 myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherGroupingEvent", TimeSpan.FromMilliseconds(500), Rgc.Guarded, () => { refresher.Refresh(RefreshType.Normal); }); host.PerformModelAction(rd => rd.Refresh.Advise(lifetime, force => { if (force) { refresher.Refresh(RefreshType.ForceRequestScriptReload); } else { myGroupingEvent.FireIncoming(); } })); }); unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args => { if (!args) { return; } var protocolSolution = solution.GetProtocolSolution(); protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ => { logger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved"); myGroupingEvent.FireIncoming(); }); fileSystemTracker.RegisterPrioritySink(lifetime, FileSystemChange, HandlingPriority.Other); }); }
private void InstallPluginIfRequired() { if (!myUnitySolutionTracker.IsUnityProjectFolder.Value) { return; } if (myPluginInstallations.Contains(mySolution.SolutionFilePath)) { return; } if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin)) { return; } // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider // ReSharper disable once ArgumentsStyleNamedExpression var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty); if (!installationInfo.ShouldInstallPlugin) { myLogger.Info("Plugin should not be installed."); if (installationInfo.ExistingFiles.Count > 0) { myLogger.Info("Already existing plugin files:\n{0}", string.Join("\n", installationInfo.ExistingFiles)); } return; } QueueInstall(installationInfo); myQueue.Enqueue(() => { myRefresher.Refresh(false); }); }
private void AdviseFileAddedOrDeleted(FileSystemChangeDelta delta) { if (delta.NewPath.ExtensionNoDot == "cs") { myLogger.Verbose($"fileSystemTracker.AdviseDirectoryChanges {delta.ChangeType}, {delta.NewPath}, {delta.OldPath}"); myRefresher.Refresh(RefreshType.Normal); } }
public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher, ILogger logger, IFileSystemTracker fileSystemTracker, UnityHost host, UnitySolutionTracker unitySolutionTracker) { myRefresher = refresher; myLogger = logger; if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null) { return; } unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args => { if (!args) { return; } host.PerformModelAction(rd => rd.Refresh.Advise(lifetime, force => { refresher.Refresh(force ? RefreshType.ForceRequestScriptReload : RefreshType.Normal); })); }); unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args => { if (!args) { return; } var protocolSolution = solution.GetProtocolSolution(); protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ => { logger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved"); refresher.Refresh(RefreshType.Normal); }); fileSystemTracker.RegisterPrioritySink(lifetime, FileSystemChange, HandlingPriority.Other); }); }
public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher, ChangeManager changeManager, UnityEditorProtocol protocolController) { if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null) { return; } var groupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherOnSaveEvent", TimeSpan.FromMilliseconds(500), Rgc.Invariant, () => refresher.Refresh(false)); var protocolSolution = solution.GetProtocolSolution(); protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ => { if (refresher.IsRefreshing) { return; } if (protocolController.UnityModel.Value == null) { return; } groupingEvent.FireIncoming(); }); changeManager.Changed2.Advise(lifetime, args => { var changes = args.ChangeMap.GetChanges <ProjectModelChange>(); if (changes == null) { return; } if (refresher.IsRefreshing) { return; } var hasChange = changes.Any(HasAnyFileChangeRec); if (!hasChange) { return; } groupingEvent.FireIncoming(); }); }
private void InstallPluginIfRequired() { if (!myUnitySolutionTracker.IsUnityProjectFolder.Value) { return; } if (myPluginInstallations.Contains(mySolution.SolutionFilePath)) { return; } if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin)) { return; } // Unity 2019.2+ is expected to have com.unity.ide.rider package, which loads EditorPlugin directly from Rider installation var manifestJsonFile = mySolution.SolutionDirectory.Combine("Packages/manifest.json"); if (manifestJsonFile.ExistsFile) { var text = manifestJsonFile.ReadAllText2().Text; //"com.unity.ide.rider": "1.0.7" var match = Regex.Match(text, @"""com\.unity\.ide\.rider""\s*:\s*""(?<version>.*)""", RegexOptions.Multiline); if (match.Success) { if (Version.TryParse(match.Groups["version"].Value, out var version)) { if (version >= new Version(1, 0, 7)) { myLogger.Verbose($"com.unity.ide.rider version {version}. Skip EditorPlugin installation."); return; } myLogger.Verbose($"com.unity.ide.rider version {version}. EditorPlugin installation continues."); } } } var localPackage = mySolution.SolutionDirectory.Combine("Packages/com.unity.ide.rider/package.json"); if (localPackage.ExistsFile) { myLogger.Verbose("Local package com.unity.ide.rider detected, skip EditorPlugin installation."); return; } // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider // ReSharper disable once ArgumentsStyleNamedExpression var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty); if (!installationInfo.ShouldInstallPlugin) { myLogger.Info("Plugin should not be installed."); if (installationInfo.ExistingFiles.Count > 0) { myLogger.Info("Already existing plugin files:\n{0}", string.Join("\n", installationInfo.ExistingFiles)); } return; } QueueInstall(installationInfo); myQueue.Enqueue(() => { mySolution.Locks.Tasks.StartNew(myLifetime, Scheduling.MainDispatcher, () => myRefresher.Refresh(RefreshType.Normal)); }); }
public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher, UnityEditorProtocol protocolController, DocumentTransactionManager documentTransactionManager, IShellLocks locks, ILogger logger) { myLogger = logger; if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null) { return; } var groupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherOnSaveEvent", TimeSpan.FromMilliseconds(500), Rgc.Invariant, () => refresher.Refresh(false)); var protocolSolution = solution.GetProtocolSolution(); protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ => { if (protocolController.UnityModel.Value == null) { return; } myLogger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved"); groupingEvent.FireIncoming(); }); documentTransactionManager.AfterTransactionCommit.Advise(lifetime, args => { if (protocolController.UnityModel.Value == null) { return; } if (args.Succeded && args.Changes != null && args.Changes.Any()) { locks.ExecuteWithReadLock(() => { if (documentTransactionManager.CurrentTransaction?.ParentTransaction == null) { myLogger.Verbose("documentTransactionManager.AfterTransactionCommit"); groupingEvent.FireIncoming(); } }); } }); }