Exemplo n.º 1
0
 public void OnExtraActionClick(CodeInsightsHighlighting highlighting, string actionId)
 {
     if (actionId.Equals(StartUnityActionId))
     {
         myHost.PerformModelAction(model => model.StartUnity.Fire(RdVoid.Instance));
     }
 }
 public void OnExtraActionClick(CodeInsightsHighlighting highlighting, string actionId, ISolution solution)
 {
     if (actionId.Equals(StartUnityActionId))
     {
         myHost.PerformModelAction(model => model.StartUnity());
     }
 }
Exemplo n.º 3
0
        public RiderUnityYamlDisableStrategy(Lifetime lifetime, ISolution solution, ISettingsStore settingsStore,
                                             UnityYamlSupport unityYamlSupport, UnityHost unityHost)
            : base(lifetime, solution, settingsStore, unityYamlSupport)
        {
            myUnityHost = unityHost;

            myUnityHost.PerformModelAction(t =>
                                           t.EnableYamlParsing.Advise(lifetime, _ => unityYamlSupport.IsUnityYamlParsingEnabled.Value = true));
        }
Exemplo n.º 4
0
        public RiderUnityYamlDisableStrategy(Lifetime lifetime, ISolution solution, SolutionCaches solutionCaches, ISettingsStore settingsStore,
                                             AssetIndexingSupport assetIndexingSupport, UnityHost unityHost)
            : base(lifetime, solution, solutionCaches, settingsStore, assetIndexingSupport)
        {
            myUnityHost = unityHost;

            myUnityHost.PerformModelAction(t =>
                                           t.EnableYamlParsing.Advise(lifetime, _ => assetIndexingSupport.IsEnabled.Value = true));
        }
Exemplo n.º 5
0
        public static Action ProcessDataContext(
            [NotNull] Lifetime lifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))] IPsiDocumentRangeView psiDocumentRangeView,
            UnityHost host,
            UnityApi unityApi)
        {
            var unityName = GetUnityName(psiDocumentRangeView, unityApi);

            // This is called only if the process finished while the context is still valid
            return(() => { host.PerformModelAction(rd => rd.ExternalDocContext.Value = unityName); });
        }
        public AssetModeNotification(UnitySolutionTracker solutionTracker, AssetSerializationMode assetSerializationMode, UnityHost unityHost)
        {
            if (!solutionTracker.IsUnityProject.HasTrueValue())
            {
                return;
            }

            if (!assetSerializationMode.IsForceText)
            {
                unityHost.PerformModelAction(t => t.NotifyAssetModeForceText());
            }
        }
