From ba2cb8f3e6b5ab37ee55cd24f294836b7960adad Mon Sep 17 00:00:00 2001 From: Jos Warmer Date: Thu, 19 Sep 2024 14:46:25 +0200 Subject: [PATCH] Clear all caches when opening a new model, otherwise nodes with the same id in different models will interfere --- .../core-svelte/src/lib/components/FreonComponent.svelte | 6 +++--- packages/core/src/editor/FreEditor.ts | 2 +- .../core/src/editor/projections/FreProjectionHandler.ts | 7 +++++++ packages/core/src/environment/FreEnvironment.ts | 3 ++- packages/core/src/environment/FreLanguageEnvironment.ts | 1 + packages/core/src/storage/InMemoryModel.ts | 3 +++ .../languagedef/generator/templates/EnvironmentTemplate.ts | 2 ++ packages/webapp-lib/src/lib/language/EditorState.ts | 4 +++- 8 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/core-svelte/src/lib/components/FreonComponent.svelte b/packages/core-svelte/src/lib/components/FreonComponent.svelte index 69072f004..295dbf271 100644 --- a/packages/core-svelte/src/lib/components/FreonComponent.svelte +++ b/packages/core-svelte/src/lib/components/FreonComponent.svelte @@ -14,8 +14,8 @@ ARROW_LEFT, DELETE, ENTER, - ARROW_RIGHT, isNullOrUndefined, isTableRowBox, isElementBox, - } from "@freon4dsl/core"; + ARROW_RIGHT, isNullOrUndefined, isTableRowBox, isElementBox + } from "@freon4dsl/core" import RenderComponent from "./RenderComponent.svelte"; import ContextMenu from "./ContextMenu.svelte"; import { afterUpdate, onMount, tick } from "svelte"; @@ -161,7 +161,7 @@ const refreshRootBox = (why?: string) => { rootBox = editor.rootBox; - LOGGER.log("REFRESH " + why + " ==================> FreonComponent with rootbox " + rootBox?.id); + LOGGER.log("REFRESH " + why + " ==================> FreonComponent with rootbox " + rootBox?.id + " unit " + (!!(rootBox?.node) ? rootBox.node["name"] : "undefined")); }; refreshRootBox("Initialize FreonComponent"); diff --git a/packages/core/src/editor/FreEditor.ts b/packages/core/src/editor/FreEditor.ts index b4e4f4093..e801b6963 100644 --- a/packages/core/src/editor/FreEditor.ts +++ b/packages/core/src/editor/FreEditor.ts @@ -86,7 +86,7 @@ export class FreEditor { } auto = () => { - // console.log("CALCULATE NEW ROOTBOX rootelement is " + this?.rootElement?.freLanguageConcept()); + LOGGER.log("CALCULATE NEW ROOTBOX rootelement is " + this?.rootElement?.freLanguageConcept() + " name " + (!!this.rootElement ? this.rootElement["name"] : "undefined")); if (this.rootElement !== null) { this._rootBox = this.projection.getBox(this.rootElement); this.rootBoxChanged(); diff --git a/packages/core/src/editor/projections/FreProjectionHandler.ts b/packages/core/src/editor/projections/FreProjectionHandler.ts index 856767993..5a1b2295b 100644 --- a/packages/core/src/editor/projections/FreProjectionHandler.ts +++ b/packages/core/src/editor/projections/FreProjectionHandler.ts @@ -58,6 +58,13 @@ export class FreProjectionHandler { }); } + /** + * Clears the element provider map, needed whenever a new model is opened + */ + clear(): void { + this.elementToProvider.clear() + } + /////////// The main methods /////////// /** diff --git a/packages/core/src/environment/FreEnvironment.ts b/packages/core/src/environment/FreEnvironment.ts index 93dbda612..823561e7b 100644 --- a/packages/core/src/environment/FreEnvironment.ts +++ b/packages/core/src/environment/FreEnvironment.ts @@ -1,4 +1,4 @@ -import { FreEditor } from "../editor"; +import { FreEditor, FreProjectionHandler } from "../editor" import { FreInterpreter } from "../interpreter"; import { FreValidator } from "../validator"; import { FreScoperComposite } from "../scoper"; @@ -21,6 +21,7 @@ export interface FreEnvironment { writer: FreWriter; reader: FreReader; interpreter: FreInterpreter; + projectionHandler: FreProjectionHandler; languageName: string; fileExtensions: Map; diff --git a/packages/core/src/environment/FreLanguageEnvironment.ts b/packages/core/src/environment/FreLanguageEnvironment.ts index ff268768a..ab345a7fa 100644 --- a/packages/core/src/environment/FreLanguageEnvironment.ts +++ b/packages/core/src/environment/FreLanguageEnvironment.ts @@ -36,6 +36,7 @@ export class FreLanguageEnvironment implements FreEnvironment { public validator: FreValidator; public writer: FreWriter; public interpreter: FreInterpreter; + public projectionHandler: FreProjectionHandler; // @ts-ignore // function needs to be implemented because it is part of the interface FreEnvironment diff --git a/packages/core/src/storage/InMemoryModel.ts b/packages/core/src/storage/InMemoryModel.ts index ba032197e..c3a1e43d2 100644 --- a/packages/core/src/storage/InMemoryModel.ts +++ b/packages/core/src/storage/InMemoryModel.ts @@ -30,6 +30,7 @@ export class InMemoryModel { * @param name */ async createModel(name: string): Promise { + LOGGER.log(`createModel ${name}`) this.__model = this.languageEnvironment.newModel(name); await this.server.createModel(name); this.currentModelChanged(); @@ -79,6 +80,7 @@ export class InMemoryModel { * @param unitConcept */ async createUnit(name: string, unitConcept: string): Promise { + LOGGER.log(`createUnit ${name} of type ${unitConcept}`) const newUnit = this.model.newUnit(unitConcept); newUnit.name = name; await this.server.createModelUnit(this.model.name, newUnit); @@ -110,6 +112,7 @@ export class InMemoryModel { * @param unit */ async addUnit(unit: FreModelUnit): Promise { + LOGGER.log(`addUnit ${unit?.name}`) this.model.addUnit(unit); await this.saveUnit(unit); this.currentModelChanged(); diff --git a/packages/meta/src/languagedef/generator/templates/EnvironmentTemplate.ts b/packages/meta/src/languagedef/generator/templates/EnvironmentTemplate.ts index 04543a5da..4724b7360 100644 --- a/packages/meta/src/languagedef/generator/templates/EnvironmentTemplate.ts +++ b/packages/meta/src/languagedef/generator/templates/EnvironmentTemplate.ts @@ -63,6 +63,7 @@ export class EnvironmentTemplate { initializeEditorDef(); initializeScoperDef(this.scoper); initializeTypers(this.typer); + this.projectionHandler = myComposite; } /** @@ -84,6 +85,7 @@ export class EnvironmentTemplate { writer: ${Names.FreWriter} = new ${Names.writer(language)}(); reader: ${Names.FreReader} = new ${Names.reader(language)}(); interpreter: ${Names.FreInterpreter} = new ${Names.interpreterName(language)}; + projectionHandler: FreProjectionHandler; languageName: string = "${language.name}"; fileExtensions: Map = new Map([ ${language.modelConcept.unitTypes().map((unit) => `["${Names.classifier(unit)}", "${unit.fileExtension}"]`)} diff --git a/packages/webapp-lib/src/lib/language/EditorState.ts b/packages/webapp-lib/src/lib/language/EditorState.ts index e9c2dd7f1..9e4739e18 100644 --- a/packages/webapp-lib/src/lib/language/EditorState.ts +++ b/packages/webapp-lib/src/lib/language/EditorState.ts @@ -1,5 +1,5 @@ // This file contains all methods to connect the webapp to the Freon generated language editorEnvironment and to the server that stores the models -import { FreError, FreErrorSeverity, FreLogger, InMemoryModel } from "@freon4dsl/core"; +import { BoxFactory, FreError, FreErrorSeverity, FreLogger, InMemoryModel } from "@freon4dsl/core" import type { FreEnvironment, FreNode, @@ -104,6 +104,8 @@ export class EditorState { first = false; } } + BoxFactory.clearCaches() + this.langEnv.projectionHandler.clear() EditorState.getInstance().showUnitAndErrors(this.currentUnit); } else { editorProgressShown.set(false);