Opened 4 years ago

Closed 4 years ago

#6248 closed defect (fixed)

Syntactically wrong modifications are lost when saving other models on the same file

Reported by: Francesco Casella Owned by: Adeel Asghar
Priority: blocker Milestone: 1.17.0
Component: OMEdit Version: 1.16.0
Keywords: Cc: Andrea Bartolini, massimo ceraolo, simone1.bosotti@…, matteoluigi.depascali@…, paolo.curatolo@…

Description

Steps to reproduce:

  • load package P
  • open model M1
  • open model M2
  • add Real x = 1 without semicolon to model M2
  • switch to M1
  • change x = 5 into x = 6
  • save M1
  • switch to M2
  • the incomplete equation Real x = 1 is gone

Obviously this happens because OMC needs to save P.mo and cannot do so with syntactically invalid code in M2. However, if just spent 30 minutes working on M2, such a behaviour can be surprising, and possibly a bit annoying.

It is OK (and in fact quite desirable) that one can switch to other tabs from a syntactically incomplete tab, e.g. to look for component or type names. What is not ok is that syntactically incorrect or incomplete code is silently discarded when saving the file it would belong to.

Proposal: when saving a file that involves a tab with code that cannot be parsed. open a dialog with the following error message "Tab XXX contains invalid Modelica code. This prevents saving yyy.mo" and three buttons:

  1. Fix errors manually (-> brings Tab XXX to the foreground)
  2. Discard changes in Tab XXX and save (-> current behaviour)
  3. Cancel

If there are multiple tabs with problems, show this dialog for the first one, and then when trying to save again show the next one and so forth.

Attachments (1)

P.mo (88 bytes ) - added by Francesco Casella 4 years ago.

Download all attachments as: .zip

Change History (7)

by Francesco Casella, 4 years ago

Attachment: P.mo added

comment:1 by Andrea Bartolini, 4 years ago

My opinion is that also the wrong code should be saved, if the user ask to do that...

Moreover, the user should be able to open other models also if the currently open contains wrong code... I spend a lot of time in commment/uncomment wrong code when I need to open other models before to complete the current one...

The IDE shall help the user, not constrain it.

My proposal is to always save the code and always allow the open or switch to other models.
If wrong code is present the parser simply stop operations and a warning is given. The other views will be left empty or filled with a red crossed box.

in reply to:  1 comment:2 by Francesco Casella, 4 years ago

Replying to Andrea.Bartolini:

My opinion is that also the wrong code should be saved, if the user ask to do that...

Sure, though this could be tricky if OMC cannot parse it.

Moreover, the user should be able to open other models also if the currently open contains wrong code... I spend a lot of time in commment/uncomment wrong code when I need to open other models before to complete the current one...

Absolutely. That's possible today and it should stay so.

The IDE shall help the user, not constrain it.

My proposal is to always save the code

Not sure that this is always a good idea. I any case, it may be technically difficult

and always allow the open or switch to other models.

Yes.

If wrong code is present the parser simply stop operations and a warning is given. The other views will be left empty or filled with a red crossed box.

The problem is (as I understand) that OMC can only save code that has been successfully parsed.

comment:3 by Philip Hannebohm, 4 years ago

Possible duplicate of #6162, where even correct code is lost.

in reply to:  3 comment:4 by Francesco Casella, 4 years ago

Replying to phannebohm:

Possible duplicate of #6162, where even correct code is lost.

Sure. But I'll keep this open, to make sure that when #6162 is fixed, this one also is.

comment:5 by Adeel Asghar, 4 years ago

comment:6 by Francesco Casella, 4 years ago

Resolution: fixed
Status: newclosed

At least now there is no possibility of inadvertently losing some code.

The drawback is that you can't switch to other tabs until you either fix your code to be valid, or decide to lose your last modification. But I guess overall the situation is improved compared to the previous status. This drawback could be fixed when we enable the possibility of saving incomplete or incorrect code, but that's another story.

Note: See TracTickets for help on using tickets.