Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] CTags indexer cannot process linked source folders - remedy suggestion

Hello folks,

I came across this issue, details are documented in 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=117847

After some digging I think I can offer an initial suggestion for a remedy. 

1. Instead of simply running ctags from the project root directory ctags must 
be called for all project source folders in a loop. ctags must be called with 
an absolute path which is valid in the machine's file system on which it is 
run.
Like this:
In CTagsIndexAll.execute(IProgressMonitor) call runCTags() in a loop:


	try {
		ICProject cproject = CModelManager.getDefault().create(project);
		ISourceRoot[] sourceRoots = cproject.getAllSourceRoots();
		success = true ;
		for (int i = 0; i < sourceRoots.length; i++) {
			ISourceRoot sourceRoot = sourceRoots[i];
			location = sourceRoot.getResource().getLocation();
			success &= runCTags(location);
		}
	} catch (CModelException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}


2. Since we are now calling runCTags() in a loop we must add the -a option for 
ctags so that parse results will be appended.

3. We give ctags the (absolute) path of the directory to parse instead of just 
starting the process in the directory and letting ctags implicitly working 
from the current directory. This makes ctags write absolute file paths into 
the tags file too and so the files can surely be located.

So the start of runCTags() should look like this: 

    private boolean runCTags(IPath directoryToRunFrom) { 
    	String pathToCollectFrom = directoryToRunFrom.toString();
    	String[] args = {"--excmd=number", //$NON-NLS-1$
		        "--format=2", //$NON-NLS-1$
				"--sort=no",  //$NON-NLS-1$
				"--fields=aiKlmnsSz", //$NON-NLS-1$
				"--c-types=cdefgmnpstuvx", //$NON-NLS-1$
				"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
				"--languages=c,c++", //$NON-NLS-1$
				"-a", //$NON-NLS-1$ // pn3484 All locations are collected in one file
				"-f",ctagsFile,"-R", //$NON-NLS-1$ //$NON-NLS-2$
				pathToCollectFrom  // pn3484 Give absolute path so that tag file entries 
will be absolute
    	};


Drawback:

Since ctags is called with an absolute path on a specific build machine the 
ctags file contains paths which are bound to this machine. It would be even 
more elegant to transform the absolute paths from the ctags file to workspace 
relative paths which are then entered into the index. In this way ctags files 
could be shared between machines.
This argument is not so pressing however, since the ctags runs are _fast_ 
while the import of the tags file into eclipse takes __long__.

Any opinions on this?


Thank you,


Norbert



Back to the top