mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 93788: CTags indexer should index the include path
This commit is contained in:
parent
750f5bb545
commit
0d6a37aebe
3 changed files with 97 additions and 5 deletions
|
@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.core.index.ctagsindexer;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CommandLauncher;
|
||||
|
@ -24,6 +26,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.core.model.IIncludeReference;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.index.cindexstorage.CIndexStorage;
|
||||
import org.eclipse.cdt.internal.core.index.cindexstorage.Util;
|
||||
import org.eclipse.cdt.internal.core.index.domsourceindexer.AbstractIndexerRunner;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
|
||||
|
@ -123,7 +126,8 @@ class CTagsIndexAll extends CTagsIndexRequest {
|
|||
}
|
||||
|
||||
//Try to index includes (if any exist)
|
||||
//cTagsInclude(index);
|
||||
if (ctagIndexIncludes())
|
||||
cTagsInclude(index);
|
||||
|
||||
} catch (IOException e) {
|
||||
if (IndexManager.VERBOSE) {
|
||||
|
@ -146,20 +150,58 @@ class CTagsIndexAll extends CTagsIndexRequest {
|
|||
refs = cProj.getIncludeReferences();
|
||||
} catch (CModelException e) {}
|
||||
|
||||
|
||||
//Find common base for references
|
||||
String[] pathString = new String[refs.length];
|
||||
for (int i=0; i<refs.length; i++){
|
||||
runCTags(refs[i].getPath());
|
||||
pathString[i] = refs[i].getPath().toOSString();
|
||||
}
|
||||
Util.sort(pathString);
|
||||
|
||||
HashSet finalArray = new HashSet();
|
||||
String currentString = null;
|
||||
for (int i=0; i<refs.length; i++){
|
||||
if (currentString == null){
|
||||
currentString = pathString[i];
|
||||
finalArray.add(currentString);
|
||||
} else {
|
||||
if (pathString[i].startsWith(currentString)){
|
||||
continue;
|
||||
} else {
|
||||
currentString = pathString[i];
|
||||
finalArray.add(currentString);
|
||||
}
|
||||
}
|
||||
}
|
||||
finalArray.add(currentString);
|
||||
|
||||
Iterator iter = finalArray.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
IPath newPath = new Path((String) iter.next());
|
||||
runCTags(newPath);
|
||||
ctagsFileToUse=ctagsFile;
|
||||
//Parse the CTag File
|
||||
CTagsFileReader reader = new CTagsFileReader(project,ctagsFileToUse,indexer);
|
||||
reader.setRootDirectory(refs[i].getPath());
|
||||
reader.setRootDirectory(newPath);
|
||||
reader.setIndex(index);
|
||||
reader.parse();
|
||||
}
|
||||
|
||||
// request to save index when all cus have been indexed
|
||||
indexer.request(new CTagsSaveIndex(this.indexPath, indexer));
|
||||
}
|
||||
|
||||
private void sortPathArray(IPath[] paths) {
|
||||
|
||||
if (paths.length <= 1)
|
||||
return;
|
||||
|
||||
for (int i=0; i<paths.length; i++){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
@ -237,6 +279,27 @@ class CTagsIndexAll extends CTagsIndexRequest {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean ctagIndexIncludes(){
|
||||
try {
|
||||
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
|
||||
if (cdesc == null)
|
||||
return true;
|
||||
|
||||
ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
|
||||
if (cext.length > 0) {
|
||||
for (int i = 0; i < cext.length; i++) {
|
||||
String id = cext[i].getID();
|
||||
String orig = cext[i].getExtensionData("ctagsindexincludes"); //$NON-NLS-1$
|
||||
if (orig != null){
|
||||
return new Boolean(orig).booleanValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean getCTagsFileLocation() {
|
||||
try {
|
||||
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
|
||||
|
|
|
@ -71,6 +71,9 @@ CTagsIndexerBlock.radioButtonExternal=Import existing CTags file
|
|||
CTagsIndexerBlock.browseButton=Browse...
|
||||
CTagsIndexerBlock.fileBrowser=Select CTags File
|
||||
|
||||
CTagsIndexerBlock.includeGroup=Include Files
|
||||
CTagsIndexerBlock.indexIncludes=Index include paths
|
||||
|
||||
StatusBarUpdater.num_elements_selected={0} items selected
|
||||
|
||||
CElementLabels.anonymous=(anon)
|
||||
|
|
|
@ -43,14 +43,17 @@ public class CTagsIndexerBlock extends AbstractIndexerPage {
|
|||
protected boolean externalTagsFile = false;
|
||||
protected Button internalCTagsFile;
|
||||
protected Button externalCTagsFile;
|
||||
protected Button indexIncludePaths;
|
||||
protected Button browseButton;
|
||||
protected Text cTagsFile;
|
||||
|
||||
|
||||
private String storedInternalExternal;
|
||||
private String storedTagFile;
|
||||
|
||||
public final static String PREF_INTOREXT_CTAGS = CUIPlugin.PLUGIN_ID + ".intorextctags"; //$NON-NLS-1$
|
||||
public final static String PREF_CTAGSLOCATION_CTAGS = CUIPlugin.PLUGIN_ID + ".ctagslocation"; //$NON-NLS-1$
|
||||
public final static String PREF_CTAGS_INDEXINCLUDEFILES = CUIPlugin.PLUGIN_ID + ".ctagsindexincludes"; //$NON-NLS-1$
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.index.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject)
|
||||
|
@ -75,7 +78,8 @@ public class CTagsIndexerBlock extends AbstractIndexerPage {
|
|||
IProject proj = null;
|
||||
String internalExternalCTagsString = internalTagsFile ? CTagsIndexer.CTAGS_INTERNAL : CTagsIndexer.CTAGS_EXTERNAL;
|
||||
String cTagsFileLocation = cTagsFile.getText();
|
||||
|
||||
String indexIncludeFiles = new Boolean(indexIncludePaths.getSelection()).toString();
|
||||
|
||||
//if external has been chosen, ensure that there is a cTagsFileLocation selected; otherwise default
|
||||
//to internal file
|
||||
if (internalExternalCTagsString.equals(CTagsIndexer.CTAGS_EXTERNAL) && cTagsFileLocation.equals("")) //$NON-NLS-1$
|
||||
|
@ -102,12 +106,17 @@ public class CTagsIndexerBlock extends AbstractIndexerPage {
|
|||
if (orig == null || !orig.equals(cTagsFileLocation)) {
|
||||
cext[i].setExtensionData("ctagfilelocation", cTagsFileLocation); //$NON-NLS-1$
|
||||
}
|
||||
orig = cext[i].getExtensionData("ctagsindexincludes"); //$NON-NLS-1$
|
||||
if (orig == null || !orig.equals(cTagsFileLocation)) {
|
||||
cext[i].setExtensionData("ctagsindexincludes", indexIncludeFiles); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (prefStore != null) {
|
||||
prefStore.setValue(PREF_INTOREXT_CTAGS, internalExternalCTagsString);
|
||||
prefStore.setValue(PREF_CTAGSLOCATION_CTAGS,cTagsFileLocation);
|
||||
prefStore.setValue(PREF_CTAGS_INDEXINCLUDEFILES,indexIncludeFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +137,15 @@ public class CTagsIndexerBlock extends AbstractIndexerPage {
|
|||
public void createControl(Composite parent) {
|
||||
Composite page = ControlFactory.createComposite(parent, 1);
|
||||
|
||||
Group includeGroup = ControlFactory.createGroup(page,CUIMessages.getString("CTagsIndexerBlock.includeGroup"),1);
|
||||
GridData gd2 = (GridData) includeGroup.getLayoutData();
|
||||
gd2.grabExcessHorizontalSpace = true;
|
||||
gd2.horizontalAlignment = GridData.FILL;
|
||||
|
||||
indexIncludePaths = ControlFactory.createCheckBox(includeGroup,CUIMessages.getString("CTagsIndexerBlock.indexIncludes"));//$NON-NLS-1$ //$NON-NLS-2$
|
||||
((GridData)indexIncludePaths.getLayoutData()).horizontalSpan =1;
|
||||
((GridData)indexIncludePaths.getLayoutData()).grabExcessHorizontalSpace = true;
|
||||
|
||||
Group group = ControlFactory.createGroup(page, CUIMessages.getString("CTagsIndexerBlock.blockName"),3); //$NON-NLS-1$
|
||||
|
||||
GridData gd = (GridData) group.getLayoutData();
|
||||
|
@ -204,6 +222,14 @@ public class CTagsIndexerBlock extends AbstractIndexerPage {
|
|||
cTagsFile.setText(orig);
|
||||
}
|
||||
|
||||
orig = cext[i].getExtensionData("ctagsindexincludes"); //$NON-NLS-1$
|
||||
if (orig != null){
|
||||
if (new Boolean(orig).booleanValue()){
|
||||
indexIncludePaths.setSelection(true);
|
||||
} else {
|
||||
indexIncludePaths.setSelection(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue