Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eclipse error reporting #995

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions org.lflang/src/org/lflang/FileConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Consumer;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
Expand Down Expand Up @@ -66,6 +67,16 @@ public class FileConfig {
*/
public final Resource resource;

/**
* If running in an Eclipse IDE, the iResource refers to the
* IFile representing the Lingua Franca program.
* This is the XText view of the file, which is distinct
* from the Eclipse eCore view of the file and the OS view of the file.
*
* This is null if running outside an Eclipse IDE.
*/
public final IResource iResource;

/**
* The full path to the file containing the .lf file including the
* full filename with the .lf extension.
Expand Down Expand Up @@ -138,6 +149,8 @@ public FileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchica

Path binRoot = outPath.resolve(DEFAULT_BIN_DIR);
this.binPath = useHierarchicalBin ? binRoot.resolve(getSubPkgPath(srcPath)) : binRoot;

this.iResource = FileUtil.getIResource(resource);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions org.lflang/src/org/lflang/generator/EclipseErrorReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.validation.EObjectDiagnosticImpl;

import org.lflang.ErrorReporter;
import org.lflang.FileConfig;
import org.lflang.util.FileUtil;
Expand Down Expand Up @@ -113,10 +114,7 @@ private String report(String message, Severity severity, Integer line, Path file

// Create a marker in the IDE for the error.
// See: https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_markers.htm
final IResource iResource = file != null
? FileUtil.getIResource(file)
: FileUtil.getIResource(fileConfig.resource);

IResource iResource = file != null ? FileUtil.getIResource(file) : fileConfig.iResource;
try {
IMarker marker = iResource.createMarker(IMarker.PROBLEM);

Expand Down
21 changes: 13 additions & 8 deletions org.lflang/src/org/lflang/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ public static void deleteDirectory(Path dir) throws IOException {
* Get the iResource corresponding to the provided resource if it can be
* found.
*/
public static IResource getIResource(Resource r) {
return getIResource(java.net.URI.create(r.getURI().toString()));
public static IResource getIResource(Resource r) throws IOException {
return getIResource(FileUtil.toPath(r).toFile().toURI());
}

/**
Expand All @@ -371,20 +371,25 @@ public static IResource getIResource(Path path) {
/**
* Get the specified uri as an Eclipse IResource or null if it is not found.
*
* Also returns null if this is not called from within a running Eclipse instance.
*
* @param uri A java.net.uri of the form "file://path".
*/
public static IResource getIResource(java.net.URI uri) {
IResource resource = null;
// For some peculiar reason known only to Eclipse developers,
// the resource cannot be used directly but has to be converted
// a resource relative to the workspace root.
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
try {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

IFile[] files = workspaceRoot.findFilesForLocationURI(uri);
if (files != null && files.length > 0 && files[0] != null) {
resource = files[0];
IFile[] files = workspaceRoot.findFilesForLocationURI(uri);
if (files != null && files.length > 0 && files[0] != null) {
return files[0];
}
} catch (IllegalStateException e) {
// We are outside of Eclipse.
}
return resource;
return null;
}

/**
Expand Down