Skip to content

Commit 22ef027

Browse files
benedekhslisson
authored andcommitted
fix(mps-sync-plugin-lib): new models and modules coming from the server were not activated
1 parent a330536 commit 22ef027

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/tasks/SyncQueue.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import org.modelix.mps.sync.transformation.exceptions.ModelixToMpsSynchronizatio
2929
import org.modelix.mps.sync.transformation.exceptions.MpsToModelixSynchronizationException
3030
import org.modelix.mps.sync.transformation.exceptions.SynchronizationException
3131
import org.modelix.mps.sync.transformation.exceptions.pleaseCheckLogs
32-
import org.modelix.mps.sync.util.completeWithDefault
3332
import java.util.concurrent.CompletableFuture
3433
import java.util.concurrent.ConcurrentHashMap
3534
import java.util.concurrent.ConcurrentLinkedQueue
@@ -95,7 +94,8 @@ class SyncQueue : InjectableService {
9594
if (noTaskIsRunning || isNoneDirection || runningTaskDirectionIsTheSame) {
9695
enqueueAndFlush(task)
9796
} else {
98-
task.result.completeWithDefault()
97+
// Fail the result in this case, because the follower tasks assume that its predecessor task ran.
98+
task.result.completeExceptionally(IllegalStateException("Predecessor task was not scheduled in the SyncQueue."))
9999
}
100100
}
101101

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/transformation/modelixToMps/incremental/ModelixTreeChangeVisitor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class ModelixTreeChangeVisitor(
221221

222222
val iNode = getNode(nodeId)
223223
if (iNode.isModule()) {
224-
moduleTransformer.transformToModule(nodeId)
224+
moduleTransformer.transformToModuleAndActivate(nodeId)
225225
} else if (iNode.isModuleDependency()) {
226226
val moduleNodeId = iNode.getModule()?.nodeIdAsLong()
227227
val parentModule = nodeMap.getModule(moduleNodeId)!!
@@ -233,7 +233,7 @@ class ModelixTreeChangeVisitor(
233233
}
234234
moduleTransformer.transformModuleDependency(nodeId, parentModule)
235235
} else if (iNode.isModel()) {
236-
modelTransformer.transformToModel(nodeId)
236+
modelTransformer.transformToModelAndActivate(nodeId)
237237
} else if (iNode.isModelImport()) {
238238
modelTransformer.transformModelImport(nodeId)
239239
} else if (iNode.isSingleLanguageDependency()) {

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/transformation/modelixToMps/transformers/ModelTransformer.kt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import org.modelix.model.api.getNode
4141
import org.modelix.model.mpsadapters.MPSArea
4242
import org.modelix.model.mpsadapters.MPSLanguageRepository
4343
import org.modelix.model.mpsadapters.MPSModelImportAsNode
44-
import org.modelix.mps.sync.bindings.BindingsRegistry
44+
import org.modelix.mps.sync.IBinding
4545
import org.modelix.mps.sync.bindings.EmptyBinding
4646
import org.modelix.mps.sync.bindings.ModelBinding
4747
import org.modelix.mps.sync.modelix.util.getModel
@@ -54,6 +54,7 @@ import org.modelix.mps.sync.mps.util.createModel
5454
import org.modelix.mps.sync.mps.util.deleteDevKit
5555
import org.modelix.mps.sync.mps.util.deleteLanguage
5656
import org.modelix.mps.sync.mps.util.descriptorSuffix
57+
import org.modelix.mps.sync.tasks.ContinuableSyncTask
5758
import org.modelix.mps.sync.tasks.SyncDirection
5859
import org.modelix.mps.sync.tasks.SyncLock
5960
import org.modelix.mps.sync.transformation.cache.ModelWithModelReference
@@ -79,14 +80,19 @@ class ModelTransformer(
7980

8081
private val notifier = serviceLocator.wrappedNotifier
8182

83+
/**
84+
* The registry to store the [IBinding]s.
85+
*/
86+
private val bindingsRegistry = serviceLocator.bindingsRegistry
87+
8288
private val mpsProject = serviceLocator.mpsProject
8389
private val mpsRepository = serviceLocator.mpsRepository
8490

8591
private val nodeTransformer = NodeTransformer(branch, serviceLocator, mpsLanguageRepository)
8692

8793
private val resolvableModelImports = mutableListOf<ResolvableModelImport>()
8894

89-
fun transformToModelCompletely(nodeId: Long, branch: IBranch, bindingsRegistry: BindingsRegistry) =
95+
fun transformToModelCompletely(nodeId: Long) =
9096
transformToModel(nodeId)
9197
.continueWith(linkedSetOf(SyncLock.MODELIX_READ, SyncLock.MPS_WRITE), SyncDirection.MODELIX_TO_MPS) {
9298
val model = branch.getNode(nodeId)
@@ -115,7 +121,27 @@ class ModelTransformer(
115121
}
116122
}
117123

118-
fun transformToModel(nodeId: Long) =
124+
/**
125+
* Transforms a modelix node, identified by its [nodeId], to an [SModel] and then creates and activates its
126+
* [ModelBinding].
127+
*
128+
* @param nodeId the identifier of the modelix node that represents the [SModel].
129+
*
130+
* @return the [ContinuableSyncTask] handle to append a new sync task after this one is completed.
131+
*
132+
* @see [transformToModel]
133+
*/
134+
fun transformToModelAndActivate(nodeId: Long) =
135+
transformToModel(nodeId)
136+
.continueWith(linkedSetOf(SyncLock.MODELIX_READ, SyncLock.MPS_WRITE), SyncDirection.MODELIX_TO_MPS) {
137+
val iNode = branch.getNode(nodeId)
138+
val model = nodeMap.getModel(iNode.nodeIdAsLong()) as SModelBase
139+
val binding = ModelBinding(model, branch, serviceLocator)
140+
bindingsRegistry.addModelBinding(binding)
141+
binding.activate()
142+
}
143+
144+
private fun transformToModel(nodeId: Long) =
119145
syncQueue.enqueue(linkedSetOf(SyncLock.MODELIX_READ, SyncLock.MPS_WRITE), SyncDirection.MODELIX_TO_MPS) {
120146
val iNode = branch.getNode(nodeId)
121147
val name = iNode.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name)

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/transformation/modelixToMps/transformers/ModuleTransformer.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ModuleTransformer(
9191
val module = branch.getNode(nodeId)
9292
val modelBindingsFuture = module.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Module.models)
9393
.waitForCompletionOfEachTask(futuresWaitQueue, collectResults = true) {
94-
modelTransformer.transformToModelCompletely(it.nodeIdAsLong(), branch, bindingsRegistry)
94+
modelTransformer.transformToModelCompletely(it.nodeIdAsLong())
9595
}
9696

9797
// join the newly added model bindings with the existing bindings
@@ -126,6 +126,28 @@ class ModuleTransformer(
126126
bindings
127127
}
128128

129+
/**
130+
* Transforms a modelix node, identified by its [nodeId], to an [SModule] without transforming the contained models.
131+
* After that it creates and activates the module's [ModuleBinding].
132+
*
133+
* @param nodeId the identifier of the modelix node that represents the [SModule].
134+
* @param fetchTargetModule if true, then the target [SModule]s of the Module Dependencies (outgoing from this
135+
* source [SModule]) will be also transformed.
136+
*
137+
* @return the [ContinuableSyncTask] handle to append a new sync task after this one is completed.
138+
*
139+
* @see [transformToModule]
140+
*/
141+
fun transformToModuleAndActivate(nodeId: Long, fetchTargetModule: Boolean = false) =
142+
transformToModule(nodeId, fetchTargetModule)
143+
.continueWith(linkedSetOf(SyncLock.MODELIX_READ, SyncLock.MPS_WRITE), SyncDirection.MODELIX_TO_MPS) {
144+
val iNode = branch.getNode(nodeId)
145+
val module = nodeMap.getModule(iNode.nodeIdAsLong()) as AbstractModule
146+
val moduleBinding = ModuleBinding(module, branch, serviceLocator)
147+
bindingsRegistry.addModuleBinding(moduleBinding)
148+
moduleBinding.activate()
149+
}
150+
129151
fun transformToModule(nodeId: Long, fetchTargetModule: Boolean = false) =
130152
syncQueue.enqueue(linkedSetOf(SyncLock.MODELIX_READ, SyncLock.MPS_WRITE), SyncDirection.MODELIX_TO_MPS) {
131153
val iNode = branch.getNode(nodeId)

0 commit comments

Comments
 (0)