mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Allow to cancel indexer while collecting files.
This commit is contained in:
parent
75ab77d311
commit
fe15e65401
5 changed files with 29 additions and 12 deletions
|
@ -59,14 +59,20 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
|||
private final Collection fHeaders;
|
||||
private final boolean fAllFiles;
|
||||
private final Collection fSources;
|
||||
private final IProgressMonitor fProgressMonitor;
|
||||
|
||||
private TranslationUnitCollector(Collection sources, Collection headers, boolean allFiles) {
|
||||
private TranslationUnitCollector(Collection sources, Collection headers, boolean allFiles,
|
||||
IProgressMonitor pm) {
|
||||
fHeaders = headers;
|
||||
fAllFiles = allFiles;
|
||||
fSources = sources;
|
||||
fProgressMonitor= pm;
|
||||
}
|
||||
|
||||
public boolean visit(ICElement element) throws CoreException {
|
||||
if (fProgressMonitor.isCanceled()) {
|
||||
return false;
|
||||
}
|
||||
switch (element.getElementType()) {
|
||||
case ICElement.C_UNIT:
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
|
@ -118,14 +124,15 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
|||
return (trace != null && trace.equalsIgnoreCase(value));
|
||||
}
|
||||
|
||||
protected void processDelta(ICElementDelta delta, Collection added, Collection changed, Collection removed) throws CoreException {
|
||||
protected void processDelta(ICElementDelta delta, Collection added, Collection changed, Collection removed,
|
||||
IProgressMonitor pm) throws CoreException {
|
||||
boolean allFiles= getIndexAllFiles();
|
||||
int flags = delta.getFlags();
|
||||
|
||||
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
|
||||
ICElementDelta[] children = delta.getAffectedChildren();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
processDelta(children[i], added, changed, removed);
|
||||
processDelta(children[i], added, changed, removed, pm);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,20 +162,22 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
|||
case ICElement.C_CCONTAINER:
|
||||
ICContainer folder= (ICContainer) element;
|
||||
if (delta.getKind() == ICElementDelta.ADDED) {
|
||||
collectSources(folder, added, added, allFiles);
|
||||
collectSources(folder, added, added, allFiles, pm);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void collectSources(ICContainer container, final Collection sources, final Collection headers, final boolean allFiles) throws CoreException {
|
||||
container.accept(new TranslationUnitCollector(sources, headers, allFiles));
|
||||
private void collectSources(ICContainer container, Collection sources, Collection headers, boolean allFiles,
|
||||
IProgressMonitor pm) throws CoreException {
|
||||
container.accept(new TranslationUnitCollector(sources, headers, allFiles, pm));
|
||||
}
|
||||
|
||||
protected void collectSources(ICProject project, final Collection sources, final Collection headers, final boolean allFiles) throws CoreException {
|
||||
protected void collectSources(ICProject project, Collection sources, Collection headers, boolean allFiles,
|
||||
IProgressMonitor pm) throws CoreException {
|
||||
fMessage= MessageFormat.format(Messages.PDOMIndexerTask_collectingFilesTask, new Object[]{project.getElementName()});
|
||||
project.accept(new TranslationUnitCollector(sources, headers, allFiles));
|
||||
project.accept(new TranslationUnitCollector(sources, headers, allFiles, pm));
|
||||
}
|
||||
|
||||
protected void removeTU(IWritableIndex index, ITranslationUnit tu, int readlocks) throws CoreException, InterruptedException {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.model.ICElementDelta;
|
|||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
||||
|
||||
|
@ -29,7 +30,7 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
|
||||
public PDOMFastHandleDelta(PDOMFastIndexer indexer, ICElementDelta delta) throws CoreException {
|
||||
super(indexer);
|
||||
processDelta(delta, changed, changed, removed);
|
||||
processDelta(delta, changed, changed, removed, new NullProgressMonitor());
|
||||
fTotalSourcesEstimate= changed.size() + removed.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,12 @@ class PDOMFastReindex extends PDOMFastIndexerJob {
|
|||
boolean allFiles= getIndexAllFiles();
|
||||
List sources= new ArrayList();
|
||||
List headers= new ArrayList();
|
||||
collectSources(indexer.getProject(), sources, allFiles ? headers : null, allFiles);
|
||||
collectSources(indexer.getProject(), sources,
|
||||
allFiles ? headers : null, allFiles, monitor);
|
||||
|
||||
if (monitor.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fTotalSourcesEstimate= sources.size() + headers.size();
|
||||
setupIndexAndReaderFactory();
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.model.ICElementDelta;
|
|||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -33,7 +34,7 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
|||
|
||||
public PDOMFullHandleDelta(PDOMFullIndexer indexer, ICElementDelta delta) throws CoreException {
|
||||
super(indexer);
|
||||
processDelta(delta, changed, changed, removed);
|
||||
processDelta(delta, changed, changed, removed, new NullProgressMonitor());
|
||||
fTotalSourcesEstimate= changed.size() + removed.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
|
|||
List/*<ITranslationUnit>*/ sources= new ArrayList/*<ITranslationUnit>*/();
|
||||
List/*<ITranslationUnit>*/ headers= new ArrayList/*<ITranslationUnit>*/();
|
||||
|
||||
collectSources(indexer.getProject(), sources, allFiles ? headers : null, allFiles);
|
||||
collectSources(indexer.getProject(), sources,
|
||||
allFiles ? headers : null, allFiles, monitor);
|
||||
fTotalSourcesEstimate= sources.size() + headers.size();
|
||||
|
||||
setupIndexAndReaderFactory();
|
||||
|
|
Loading…
Add table
Reference in a new issue