Bug 101287 - 'find decl/defn' navigation not working using ctags indexer & no ScannerInfo
Summary: 'find decl/defn' navigation not working using ctags indexer & no ScannerInfo
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 4.0 RC2   Edit
Assignee: Devin Steffler CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2005-06-22 12:22 EDT by Graeme Johnson CLA
Modified: 2008-06-20 12:58 EDT (History)
3 users (show)

See Also:


Attachments
Simple C project with navigation problems (2.72 KB, application/x-zip-compressed)
2005-06-22 12:23 EDT, Graeme Johnson CLA
no flags Details
fix for this PR (4.45 KB, patch)
2005-06-28 15:27 EDT, Devin Steffler CLA
bjorn.freeman-benson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Graeme Johnson CLA 2005-06-22 12:22:05 EDT
Build: Eclipse 3.1RC3, CDT M7, Exuberant CTags 544

Overview:
In projects that use the CTags indexer both ctrl+click (hyperlink) and F3 (go 
to declaration) navigation seem to be broken.  I have constructed a small test 
project that illustrates the problems, and provided it as an attachment.

Details:
1) Load the supplied project.

2) Open mylib/func2.c and navigate to the myLibFuncTwo() declaration, try to 
ctrl+click on any of the following elements, notice that none of them work.  
This is odd, given that I've seen far larger examples work fine.

  L19: 'myHelper'      --> function defined in the same file
  L18: 'SOME_MACRO'    --> macro defined in header file
  L16: 'SomeStructure' --> type defined in another file (mylib.h)

3) Try the 'Open Declaration' option on the same test cases, a warning appears 
in the status bar in red text stating 'The operation is unavailable on the 
current selection (no name selected)'.

4) At L1 in mylib/func2.c notice that ctrl+click is only available for 
the '.h' portion of '#include "mylib.h"' and that it fails to navigate to the 
declaration.  The outline in the projects view is correct, and works for 
navigation.
Comment 1 Graeme Johnson CLA 2005-06-22 12:23:18 EDT
Created attachment 23751 [details]
Simple C project with navigation problems

Here is a simple C project that can be used to show navigation problems when
using the CTags indexer.
Comment 2 John Camelon CLA 2005-06-23 13:10:46 EDT
FYI RC1 starts next Monday.
Pls have these bugs fixed by then or moved off to a later milestone.
Comment 3 David Daoust CLA 2005-06-26 20:18:09 EDT
This is broken with both the CTags indexer and normal indexer.  (I don't think
that the indexer is involved at all).

Here is a simple example that does not work

int bar() {
}

int main() {
	bar();
}

note that "All Declarations" of bar finds the correct field, but ctrl-click
doesn't do anything.   I am bumping the priorith and severity on this bug as
this is a required workflow.
Comment 4 Bogdan Gheorghe CLA 2005-06-27 00:04:07 EDT
Fixed Dave's example.

The original problem is caused by the DOM not being able to return a proper name
for the selected element in the enclosed project. Specifically, the following
always returns null:

 node = tu.selectNodeForLocation(tu.getFilePath(), offset, length);

Comment 5 Devin Steffler CLA 2005-06-27 09:25:19 EDT
Make sure that the project has the proper #include paths as well:
- build the project to pick up cygwin includes for:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
- include jdk1.4.2_04/include and jdk1.4.2_04/include/win32 to pick up the 
includes for:
#include "jni.h"

The problem is with JNICALL.  Without the #includes then the JNICALL causes 
IASTProblemDeclarations on the AST.  With the proper #includes then the AST 
doesn't have IASTProblemDeclarations but the JNICALL is not kept on the AST 
(that is why there is the error "no name selected").

Also, with proper #includes setup in the project, the JNICALL breaks the 
offsets by 1 which can be seen when navigating through the DOM AST.  So even 
with proper #includes, navigating on other elements in the AST fails because 
they have broken offsets.
Comment 6 Bogdan Gheorghe CLA 2005-06-27 09:36:59 EDT
There are a number things that need to be done to make this project sane:

1) Create a new Standard Make C project and import the source+folder enclosed
2) Add include paths + build
3) Change the SomeStruct to:

typedef struct SomeStruct
{
	int slot1;
	long slot2;
} SomeStructure;

4) Notice that the offsets presented in the  DOM Viewer are off by 1 for both
func1.c and func2.c
Comment 7 Bogdan Gheorghe CLA 2005-06-27 09:39:11 EDT
Re: Comment #5: Notice that it is still broken even if you remove all of the JNI
calls - ie. make all of them just regular functions.
Comment 8 John Camelon CLA 2005-06-27 09:53:51 EDT
       Critical  crashes, loss of data, severe memory leak 
