Opened 3 years ago

Closed 3 years ago

#6248 closed defect (fixed)

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

Reported by: casella Owned by: adeas31
Priority: blocker Milestone: 1.17.0
Component: OMEdit Version: 1.16.0
Keywords: Cc: Andrea.Bartolini, 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 casella 3 years ago.

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by casella

comment:1 follow-up: Changed 3 years ago by Andrea.Bartolini

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.

comment:2 in reply to: ↑ 1 Changed 3 years ago by casella

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 follow-up: Changed 3 years ago by phannebohm

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

comment:4 in reply to: ↑ 3 Changed 3 years ago by casella

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 Changed 3 years ago by adeas31

comment:6 Changed 3 years ago by casella

  • Resolution set to fixed
  • Status changed from new to closed

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.