From d3e0ebc3901cdedb404562f3a3cd4ff9b823f645 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 8 Sep 2015 11:06:46 -0400 Subject: [PATCH] [Arduino] Force reindex when changing build configs. Also fixes duplicate markers being created by the error parser. Change-Id: I02d2430df40e62d8a329bfe0ea8728e06afca059 --- .../build/ArduinoBuildConfiguration.java | 35 ++++++++++++------- .../internal/console/ArduinoErrorParser.java | 11 +++++- .../launch/ArduinoErrorMatchListener.java | 3 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java index a1b58a4dfe5..926e012982f 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java @@ -55,6 +55,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.osgi.service.prefs.BackingStoreException; @@ -148,6 +149,9 @@ public class ArduinoBuildConfiguration { IProjectDescription projectDesc = project.getDescription(); projectDesc.setActiveBuildConfig(config.getName()); project.setDescription(projectDesc, monitor); + + // Reindex - assuming for now each config has different compiler settings + CCorePlugin.getIndexManager().reindex(CoreModel.getDefault().create(project)); } public IEclipsePreferences getSettings() { @@ -534,20 +538,25 @@ public class ArduinoBuildConfiguration { } public IScannerInfo getScannerInfo(IResource resource) throws CoreException { - // what language is this resource and pick the right path; - switch (CCorePlugin.getContentType(resource.getProject(), resource.getName()).getId()) { - case CCorePlugin.CONTENT_TYPE_CXXSOURCE: - case CCorePlugin.CONTENT_TYPE_CXXHEADER: - if (cppScannerInfo == null) { - cppScannerInfo = calculateScannerInfo("recipe.cpp.o.pattern", resource); //$NON-NLS-1$ + IContentType contentType = CCorePlugin.getContentType(resource.getProject(), resource.getName()); + if (contentType != null) { + // what language is this resource and pick the right path; + switch (contentType.getId()) { + case CCorePlugin.CONTENT_TYPE_CXXSOURCE: + 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() { @@ -643,7 +652,7 @@ public class ArduinoBuildConfiguration { @Override protected String getMessage(Matcher matcher) { - return matcher.group(5); + return matcher.group(matcher.groupCount()); } @Override diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/console/ArduinoErrorParser.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/console/ArduinoErrorParser.java index 96031b72aef..643266d13dd 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/console/ArduinoErrorParser.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/console/ArduinoErrorParser.java @@ -8,6 +8,7 @@ import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; public abstract class ArduinoErrorParser extends ArduinoConsoleParser { @@ -38,13 +39,21 @@ public abstract class ArduinoErrorParser extends ArduinoConsoleParser { 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); if (matcher.matches()) { String fileName = getFileName(matcher); IFile file = buildDirectory.getFile(fileName); 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 { IMarker marker = file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, getMessage(matcher)); diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoErrorMatchListener.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoErrorMatchListener.java index 839d16f2a78..c8d0e91fcee 100644 --- a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoErrorMatchListener.java +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoErrorMatchListener.java @@ -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.ui.internal.Activator; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.ui.console.PatternMatchEvent; @@ -22,7 +23,7 @@ public class ArduinoErrorMatchListener extends ArduinoPatternMatchListener { event.getOffset() + marker.getAttribute(ArduinoErrorParser.LINK_OFFSET, 0), marker.getAttribute(ArduinoErrorParser.LINK_LENGTH, event.getLength())); } - } catch (BadLocationException e) { + } catch (BadLocationException | CoreException e) { Activator.log(e); } }