movatechtoday / jsonnet_pro

Other
1 stars 0 forks source link

Imported file content outdated if rendering through Jsonnet Pro #12

Closed l-ehlers closed 10 months ago

l-ehlers commented 1 year ago

We were able to reproduce the following issue quite reliably in different development environments:

When using jrsonnet or go-jsonnet as Jsonnet executable in Jsonnet Pro, imported files are imported in an outdated state when rendering through the Jsonnet Pro "Auto Preview" (examples below). This corrupted state can be fixed by executing jsonnet in the shell and then rerendering the file in the Jsonnet Pro "Auto Preview".

Since the issue can be fixed by executing jsonnet in the shell, we assume that Jsonnet Pro performs some caching or similar, which is not correctly invalidated on file changes.

BEFORE

A.jsonnet
{ example: "unchanged" }

B.jsonnet
{ importedExample: (import "A.jsonnet").example }

Rendered B.jsonnet
{ importedExample: "unchanged" }

CORRUPT STATE

A.jsonnet
{ example: "changed" } // This line has changed

B.jsonnet
{ importedExample: (import "A.jsonnet").example }

Rendered B.jsonnet
{ importedExample: "unchanged" } //  This line has NOT changed

AFTER EXECUTING JSONNET FROM THE SHELL

A.jsonnet
{ example: "changed" }

B.jsonnet
{ importedExample: (import "A.jsonnet").example }

Rendered B.jsonnet
{ importedExample: "changed" } // Now, this line has changed
movatechtoday commented 1 year ago

Hello. Thank you for posting the issue. I think you have met the following IDE built in feature -- Autosave files. It can be triggered by different events (for example, opening the terminal). If you open the terminal, files are saved and the jsonnet renderer sees the changes.

Could you confirm that you have 2 opened files at the same time, did the changes in the first file and then rendering the second file?

I think that it is possible to save all opened document before rendering and then render it. Let me see what I can do her.

movatechtoday commented 1 year ago

Also, I have question about jrsonnet. Do you use jrsonnet features that do not exist in other implementations? I mean these https://github.com/CertainLach/jrsonnet/blob/master/docs/features.md

l-ehlers commented 1 year ago

Hello @movatechtoday, thanks for your response!

I did have both A.jsonnet and B.jsonnet open at the same time. Then I have changed the contents of A.jsonnet, switched to B.jsonnet and pressed the space bar somewhere to trigger a new preview render.

You seem to be right about the autosaving (which surprises me because I thought Intellij IDEA would always autosave). I have just found the simple workaround to render correct previews: Ctrl+S before triggering a new preview rendering.

However, it would be great if this would be a built-in feature of Jsonnet Pro. Thanks in advance!

No, we are trying to avoid using implementation-specific Jsonnet features.

movatechtoday commented 10 months ago

Hello.

I have added 2 new options that affect rendering of jsonnet files. image

You can enabled these flags in the Settings -> Tools -> Jsonnet -> AutoPreviewsection

At the moment options are disabled. In the next release I am going to enable it. Testing shows the features are stable.

I would appreciate if you test it.