Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAnton Leherbauer2008-03-11 15:15:47 +0000
committerAnton Leherbauer2008-03-11 15:15:47 +0000
commit3b9d0a9587aa9cef01102643ea2eef5c04183d81 (patch)
tree734b6652b2a2b0b853c1d7186e766ea6cb5c5e70 /core
parent3320c11eaec198eb8cc2dba771aa097b77b6da6c (diff)
downloadorg.eclipse.cdt-3b9d0a9587aa9cef01102643ea2eef5c04183d81.tar.gz
org.eclipse.cdt-3b9d0a9587aa9cef01102643ea2eef5c04183d81.tar.xz
org.eclipse.cdt-3b9d0a9587aa9cef01102643ea2eef5c04183d81.zip
Fix for 222069: CSourceHover popup doesn't work after changing file
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java10
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java55
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java36
5 files changed, 83 insertions, 30 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java
index fd0de4832fa..d540343d705 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Anton Leherbauer (Wind River Systems) - initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@@ -40,7 +40,7 @@ public class ASTCache {
/** Full parse mode (no PDOM) */
public static int PARSE_MODE_FULL= ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
/** Fast parse mode (use PDOM) */
- public static int PARSE_MODE_FAST= ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
+ public static int PARSE_MODE_FAST= ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
/**
* Do something with an AST.
@@ -71,7 +71,7 @@ public class ASTCache {
* write access afterwards.
*/
private long fLastWriteOnIndex;
- /** Inidicates whether the AST is currenty being computed */
+ /** Indicates whether the AST is currently being computed */
private boolean fIsReconciling;
/**
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java
index c62a08c685a..47d0390a405 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2007 QNX Software Systems and others.
+ * Copyright (c) 2002, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -27,6 +27,10 @@ public final class CHoverMessages extends NLS {
public static String CMacroExpansionControl_title_fullyExpanded;
public static String CMacroExpansionControl_title_macroExpansion;
public static String CMacroExpansionControl_title_original;
+
+ public static String CMacroExpansionInput_jobTitle;
+
+ public static String CSourceHover_jobTitle;
static {
NLS.initializeMessages(BUNDLE_NAME, CHoverMessages.class);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties
index 65fbc30671e..b0b833490c5 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2007 IBM Corporation and others.
+# Copyright (c) 2000, 2008 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -15,3 +15,7 @@ CMacroExpansionControl_title_expansion=Expansion \#{0} of {1}
CMacroExpansionControl_title_fullyExpanded=Fully Expanded
CMacroExpansionControl_title_macroExpansion=Macro Expansion
CMacroExpansionControl_title_original=Original
+
+CMacroExpansionInput_jobTitle= Computing Macro Expansion
+
+CSourceHover_jobTitle= Computing Source
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java
index f19649659d6..04af1fcf38d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java
@@ -17,8 +17,9 @@ import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -48,7 +49,6 @@ import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
-import org.eclipse.cdt.internal.ui.editor.ASTProvider.WAIT_FLAG;
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
/**
@@ -58,6 +58,16 @@ import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
*/
public class CMacroExpansionInput {
+ private static class SingletonRule implements ISchedulingRule {
+ public static final ISchedulingRule INSTANCE = new SingletonRule();
+ public boolean contains(ISchedulingRule rule) {
+ return rule == this;
+ }
+ public boolean isConflicting(ISchedulingRule rule) {
+ return rule == this;
+ }
+ }
+
/**
* Computes the expansion region for a selection.
*/
@@ -199,8 +209,6 @@ public class CMacroExpansionInput {
}
MacroExpansionExplorer fExplorer;
- IDocument fDocument;
- IRegion fRegion;
boolean fStartWithFullExpansion= true;
private CMacroExpansionInput() {
@@ -226,32 +234,41 @@ public class CMacroExpansionInput {
return null;
}
- IProgressMonitor monitor= new NullProgressMonitor();
ExpansionRegionComputer computer= new ExpansionRegionComputer(tu, textRegion, force);
- final WAIT_FLAG waitFlag = force ? ASTProvider.WAIT_ACTIVE_ONLY : ASTProvider.WAIT_NO;
- IStatus status= ASTProvider.getASTProvider().runOnAST(tu, waitFlag, monitor, computer);
- if (!status.isOK()) {
- return null;
- }
- IRegion region= computer.getExpansionRegion();
- if (region == null) {
- return null;
- }
+ doRunOnAST(computer, tu, force);
+
MacroExpansionExplorer explorer= computer.getMacroExpansionExplorer();
if (explorer == null) {
return null;
}
- ITextEditor textEditor= (ITextEditor)editor;
- IDocument document= textEditor.getDocumentProvider().getDocument(editorInput);
-
+
CMacroExpansionInput input= new CMacroExpansionInput();
input.fExplorer= explorer;
- input.fDocument= document;
- input.fRegion= region;
return input;
}
+ private static void doRunOnAST(final ASTRunnable runnable, final ITranslationUnit tu, boolean force) {
+ Job job= new Job(CHoverMessages.CMacroExpansionInput_jobTitle) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_ACTIVE_ONLY, monitor, runnable);
+ }};
+
+ // If the hover thread is interrupted this might have negative
+ // effects on the index - see http://bugs.eclipse.org/219834
+ // Therefore we schedule a job to decouple the parsing from this thread.
+ job.setPriority(force ? Job.INTERACTIVE : Job.DECORATE);
+ job.setSystem(true);
+ job.setRule(SingletonRule.INSTANCE);
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException exc) {
+ job.cancel();
+ }
+ }
+
/**
* Expand the given text region to span complete lines of the document and
* add a number of lines before and after the region.
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java
index 08cb386a31e..03eb11ee538 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java
@@ -27,6 +27,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
@@ -101,6 +103,16 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
private static final boolean DEBUG = false;
+ private static class SingletonRule implements ISchedulingRule {
+ public static final ISchedulingRule INSTANCE = new SingletonRule();
+ public boolean contains(ISchedulingRule rule) {
+ return rule == this;
+ }
+ public boolean isConflicting(ISchedulingRule rule) {
+ return rule == this;
+ }
+ }
+
/**
* Computes the source location for a given identifier.
*/
@@ -787,10 +799,26 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
return source.substring(i);
}
- private String searchInIndex(ITranslationUnit tUnit, IRegion textRegion) {
- IProgressMonitor monitor= new NullProgressMonitor();
- ComputeSourceRunnable computer= new ComputeSourceRunnable(tUnit, textRegion);
- ASTProvider.getASTProvider().runOnAST(tUnit, ASTProvider.WAIT_NO, monitor, computer);
+ private String searchInIndex(final ITranslationUnit tUnit, IRegion textRegion) {
+ final ComputeSourceRunnable computer= new ComputeSourceRunnable(tUnit, textRegion);
+ Job job= new Job(CHoverMessages.CSourceHover_jobTitle) {
+ protected IStatus run(IProgressMonitor monitor) {
+ return ASTProvider.getASTProvider().runOnAST(tUnit, ASTProvider.WAIT_ACTIVE_ONLY, monitor, computer);
+ }
+ };
+ // If the hover thread is interrupted this might have negative
+ // effects on the index - see http://bugs.eclipse.org/219834
+ // Therefore we schedule a job to decouple the parsing from this thread.
+ job.setPriority(Job.DECORATE);
+ job.setSystem(true);
+ job.setRule(SingletonRule.INSTANCE);
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException exc) {
+ job.cancel();
+ return null;
+ }
return computer.getSource();
}

Back to the top