Exemplo n.º 7
0
 public static void SetModelData(this UnityHost host, string key, string value)
 {
     host.PerformModelAction(m =>
     {
         var data = m.Data;
         if (data.ContainsKey(key))
         {
             data[key] = value;
         }
         else
         {
             data.Add(key, value);
         }
     });
 }
        private void RefreshAndRunTask(IUnitTestRun run, TaskCompletionSource <bool> tcs, Lifetime taskLifetime)
        {
            var cancellationTs = run.GetData(ourCancellationTokenSourceKey);

            myLogger.Verbose("Before calling Refresh.");
            Refresh(run.Lifetime, cancellationTs.NotNull().Token).GetAwaiter().OnCompleted(() =>
            {
                // KS: Can't use run.Lifetime for ExecuteOrQueueEx here and in all similar places: run.Lifetime is terminated when
                // Unit Test Session is closed from UI without cancelling the run. This will leave task completion source in running state forever.
                mySolution.Locks.ExecuteOrQueueEx(myLifetime, "Check compilation", () =>
                {
                    if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                    {
                        tcs.SetCanceled();
                        return;
                    }

                    if (myEditorProtocol.UnityModel.Value == null)
                    {
                        myLogger.Verbose("Unity Editor connection unavailable.");
                        tcs.SetException(new Exception("Unity Editor connection unavailable."));
                        return;
                    }

                    var task = myEditorProtocol.UnityModel.Value.GetCompilationResult.Start(Unit.Instance);
                    task.Result.AdviseNotNull(myLifetime, result =>
                    {
                        if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                        {
                            tcs.SetCanceled();
                        }
                        else if (!result.Result)
                        {
                            tcs.SetException(new Exception("There are errors during compilation in Unity."));

                            mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "RunViaUnityEditorStrategy compilation failed",
                                                              () =>
                            {
                                var notification = new NotificationModel("Compilation failed",
                                                                         "Script compilation in Unity failed, so tests were not started.", true,
                                                                         RdNotificationEntryType.INFO);
                                myNotificationsModel.Notification(notification);
                            });
                            myUnityHost.PerformModelAction(model => model.ActivateUnityLogView());
                        }
                        else
                        {
                            var launch = SetupLaunch(run);
                            mySolution.Locks.ExecuteOrQueueEx(myLifetime, "ExecuteRunUT", () =>
                            {
                                if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                                {
                                    tcs.SetCanceled();
                                    return;
                                }

                                if (myEditorProtocol.UnityModel.Value == null)
                                {
                                    tcs.SetException(new Exception("Unity Editor connection unavailable."));
                                    return;
                                }

                                myEditorProtocol.UnityModel.ViewNotNull(taskLifetime, (lt, model) =>
                                {
                                    // recreate UnitTestLaunch in case of AppDomain.Reload, which is the case with PlayMode tests
                                    model.UnitTestLaunch.SetValue(launch);
                                    SubscribeResults(run, lt, tcs, launch);
                                });

                                myUnityProcessId.When(taskLifetime, (int?)null, _ => tcs.TrySetException(new Exception("Unity Editor has been closed.")));

                                var rdTask = myEditorProtocol.UnityModel.Value.RunUnitTestLaunch.Start(Unit.Instance);
                                rdTask?.Result.Advise(taskLifetime, res =>
                                {
                                    myLogger.Trace($"RunUnitTestLaunch result = {res.Result}");
                                    if (!res.Result)
                                    {
                                        var defaultMessage = "Failed to start tests in Unity.";

                                        var isCoverage =
                                            run.HostController.HostId != WellKnownHostProvidersIds.DebugProviderId &&
                                            run.HostController.HostId != WellKnownHostProvidersIds.RunProviderId;

                                        if (myPackageValidator.HasNonCompatiblePackagesCombination(isCoverage, out var message))
                                        {
                                            defaultMessage = $"{defaultMessage} {message}";
                                        }

                                        if (myEditorProtocol.UnityModel.Value.UnitTestLaunch.Value.TestMode == TestMode.Play)
                                        {
                                            if (!myPackageValidator.CanRunPlayModeTests(out var playMessage))
                                            {
                                                defaultMessage = $"{defaultMessage} {playMessage}";
                                            }
                                        }

                                        tcs.TrySetException(new Exception(defaultMessage));
                                    }
                                });
                            });
                        }
                    });
Exemplo n.º 9
0
 protected override void NotifyYamlParsingDisabled()
 {
     myUnityHost.PerformModelAction(t => t.NotifyYamlHugeFiles.Fire(RdVoid.Instance));
 }
 protected override void NotifyYamlParsingDisabled()
 {
     myUnityHost.PerformModelAction(t => t.NotifyYamlHugeFiles());
 }
        public GeneratedFileNotification(Lifetime lifetime, UnityHost unityHost, UnitySolutionTracker solutionTracker,
                                         ConnectionTracker connectionTracker, UnityEditorProtocol editorProtocol, ISolution solution,
                                         AsmDefNameCache asmDefNameCache, [CanBeNull] TextControlHost textControlHost = null,
                                         [CanBeNull] SolutionLifecycleHost solutionLifecycleHost = null, [CanBeNull] NotificationPanelHost notificationPanelHost = null)
        {
            if (solutionLifecycleHost == null)
            {
                return;
            }

            if (!solutionTracker.IsUnityGeneratedProject.Value)
            {
                return;
            }

            var fullStartupFinishedLifetimeDefinition = new LifetimeDefinition(lifetime);

            solutionLifecycleHost.FullStartupFinished.Advise(fullStartupFinishedLifetimeDefinition.Lifetime, _ =>
            {
                textControlHost.ViewHostTextControls(lifetime, (lt, id, host) =>
                {
                    var projectFile = host.ToProjectFile(solution);
                    if (projectFile == null)
                    {
                        return;
                    }

                    if (projectFile.Location.ExtensionNoDot.Equals("csproj", StringComparison.OrdinalIgnoreCase))
                    {
                        connectionTracker.State.View(lt, (unityStateLifetime, state) =>
                        {
                            var name = projectFile.Location.NameWithoutExtension;

                            IPath path;
                            using (ReadLockCookie.Create())
                            {
                                path = asmDefNameCache.GetPathFor(name)?.TryMakeRelativeTo(solution.SolutionFilePath);
                            }

                            var elements = new LocalList <INotificationPanelHyperlink>();
                            if (path != null && state != UnityEditorState.Disconnected)
                            {
                                var strPath = path.Components.Join("/").RemoveStart("../");
                                elements.Add(new NotificationPanelCallbackHyperlink(unityStateLifetime, "Edit corresponding .asmdef in Unity", false,
                                                                                    () =>
                                {
                                    unityHost.PerformModelAction(t => t.AllowSetForegroundWindow.Start(unityStateLifetime, Unit.Instance).Result.Advise(unityStateLifetime,
                                                                                                                                                        __ =>
                                    {
                                        editorProtocol.UnityModel.Value?.ShowFileInUnity.Fire(strPath);
                                    }));
                                }));
                            }

                            notificationPanelHost.AddNotificationPanel(unityStateLifetime, host, new NotificationPanel("This file is generated by Unity. Any changes made will be lost.", "UnityGeneratedFile", elements.ToArray()));
                        });
                    }
                });

                fullStartupFinishedLifetimeDefinition.Terminate();
            });
        }