finos/legend-studio

Bug: Saving models in text mode with import statement will break the project on next load

akphi opened this issue · 0 comments

akphi commented

Similar issues

  • I have searched and found no existing similar issues

How are you using Studio?

Legend Studio

Current and expected behavior

A while ago, we removed graph building from text mode, users now can save their changes directly from text mode, but due to this, sometimes, they could accidentally save text of models which depends on import statement to fully resolve paths; this is bad since we skip SectionIndex when persisting to SDLC. Previously, when we still build the graph in text-mode, the diff algo will make use of graph builder to fully resolve all the paths before saving, this is no-longer the case.

Steps to reproduce

Copy and paste the following provided text in text-mode and save, the next load the project will be broken and users will be asked to return to text-mode.

Model data

import model::*;

Class model::A {}
Class model::B extends A {}

Environment

No response

Possible solution and workaround

The possible solution is to enforce path resolution before saving in text-mode so we save entities with all paths resolved, i.e. rid ourselves of the responsibility to save import statements. I think we can follow the steps below in terms of mechanic and interaction:

  • When the users click save in text mode, first, we parse the grammar to obtain the graph data
  • If there is no section (in SectionIndex) with imports, we proceed with save per normal
  • Otherwise, we alert the users (using ActionAlert): "Import statements will not be saved, we can attempt to automatically resolve the full paths, or you can manually resolve them, remove the import statements, and try saving again" Have 2 actions: "Resolve automatically", "Resolve manually"
  • If they choose Resolve Manually nothing to be done, just close the ActionAlert
  • Otherwise, we proceed with building the graph like what we would do when switching from text-mode to form-mode and then compute the new changeset and attempt to save - while doing this, add a BlockingAlert to prevent users from making any changes/actions that might interfere with the process
  • NOTE: if at any point, the process fails, we will warn the user, "Can't automatically resolve the full paths. Please manually resolve them, remove the import statements, and try saving again". The only action here is "Resolve manually"

Contribution

  • I would like to work on the fix for this issue