Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Notify user, when compilation before tests failed #931

Merged
merged 3 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -21,6 +21,7 @@
using JetBrains.ReSharper.UnitTestProvider.nUnit.v30;
using JetBrains.ReSharper.UnitTestProvider.nUnit.v30.Elements;
using JetBrains.Rider.Model;
using JetBrains.Rider.Model.Notifications;
using JetBrains.Util;
using JetBrains.Util.Dotnet.TargetFrameworkIds;
using UnitTestLaunch = JetBrains.Platform.Unity.EditorPluginModel.UnitTestLaunch;
Expand All @@ -40,6 +41,9 @@ public class RunViaUnityEditorStrategy : IUnitTestRunStrategy
private readonly IUnitTestElementIdFactory myIDFactory;
private readonly ISolutionSaver myRiderSolutionSaver;
private readonly UnityRefresher myUnityRefresher;
private readonly NotificationsModel myNotificationsModel;
private readonly UnityHost myUnityHost;
private readonly ILogger myLogger;

private static Key<string> ourLaunchedInUnityKey = new Key<string>("LaunchedInUnityKey");
private WeakToWeakDictionary<UnitTestElementId, IUnitTestElement> myElements;
Expand All @@ -50,7 +54,10 @@ public RunViaUnityEditorStrategy(ISolution solution,
NUnitTestProvider unitTestProvider,
IUnitTestElementIdFactory idFactory,
ISolutionSaver riderSolutionSaver,
UnityRefresher unityRefresher
UnityRefresher unityRefresher,
NotificationsModel notificationsModel,
UnityHost unityHost,
ILogger logger
)
{
mySolution = solution;
Expand All @@ -60,6 +67,9 @@ UnityRefresher unityRefresher
myIDFactory = idFactory;
myRiderSolutionSaver = riderSolutionSaver;
myUnityRefresher = unityRefresher;
myNotificationsModel = notificationsModel;
myUnityHost = unityHost;
myLogger = logger;
myElements = new WeakToWeakDictionary<UnitTestElementId, IUnitTestElement>();
}

Expand Down Expand Up @@ -117,12 +127,14 @@ Task IUnitTestRunStrategy.Run(IUnitTestRun run)
// https://docs.unity3d.com/ScriptReference/Compilation.CompilationPipeline-assemblyCompilationFinished.html
// https://docs.unity3d.com/ScriptReference/Compilation.CompilationPipeline-assemblyCompilationStarted.html
// Note that those events are only available for Unity 5.6+
myLogger.Verbose("Before calling Refresh.");
Refresh(mySolution.Locks, run.Lifetime).GetAwaiter().OnCompleted(() =>
{
mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "Check compilation", () =>
{
if (myEditorProtocol.UnityModel.Value == null)
{
myLogger.Verbose("Unity Editor connection unavailable.");
tcs.SetException(new Exception("Unity Editor connection unavailable."));
return;
}
Expand All @@ -133,6 +145,13 @@ Task IUnitTestRunStrategy.Run(IUnitTestRun run)
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 RdNotificationEntry("Compilation failed", "Script compilation in Unity failed, so tests were not started.", true, RdNotificationEntryType.INFO);
myNotificationsModel.Notification.Fire(notification);
});
myUnityHost.PerformModelAction(model => model.ActivateUnityLogView.Fire());
}
else
{
Expand Down Expand Up @@ -189,14 +208,16 @@ await refreshTask.ContinueWith(task =>
var rdTask = myEditorProtocol.UnityModel.Value.GetUnityEditorState.Start(RdVoid.Instance);
rdTask?.Result.Advise(lifetime, result =>
{
if (result.Result != UnityEditorState.Refresh)
if (result.Result != UnityEditorState.Refresh && result.Result != UnityEditorState.Disconnected)
{
lifetimeDefinition.Terminate();
myLogger.Verbose("lifetimeDefinition.Terminate();");
}
});
}
});
}, locks.Tasks.UnguardedMainThreadScheduler);

while (lifetimeDefinition.Lifetime.IsAlive)
{
await Task.Delay(50, lifetimeDefinition.Lifetime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public UnityNUnitServiceProvider(ISolution solution, IPsiModules psiModules, ISy

public override IUnitTestRunStrategy GetRunStrategy(IUnitTestElement element)
{
if (!myEditorModel.HasValue() || myEditorModel.Value == null)
if (myEditorModel.Value == null)
return base.GetRunStrategy(element);

// first run from gutter mark should try to run in Unity by default. https://github.com/JetBrains/resharper-unity/issues/605
Expand Down
10 changes: 7 additions & 3 deletions resharper/resharper-unity/src/Rider/UnityEditorProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ private void CreateProtocols(FileSystemPath protocolInstancePath)
new Identities(IdKind.Client), myDispatcher, wire);
var editor = new EditorPluginModel(lf, protocol);
editor.IsBackendConnected.Set(rdVoid => true);
var frontendProcess = Process.GetCurrentProcess().GetParent();
if (frontendProcess != null)

if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.Windows)
{
editor.RiderProcessId.SetValue(frontendProcess.Id);
var frontendProcess = Process.GetCurrentProcess().GetParent(); // RiderProcessId is not used on non-Windows, but this line gives bad warning in the log
if (frontendProcess != null)
{
editor.RiderProcessId.SetValue(frontendProcess.Id);
}
}

myHost.PerformModelAction(m => m.SessionInitialized.Value = true);
Expand Down
1 change: 1 addition & 0 deletions rider/protocol/src/main/kotlin/model/rider/RdUnityModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ object RdUnityModel : Ext(SolutionModel.Solution) {

init {
sink("activateRider", void)
sink("activateUnityLogView", void)

property("editorState", EditorState)
property("unitTestPreference", UnitTestLaunchPreference.nullable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.jetbrains.rider.util.idea.getLogger
import com.jetbrains.rider.util.reactive.whenTrue

class UnityToolWindowManager(project: Project,
private val host: UnityHost,
host: UnityHost,
private val unityToolWindowFactory: UnityToolWindowFactory)
: LifetimedProjectComponent(project) {
companion object {
Expand All @@ -30,5 +30,10 @@ class UnityToolWindowManager(project: Project,

context.addEvent(message)
}

host.model.activateUnityLogView.advise(componentLifetime){
val context = unityToolWindowFactory.getOrCreateContext()
context.activateToolWindowIfNotActive()
}
}
}