1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

[Arduino] Force reindex when changing build configs.

Also fixes duplicate markers being created by the error parser.

Change-Id: I02d2430df40e62d8a329bfe0ea8728e06afca059
This commit is contained in:
Doug Schaefer 2015-09-08 11:06:46 -04:00
parent eca5073324
commit d3e0ebc390
3 changed files with 34 additions and 15 deletions

View file

@ -55,6 +55,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.BackingStoreException;
@ -148,6 +149,9 @@ public class ArduinoBuildConfiguration {
IProjectDescription projectDesc = project.getDescription(); IProjectDescription projectDesc = project.getDescription();
projectDesc.setActiveBuildConfig(config.getName()); projectDesc.setActiveBuildConfig(config.getName());
project.setDescription(projectDesc, monitor); project.setDescription(projectDesc, monitor);
// Reindex - assuming for now each config has different compiler settings
CCorePlugin.getIndexManager().reindex(CoreModel.getDefault().create(project));
} }
public IEclipsePreferences getSettings() { public IEclipsePreferences getSettings() {
@ -534,20 +538,25 @@ public class ArduinoBuildConfiguration {
} }
public IScannerInfo getScannerInfo(IResource resource) throws CoreException { public IScannerInfo getScannerInfo(IResource resource) throws CoreException {
// what language is this resource and pick the right path; IContentType contentType = CCorePlugin.getContentType(resource.getProject(), resource.getName());
switch (CCorePlugin.getContentType(resource.getProject(), resource.getName()).getId()) { if (contentType != null) {
case CCorePlugin.CONTENT_TYPE_CXXSOURCE: // what language is this resource and pick the right path;
case CCorePlugin.CONTENT_TYPE_CXXHEADER: switch (contentType.getId()) {
if (cppScannerInfo == null) { case CCorePlugin.CONTENT_TYPE_CXXSOURCE:
cppScannerInfo = calculateScannerInfo("recipe.cpp.o.pattern", resource); //$NON-NLS-1$ case CCorePlugin.CONTENT_TYPE_CXXHEADER:
if (cppScannerInfo == null) {
cppScannerInfo = calculateScannerInfo("recipe.cpp.o.pattern", resource); //$NON-NLS-1$
}
return cppScannerInfo;
default:
if (cScannerInfo == null) {
cScannerInfo = calculateScannerInfo("recipe.c.o.pattern", resource); //$NON-NLS-1$
}
return cScannerInfo;
} }
return cppScannerInfo;
default:
if (cScannerInfo == null) {
cScannerInfo = calculateScannerInfo("recipe.c.o.pattern", resource); //$NON-NLS-1$
}
return cScannerInfo;
} }
// use the cpp scanner info if all else fails
return cppScannerInfo;
} }
public void clearScannerInfoCache() { public void clearScannerInfoCache() {
@ -643,7 +652,7 @@ public class ArduinoBuildConfiguration {
@Override @Override
protected String getMessage(Matcher matcher) { protected String getMessage(Matcher matcher) {
return matcher.group(5); return matcher.group(matcher.groupCount());
} }
@Override @Override

View file

@ -8,6 +8,7 @@ import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
public abstract class ArduinoErrorParser extends ArduinoConsoleParser { public abstract class ArduinoErrorParser extends ArduinoConsoleParser {
@ -38,13 +39,21 @@ public abstract class ArduinoErrorParser extends ArduinoConsoleParser {
protected abstract int getLinkLength(Matcher matcher); protected abstract int getLinkLength(Matcher matcher);
public IMarker generateMarker(IFolder buildDirectory, String text) { public IMarker generateMarker(IFolder buildDirectory, String text) throws CoreException {
Matcher matcher = errorPattern.matcher(text); Matcher matcher = errorPattern.matcher(text);
if (matcher.matches()) { if (matcher.matches()) {
String fileName = getFileName(matcher); String fileName = getFileName(matcher);
IFile file = buildDirectory.getFile(fileName); IFile file = buildDirectory.getFile(fileName);
if (file.exists()) { if (file.exists()) {
for (IMarker marker : file.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false,
IResource.DEPTH_ZERO)) {
if (marker.getAttribute(IMarker.SEVERITY, -1) == getSeverity(matcher)
&& marker.getAttribute(IMarker.LINE_NUMBER, -1) == getLineNumber(matcher)
&& marker.getAttribute(IMarker.MESSAGE, "").equals(getMessage(matcher))) { //$NON-NLS-1$
return marker;
}
}
try { try {
IMarker marker = file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER); IMarker marker = file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
marker.setAttribute(IMarker.MESSAGE, getMessage(matcher)); marker.setAttribute(IMarker.MESSAGE, getMessage(matcher));

View file

@ -3,6 +3,7 @@ package org.eclipse.cdt.arduino.ui.internal.launch;
import org.eclipse.cdt.arduino.core.internal.console.ArduinoErrorParser; import org.eclipse.cdt.arduino.core.internal.console.ArduinoErrorParser;
import org.eclipse.cdt.arduino.ui.internal.Activator; import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.ui.console.PatternMatchEvent; import org.eclipse.ui.console.PatternMatchEvent;
@ -22,7 +23,7 @@ public class ArduinoErrorMatchListener extends ArduinoPatternMatchListener {
event.getOffset() + marker.getAttribute(ArduinoErrorParser.LINK_OFFSET, 0), event.getOffset() + marker.getAttribute(ArduinoErrorParser.LINK_OFFSET, 0),
marker.getAttribute(ArduinoErrorParser.LINK_LENGTH, event.getLength())); marker.getAttribute(ArduinoErrorParser.LINK_LENGTH, event.getLength()));
} }
} catch (BadLocationException e) { } catch (BadLocationException | CoreException e) {
Activator.log(e); Activator.log(e);
} }
} }