From d496b364e293842dd68b4f2e24a5a01c29c3374d Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Fri, 14 Jan 2022 17:46:18 +0100 Subject: [PATCH] ui: Compile button now creates a separate resource for each compilation. This fixes #746 as the modifications to ecore model by the code generator no longer leak into the editor's model, the diagram, or future compilation. --- .../ui/actions/CompileActionHandler.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/org.lflang.ui/src/org/lflang/ui/actions/CompileActionHandler.java b/org.lflang.ui/src/org/lflang/ui/actions/CompileActionHandler.java index 1ea9f6ee02..96155bfd69 100644 --- a/org.lflang.ui/src/org/lflang/ui/actions/CompileActionHandler.java +++ b/org.lflang.ui/src/org/lflang/ui/actions/CompileActionHandler.java @@ -41,6 +41,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.emf.common.util.URI; @@ -63,7 +64,6 @@ import org.eclipse.xtext.ui.editor.validation.MarkerIssueProcessor; import org.eclipse.xtext.ui.validation.MarkerTypeProvider; import org.eclipse.xtext.util.CancelIndicator; -import org.eclipse.xtext.util.concurrent.IUnitOfWork; import org.eclipse.xtext.validation.CheckMode; import org.eclipse.xtext.validation.IResourceValidator; import org.lflang.ui.LFUiModuleImpl; @@ -135,17 +135,14 @@ public Object execute(final ExecutionEvent event) throws ExecutionException { if (xtextEditor != null) { var xtextDocument = xtextEditor.getDocument(); if (xtextDocument != null) { - // Get editor's resource - var work = new IUnitOfWork() { - @Override - public XtextResource exec(XtextResource state) throws Exception { - return state; - } - - }; - var resource = xtextDocument.readOnly(work); - var file = (IFile) xtextEditor.getResource(); - lfFiles.add(new LFFile(resource, file, file.getProject(), xtextEditor)); + // Save editor + if (xtextEditor.isDirty()) { + xtextEditor.doSave(new NullProgressMonitor()); + } + // Load the resource of this editor based on its associated file (collect). + // This does not retrieve the model resource from the editor directly but creates a new one. + // => workaround for issue #746. + lfFiles.addAll(collect((IFile) xtextEditor.getResource())); } } } else if (selection instanceof IStructuredSelection) { // Invoked from context menu in project explorer @@ -172,11 +169,6 @@ protected IStatus run(IProgressMonitor monitor) { new Status(Status.ERROR, "org.lflang.ui", "Could not delete error markers", e), StatusManager.LOG); } - // Save editor - if (lfFile.editor != null && lfFile.editor.isDirty()) { - lfFile.editor.doSave(monitor.slice(0)); - } - try { // Validate monitor.subTask(String.format(VALIDATE_LABEL, lfFile.file.getProjectRelativePath().toString()));