com.intellij.openapi.components.SerializablePersistentStateComponent#loadState got marked here as @Internal which cuts off the ability to copy the settings into a State flow for broadcast, same use case as these examples from the community repo:
Can this be undone for loadState since it is the only way to be notified that new state was loaded from disk?
It looks to me that it should have been marked as OverrideOnly instead? (Maybe an enhancement to OverrideOnly could be @OverrideOnly(superRequired=true) or something along those lines if that was the intention of marking it @Internal)
SerializablePersistentStateComponent as a concept has quite some issues in the current implementation. Currently, it is under refactoring, hence the @Internal.
Please track https://youtrack.jetbrains.com/issue/IJPL-188400, where the majority of issues is discussed.
Why do you need to track the disk loading specifically?
We have been using the class for about a year now which is why I have my data classes defined in the form of:
data class State(
@field:Property val a: Boolean = true,
@field:Property val b: String? = null,
@field:Property val c: String? = null
)
Why do you need to track the disk loading specifically?
I don’t per se, but loadState is the only way to load the saved settings into a StateFlow, our code looks nearly verbatim to GitLabPersistentAccounts.kt, but with more fields
var a: String?
get() = state.a
set(value) {
updateStateAndEmit {
it.copy(a = value)
}
}
private fun updateStateAndEmit(updateFunction: (currentState: State) -> State) {
updateState(updateFunction)
stateFlow.value = state
}
override fun loadState(state: State) {
super.loadState(state)
stateFlow.value = state
}
@robert.novotny What is our path forward, we currently have a release in flight that looks to be blocked by this. Do we need to ask for an exception?
We will refactor off of this class and onto the parent class where update is still safe to override and use a StateFlow to hold the state and use StateFlow<T>.update to achieve the same atomic updates as updateStateAndEmit