1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 222069: CSourceHover popup doesn't work after changing file

This commit is contained in:
Anton Leherbauer 2008-03-11 15:15:47 +00:00
parent 3320c11eae
commit 3b9d0a9587
5 changed files with 83 additions and 30 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -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;
/**

View file

@ -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
@ -28,6 +28,10 @@ public final class CHoverMessages extends NLS {
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);
}

View file

@ -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

View file

@ -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.

View file

@ -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();
}