Skip to main content

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

Hi,

I think that there might still be some issues with linked folders.

Consider the following project structure:

C:\aproject\alinkedfolder[a source folder that links to C:\foo]
C:\foo\bar.h

The ctags indexer may have problems finding the IFile object for the file bar.h (with the location C:\foo\bar.h and the workspace path C:\aproject\alinkedfolder\bar.h).

I've added a bug report and a patch suggestion with some questions to bugzilla:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=136113

Any opinions on this?

BR,
/Per


On 1/5/06, Norbert Ploett <norbert.ploett@xxxxxxxxxxx> wrote:
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

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top