Skip to content

Commit 6a3fd4c

Browse files
committed
fix(mps-sync-plugin): status stopped updating after an exception
1 parent f59c1d2 commit 6a3fd4c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/BindingWorker.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class BindingWorker(
7979
invalidatingListener = null
8080
}
8181

82-
private fun ModelSynchronizer.executeSync() {
82+
private fun ModelSynchronizer.synchronizeAndStoreInstance() {
8383
try {
8484
activeSynchronizer = this
8585
synchronize()
@@ -94,10 +94,17 @@ class BindingWorker(
9494
val current = synchronizer.getCurrentSyncStack()
9595
val previous = previousSyncStack
9696
previousSyncStack = current
97+
98+
// The user should just have enough details to understand where the sync is spending its time.
9799
val firstChange = current.zip(previous).indexOfFirst { it.first != it.second }
98-
val busyPath = current.take(firstChange + 1)
99-
return busyPath.joinToString(" > ") {
100-
it.getName() ?: it.tryGetConcept()?.getShortName() ?: it.getNodeReference().serialize()
100+
val path = current.take(firstChange + 1).drop(1)
101+
102+
return path.joinToString(" > ") { node ->
103+
runCatching { node.getName() }.getOrNull()?.takeIf { it.isNotEmpty() }
104+
?: runCatching { node.tryGetConcept()?.getShortName() }.getOrNull()?.takeIf { it.isNotEmpty() }
105+
?: runCatching { node.getNodeReference().serialize() }.getOrNull()
106+
?: runCatching { node.toString() }.getOrNull()
107+
?: (node::class.java.simpleName + "@" + System.identityHashCode(node))
101108
}
102109
}
103110

@@ -279,7 +286,7 @@ class BindingWorker(
279286
if (!continueOnError()) throw it
280287
getMPSListener().synchronizationErrorHappened()
281288
},
282-
).executeSync()
289+
).synchronizeAndStoreInstance()
283290
}
284291
}
285292
}
@@ -340,7 +347,7 @@ class BindingWorker(
340347
sourceMask = MPSProjectSyncMask(listOf(mpsProject), true),
341348
targetMask = MPSProjectSyncMask(listOf(mpsProject), false),
342349
onException = { if (!continueOnError()) throw it },
343-
).executeSync()
350+
).synchronizeAndStoreInstance()
344351
}
345352
}
346353
}

mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ui/ModelSyncStatusWidget.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ class ModelSyncStatusWidget(val project: Project) : CustomStatusBarWidget, Statu
4141
companion object {
4242
const val ID = "ModelixSyncStatus"
4343
val ICON = IconManager.getInstance().getIcon("org/modelix/mps/sync3/modelix16.svg", this::class.java)
44+
private val LOG = mu.KotlinLogging.logger { }
4445
}
4546

4647
private val component: JLabel = JLabel("", ICON, JLabel.LEFT)
4748
private val timer = EdtExecutorService.getScheduledExecutorInstance()
48-
.scheduleWithFixedDelay({ updateComponent() }, 1000, 500, TimeUnit.MILLISECONDS)
49+
.scheduleWithFixedDelay({
50+
try {
51+
updateComponent()
52+
} catch (ex: Throwable) {
53+
LOG.error(ex) { "Widget update failed" }
54+
}
55+
}, 1000, 500, TimeUnit.MILLISECONDS)
4956
private var disposed = false
5057
private var highlighted = false
5158

0 commit comments

Comments
 (0)