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

[error reporting] Correct bugs reported on Epoch #1038

Merged
merged 3 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 19 additions & 11 deletions org.lflang/src/org/lflang/generator/EclipseErrorReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.diagnostics.Severity;
Expand Down Expand Up @@ -109,21 +111,12 @@ private String report(String message, Severity severity, Integer line, Path file
if (line == null || file == null)
System.err.println(header + ": " + message);
else
System.err.println(header + ": " + file + " line " + line
+ "\n" + message);

// Determine the iResource to report on
IResource iResource = file != null ? FileUtil.getIResource(file) : null;
// if we couldn't find an iResource (for whatever reason), then use the
// iResource of the main file
if (iResource == null) {
iResource = fileConfig.iResource;
}
System.err.println(header + ": " + file + " line " + line + "\n" + message);

// 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.html
try {
IMarker marker = iResource.createMarker(IMarker.PROBLEM);
IMarker marker = bestEffortGetIResource(file).createMarker(IMarker.PROBLEM);
petervdonovan marked this conversation as resolved.
Show resolved Hide resolved

// Mark as LF compilation marker to be able to remove marker at next compile run
marker.setAttribute(this.getClass().getName(), true);
Expand Down Expand Up @@ -153,6 +146,21 @@ private String report(String message, Severity severity, Integer line, Path file
return header + ": " + message;
}

private IResource bestEffortGetIResource(Path path) {
IResource iResource = null;
if (path != null) {
iResource = FileUtil.getIResource(path);
if (iResource == null) {
// This operation is risky and may fail with a IllegalStateException or NPE.
petervdonovan marked this conversation as resolved.
Show resolved Hide resolved
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
iResource = workspaceRoot.findMember(org.eclipse.core.runtime.Path.fromOSString(
path.subpath(1, path.getNameCount()).toString()
));
}
}
return (iResource == null) ? fileConfig.iResource : iResource;
}

/**
* Report an error.
*
Expand Down
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/c/CGenerator.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -3469,7 +3469,7 @@ class CGenerator extends GeneratorBase {
// The third match is a character position within the line.
// The fourth match will be the error message.
static final Pattern compileErrorPattern = Pattern.compile(
"^(file:/(?<path>.*)):(?<line>[0-9]+):(?<column>[0-9]+):(?<message>.*)$"
"^(file:(?<path>.*)):(?<line>[0-9]+):(?<column>[0-9]+):(?<message>.*)$"
);

/** Given a line of text from the output of a compiler, return
Expand Down