diff --git a/php.editor/src/org/netbeans/modules/php/editor/nav/OccurrencesFinderImpl.java b/php.editor/src/org/netbeans/modules/php/editor/nav/OccurrencesFinderImpl.java --- a/php.editor/src/org/netbeans/modules/php/editor/nav/OccurrencesFinderImpl.java +++ b/php.editor/src/org/netbeans/modules/php/editor/nav/OccurrencesFinderImpl.java @@ -49,6 +49,9 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.concurrent.CountDownLatch; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.prefs.Preferences; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; @@ -70,6 +73,7 @@ import org.netbeans.modules.php.editor.model.OccurencesSupport; import org.netbeans.modules.php.editor.options.MarkOccurencesSettings; import org.netbeans.modules.php.editor.parser.PHPParseResult; +import org.openide.util.RequestProcessor; /** * @@ -78,9 +82,12 @@ * @author Radek Matous */ public class OccurrencesFinderImpl extends OccurrencesFinder { + private static final RequestProcessor RP = new RequestProcessor(OccurrencesFinderImpl.class); + private static final Logger LOGGER = Logger.getLogger(OccurrencesFinderImpl.class.getName()); private Map range2Attribs; private int caretPosition; private volatile boolean cancelled; + private CountDownLatch latch = new CountDownLatch(1); @Override public void setCaretPosition(int position) { @@ -89,6 +96,11 @@ @Override public Map getOccurrences() { + try { + latch.await(); + } catch (InterruptedException ex) { + LOGGER.log(Level.FINE, null, ex); + } return range2Attribs; } @@ -98,32 +110,40 @@ } @Override - public void run(Result result, SchedulerEvent event) { - //remove the last occurrences - the CSL caches the last found occurences for us - range2Attribs = null; + public void run(final Result result, SchedulerEvent event) { + latch = new CountDownLatch(1); + RP.post(new Runnable() { - if (cancelled) { - cancelled = false; - return; - } + @Override + public void run() { + //remove the last occurrences - the CSL caches the last found occurences for us + range2Attribs = null; - Preferences node = MarkOccurencesSettings.getCurrentNode(); - Map localRange2Attribs = new HashMap(); - if (node.getBoolean(MarkOccurencesSettings.ON_OFF, true)) { - for (OffsetRange r : compute((ParserResult) result, caretPosition)) { - localRange2Attribs.put(r, ColoringAttributes.MARK_OCCURRENCES); + if (cancelled) { + cancelled = false; + return; + } + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + Map localRange2Attribs = new HashMap(); + if (node.getBoolean(MarkOccurencesSettings.ON_OFF, true)) { + for (OffsetRange r : compute((ParserResult) result, caretPosition)) { + localRange2Attribs.put(r, ColoringAttributes.MARK_OCCURRENCES); + } + } + + if (cancelled) { + cancelled = false; + return; + } + + if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true) || localRange2Attribs.size() > 0) { + //store the occurrences if not empty, return null in getOccurrences() otherwise + range2Attribs = localRange2Attribs; + } + latch.countDown(); } - } - - if (cancelled) { - cancelled = false; - return; - } - - if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true) || localRange2Attribs.size() > 0) { - //store the occurrences if not empty, return null in getOccurrences() otherwise - range2Attribs = localRange2Attribs; - } + }); } static Collection compute(final ParserResult parameter, final int offset) {