Skip to content

Commit d4335c9

Browse files
committed
feat(mps-sync-plugin): allow to update binding for switching a branch
1 parent 464d578 commit d4335c9

File tree

4 files changed

+472
-0
lines changed

4 files changed

+472
-0
lines changed

mps-sync-plugin3/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
testImplementation(libs.kotlin.coroutines.test)
5656
testImplementation(libs.logback.classic)
5757
testImplementation(kotlin("test"))
58+
testImplementation(libs.mockk)
5859
testImplementation(project(":authorization"), excludeMPSLibraries)
5960
testImplementation(project(":model-server"), excludeMPSLibraries)
6061
testImplementation(libs.ktor.client.cio, excludeMPSLibraries)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface IModelSyncService {
3636
fun getServerConnections(): List<IServerConnection>
3737
fun getUsedServerConnections(): List<IServerConnection>
3838
fun getBindings(): List<IBinding>
39+
fun updateBinding(oldBranchRef: BranchReference, newBranchRef: BranchReference, resetLocalState: Boolean = false)
3940
}
4041

4142
data class ModelServerConnectionProperties(

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ class ModelSyncService(val project: Project) :
8585
return loadedState.bindings.keys.map { Binding(it) }
8686
}
8787

88+
@Synchronized
89+
override fun updateBinding(oldBranchRef: BranchReference, newBranchRef: BranchReference, resetLocalState: Boolean) {
90+
updateState {
91+
it.bindings.none { it.key.branchRef == oldBranchRef } &&
92+
throw IllegalArgumentException("No binding for $oldBranchRef")
93+
94+
it.copy(
95+
bindings = it.bindings.mapKeys { (key, _) ->
96+
if (key.branchRef == oldBranchRef) {
97+
key.copy(branchRef = newBranchRef)
98+
} else {
99+
key
100+
}
101+
}.mapValues { (key, value) ->
102+
if (resetLocalState && key.branchRef == newBranchRef) {
103+
value.copy(versionHash = null)
104+
} else {
105+
value
106+
}
107+
},
108+
)
109+
}
110+
}
111+
88112
@Synchronized
89113
fun loadState(newState: SyncServiceState) {
90114
val oldState: SyncServiceState = this.loadedState

0 commit comments

Comments
 (0)