Add import field to metadata to satisfy older versions (#11797)

Fixes #11742

I was [wrong](https://github.com/enso-org/enso/issues/11742#issuecomment-2514109015) - not the _new_ fields make metadata broken for older versions, but removing an _old_ field.

This PR bring it back, which solves the issue - for a while.
This commit is contained in:
Adam Obuchowicz 2024-12-06 15:47:02 +01:00 committed by GitHub
parent c284bcb854
commit c410311b15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -74,7 +74,11 @@ export function applyDocumentUpdates(
if (codeChanged || idsChanged || metadataChanged) {
// Update the metadata object.
// Depth-first key order keeps diffs small.
newMetadata = { node: {}, widget: {} }
newMetadata = {
node: {},
widget: {},
import: {}, // "import" is required by older versions (even though they don't use it)
}
root.visitRecursive(ast => {
let pos = ast.nodeMetadata.get('position')
const vis = ast.nodeMetadata.get('visualization')

View File

@ -350,7 +350,7 @@ class ModulePersistence extends ObservableV2<{ removed: () => void }> {
// @ts-expect-error This is SAFE. `this.state` is only `readonly` to ensure that
// this is the only place where it is mutated.
this.state = state
if (state === LsSyncState.Synchronized) this.trySyncRemoveUpdates()
if (state === LsSyncState.Synchronized) this.trySyncRemoteUpdates()
} else {
throw new Error('LsSync disposed')
}
@ -450,10 +450,10 @@ class ModulePersistence extends ObservableV2<{ removed: () => void }> {
} else {
this.updateToApply = update
}
this.trySyncRemoveUpdates()
this.trySyncRemoteUpdates()
}
trySyncRemoveUpdates() {
trySyncRemoteUpdates() {
if (this.updateToApply == null) return
// apply updates to the ls-representation doc if we are already in sync with the LS.
if (!this.inState(LsSyncState.Synchronized)) return