kieler / klighd-vscode

Eclipse Public License 2.0
8 stars 6 forks source link

Feat: Add the ability to persist data #12

Closed christoph-fricke closed 2 years ago

christoph-fricke commented 2 years ago

This PR adds the long awaited ability to persist data between reloads. The data is send to the LS during initialization under the clientDiagramOptions key (same as before).

To achieve this, a PersistenceStorage service is added to the core. An OptionsPersistence action handler handles all actions that update diagram options (render, layout, synthesis) and persists them using the new service.

Each platform provides their implementation for the service and is responsible for notifying the server about the data during initialization.

The CLI uses the localStorage to persist the data long term. A URL search param and a CLI option have been added for the user to nuke persisted data. Since localStorage depends on the origin, which is port dependent, the CLI has been switched from a random port to a series of preferred ports (falls back to a random port after 6 availability tests).

The VS Code extension uses messages to sync the data between the webview and extension. The data is stored in the workspace state, which means that it will change between opened folder. Say a user has two projects, they would use different persisted options. @NiklasRentzCAU This is up to debate and can be change easily to a global storage, because both use the Memento API. An command has been added to the extension as well, which allows the user to nuke persisted data. I think it is quite useful if one wants to return to the defaults, but it only truly applies to the LS after a reload (since the LS is only initialized on startup...).