(X)    Major 	  major loss of function
Comment 9 Graeme Johnson CLA 2005-06-27 10:02:57 EDT
I thought it might help if I explained our use case.  

We're trying to use CDT to manage a large source-tree that targets about 20 
different platforms, as such we'll almost never have the correct header files 
locally.  This is the reason that the project include paths weren't set up. 

We were hoping that the CTags indexer would provide rudimentary search (better 
than grep) without the requirement of being able to compile locally.
Comment 10 John Camelon CLA 2005-06-27 10:29:25 EDT
The include paths are still used by the navigation features in order to
determine what to navigate to/from. 

BTW, selection of the CTags indexer states that it provides only declaration
symbols.  Navigation to and from cross references will not work in this mode.  

There are 2 aspects to this bug.

1.  If we do set up the project correctly there is some sort of error in the
parser relating to offsets, which then messes up the navigation features. I can
investigate this further and perhaps fix this for RC1.  

2.  Perhaps the selection/navigation features should have a backup strategy for
when the translation unit cannot return a specific node relating to a selection.
 Devin, is it possible to query the index w/just a string in this case?

I always thought that the CTags case could handle the "impossible to set up the
include paths" scenario ... I'd like to see some more best effort heuristics in
this case.  This would not be able to be fixed for RC1 though ... 
Comment 11 Devin Steffler CLA 2005-06-27 10:42:51 EDT
Without a proper AST the best that can be used to search against the index is 
the selected string i.e. "JNICALL", "foo".

We need to discuss if this should be included in the F2/F3 heuristics which are 
supposed to "jump to the most correct element found".  If the user wants to 
find all C/C++ elements in the index relative to a string then they can use 
Search to do this.  Would plugging this functionality into F2/F3 be the best 
thing to do since only one result can be opened?  I think that this wouldn't be 
helpful to the user as broken code could jump around to anything that is found 
in the index matching the string.  Maybe the error returned to the user should 
hint that Search could be used to find matching results in the index?
Comment 12 Graeme Johnson CLA 2005-06-27 10:54:23 EDT
We were looking for the same navigation features that one gets from CTags + 
VIM inside the Eclipse environment.  For ambiguous definitions VIM simply 
displays a list of choices -- in practice, this works pretty well.
Comment 13 John Camelon CLA 2005-06-27 11:21:35 EDT
I've raised https://bugs.eclipse.org/bugs/show_bug.cgi?id=101875 to track why
the parser is failing for selecting these nodes.  Graeme, as a work around to
what you are doing, you can add a new line to the end of your header files.  

Devin wrote:
> If the user wants to find all C/C++ elements in the index relative to a 
> string then they can use Search to do this.  Would plugging this 
> functionality into F2/F3 be the best thing to do since only one result 
> can be opened?  

I do not want F2/F3 to bring up a dialog. 
I do want F2/F3 to take advantage of what is in the index in the case where the
parser has a hard time figuring out the particular node selected.  Consider this
to be error-proofing your feature in the event of a parser bug (or
misconfiguration). 

We already go to the first declaration when there are many in the index, I
figure we can do the same in this case.  Since in C there is very little
overloading, I think this would work well.  In C++ your mileage may vary. :-)

Assigning to Devin, marking for 3.0 (should not gate RC1).
Comment 14 Devin Steffler CLA 2005-06-28 15:27:27 EDT
Created attachment 24107 [details]
fix for this PR

This patch adds the functionality that allows someone to perform F2/F3 on text
even if there is nothing on the AST for that text (i.e. the AST is broken). 
Although it probably won't be addressed until after RC1.

// example.cpp:
int abc;
int main(int argc, char **argv) {
   abc // this is an IASTProblemDeclaration but F2/F3 will find abc above
       // with this patch through the index
}
Comment 15 John Camelon CLA 2005-06-28 15:56:39 EDT
I cannot read your patch. 
If you are attaching a zip file, pls don't say its a patch, as bugzilla tries to
decode it as a text file. 
Comment 16 John Camelon CLA 2005-06-28 16:36:04 EDT
Patch applied. This will be included in RC1. 
Thanks Devin.
Comment 17 Markus Schorn CLA 2006-12-19 08:03:02 EST
Testcase testBug101287 is failing.
Comment 18 Markus Schorn CLA 2007-05-16 10:20:54 EDT
I have fixed the related testcase.