Skip to content

Pre commit hook, which was checking unsaved scenes, is not checking also other GameObjects states, like ScriptableObjects #2338

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
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
Expand Up @@ -105,12 +105,12 @@ private void AdviseFrontendToUnityModel(Lifetime lifetime, FrontendBackendModel
: backendUnityModel.RunMethodInUnity.Start(l, data).ToRdTask(l);
});

frontendBackendModel.HasUnsavedScenes.Set((l, u) =>
frontendBackendModel.HasUnsavedState.Set((l, u) =>
{
var backendUnityModel = backendUnityModelProperty.Maybe.ValueOrDefault;
return backendUnityModel == null
? Rd.Tasks.RdTask<bool>.Cancelled()
: backendUnityModel.HasUnsavedScenes.Start(l, u).ToRdTask(l);
: backendUnityModel.HasUnsavedState.Start(l, u).ToRdTask(l);
});

frontendBackendModel.StartProfiling.Set((l, play) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Uri GetUri([NotNull] string keyword)
private string GetVersionSpecificPieceOfUrl()
{
var version = mySolutionsManager.Solution?.GetComponent<UnityVersion>().ActualVersionForSolution.Value;
if (version == null)
if (version == null || version.Major == 0)
return string.Empty;

// Version before 2017.1 has different format of version:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ object BackendUnityModel: Root() {
property("unitTestLaunch", UnitTestLaunch).documentation = "Set the details of the current unit test session"
call("runUnitTestLaunch", void, bool).documentation = "Start the unit test session. Results are fired via UnitTestLaunch.TestResult"

call ("hasUnsavedScenes", void, bool)
call ("hasUnsavedState", void, bool)

// profiler
call ("startProfiling", ProfilingData, void).documentation = "Start profiling and enter PlayMode, depending on the param"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object FrontendBackendModel : Ext(SolutionModel.Solution) {
call("runMethodInUnity", Library.RunMethodData, Library.RunMethodResult)
property("isDeferredCachesCompletedOnce", bool)

call ("hasUnsavedScenes", void, bool)
call ("hasUnsavedState", void, bool)

// Actions called from Unity to the backend
callback("openFileLineCol", RdOpenFileArgs, bool).documentation = "Called from Unity to quickly open a file in an existing Rider instance"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package com.jetbrains.rider.plugins.unity.actions

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import com.jetbrains.rider.plugins.unity.isConnectedToEditor
import com.jetbrains.rider.plugins.unity.toolWindow.UnityToolWindowFactory

class ShowUnityLogInRiderAction : DumbAwareAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project?: return
e.getFrontendBackendModel() ?: return
UnityToolWindowFactory.show(project)
val context = UnityToolWindowFactory.getInstance(project).getOrCreateContext()
context.activateToolWindowIfNotActive()
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = e.project.isConnectedToEditor()
e.presentation.isEnabled = e.getFrontendBackendModel() != null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import com.jetbrains.rider.util.idea.getService
import org.jdom.Element

@State(name = "UnityCheckinConfiguration", storages = [(Storage(StoragePathMacros.WORKSPACE_FILE))])
class UnsavedSceneCheckinState(val project: Project) : PersistentStateComponent<Element> {
class UnsavedCheckinState(val project: Project) : PersistentStateComponent<Element> {

companion object {
fun getService(project: Project) = project.getService<UnsavedSceneCheckinState>()
fun getService(project: Project) = project.getService<UnsavedCheckinState>()
const val attributeName = "checkUnsavedScenes"
}

var checkUnsavedScenes: Boolean = true
var checkUnsavedState: Boolean = true

override fun getState(): Element {
val element = Element("state")
element.setAttribute(attributeName, checkUnsavedScenes.toString())
element.setAttribute(attributeName, checkUnsavedState.toString())
return element
}

override fun loadState(element: Element) {
val attributeValue = element.getAttributeBooleanValue(attributeName)
checkUnsavedScenes = attributeValue
checkUnsavedState = attributeValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ private class UnresolvedMergeCheckHandler(
) : CheckinHandler() {

private val project = panel.project
private val settings = UnsavedSceneCheckinState.getService(project)
private val settings = UnsavedCheckinState.getService(project)
override fun getBeforeCheckinConfigurationPanel(): RefreshableOnComponent? {
if (!project.isUnityProject())
return null

return BooleanCommitOption(
panel, UnityUIBundle.message("commitOption.check.unsaved.unity.scenes"), false,
settings::checkUnsavedScenes
panel, UnityUIBundle.message("commitOption.check.unsaved.unity.state"), false,
settings::checkUnsavedState
)
}

override fun beforeCheckin(
executor: CommitExecutor?,
additionalDataConsumer: PairConsumer<Any, Any>
): ReturnResult {
if (settings.checkUnsavedScenes && project.isUnityProject()) {
if (settings.checkUnsavedState && project.isUnityProject()) {
var providerResult = false
try {
providerResult = project.solution.frontendBackendModel.hasUnsavedScenes
providerResult = project.solution.frontendBackendModel.hasUnsavedState
.sync(Unit, RpcTimeouts(200L, 200L))
}
catch (t: CancellationException){
Expand All @@ -69,8 +69,8 @@ private class UnresolvedMergeCheckHandler(
private fun askUser(): ReturnResult {
val dialogResult = Messages.showOkCancelDialog(
project,
UnityUIBundle.message("dialog.unsaved.message.changes.in.unity.scenes.will.not.be.included.in.commit"),
UnityUIBundle.message("dialog.unsaved.title.unity.scenes"),
UnityUIBundle.message("dialog.unsaved.message.changes.in.unity.state.will.not.be.included.in.commit"),
UnityUIBundle.message("dialog.unsaved.title.unity.state"),
UnityUIBundle.message("dialog.unsaved.button.commit.anyway"),
UnityUIBundle.message("dialog.unsaved.button.cancel"),
Messages.getWarningIcon()
Expand Down
2 changes: 1 addition & 1 deletion rider/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<diff.merge.external.AutomaticExternalMergeTool implementation="com.jetbrains.rider.plugins.unity.diff.UnityYamlAutomaticExternalMergeTool"/>

<checkinHandlerFactory implementation="com.jetbrains.rider.plugins.unity.ui.vcs.UnsavedSceneCheckinHandlerFactory"/>
<projectService serviceImplementation="com.jetbrains.rider.plugins.unity.ui.vcs.UnsavedSceneCheckinState"/>
<projectService serviceImplementation="com.jetbrains.rider.plugins.unity.ui.vcs.UnsavedCheckinState"/>

<checkinHandlerFactory implementation="com.jetbrains.rider.plugins.unity.ui.vcs.MetaFilesCheckinHandlerFactory"/>
<projectService serviceImplementation="com.jetbrains.rider.plugins.unity.ui.vcs.MetaFilesCheckinState"/>
Expand Down
6 changes: 3 additions & 3 deletions rider/src/main/resources/messages/UnityUIBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ don.t.show.again=Don't show again


# Pre-commit checks
commitOption.check.unsaved.unity.scenes=Check unsaved Unity scenes
dialog.unsaved.message.changes.in.unity.scenes.will.not.be.included.in.commit=Unsaved changes in Unity scenes will not be included in the commit
dialog.unsaved.title.unity.scenes=Unsaved Unity Scenes
commitOption.check.unsaved.unity.state=Check unsaved Unity state
dialog.unsaved.message.changes.in.unity.state.will.not.be.included.in.commit=Unsaved changes in Unity will not be included in the commit
dialog.unsaved.title.unity.state=Unsaved Unity State
dialog.unsaved.button.cancel=Cancel
dialog.unsaved.button.commit.anyway=Commit Anyway

Expand Down
4 changes: 2 additions & 2 deletions unity/EditorPlugin/AfterUnity56/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ static EntryPoint()
if (UnityUtils.IsInBatchModeAndNotInRiderTests)
return;

PluginEntryPoint.OnModelInitialization += UnitTesting.Initialization.OnModelInitializationHandler;
PluginEntryPoint.OnModelInitialization += Initialization.OnModelInitializationHandler;
PluginEntryPoint.OnModelInitialization += Navigation.Initialization.OnModelInitializationHandler;
PluginEntryPoint.OnModelInitialization += Packages.Initialization.OnModelInitializationHandler;
AppDomain.CurrentDomain.DomainUnload += (EventHandler) ((_, __) =>
{
PluginEntryPoint.OnModelInitialization -= UnitTesting.Initialization.OnModelInitializationHandler;
PluginEntryPoint.OnModelInitialization -= Initialization.OnModelInitializationHandler;
PluginEntryPoint.OnModelInitialization -= Navigation.Initialization.OnModelInitializationHandler;
PluginEntryPoint.OnModelInitialization -= Packages.Initialization.OnModelInitializationHandler;
});
Expand Down
28 changes: 28 additions & 0 deletions unity/EditorPlugin/AfterUnity56/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace JetBrains.Rider.Unity.Editor.AfterUnity56
{
public static class EnumExtensions
{
/// <summary>
/// HasFlag implementation for older dotnet framework
/// </summary>
/// <param name="flags"></param>
/// <param name="flag"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static bool HasFlag(this Enum flags, Enum flag)
{
// check if from the same type.
if (flags.GetType() != flag.GetType())
{
throw new ArgumentException("flags and flag should be of the same type.");
}

var intFlag = Convert.ToUInt64(flag);
var intFlags = Convert.ToUInt64(flags);

return (intFlags & intFlag) == intFlag;
}
}
}
Loading