Bug 508216 - Search results for macro do not show enclosing class/function
Summary: Search results for macro do not show enclosing class/function
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-source-nav (show other bugs)
Version: Next   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 9.3.0   Edit
Assignee: Nathan Ridge CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-25 15:35 EST by Nathan Ridge CLA
Modified: 2020-04-01 02:46 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Ridge CLA 2016-11-25 15:35:42 EST
Consider the following code:

  void waldo();

  struct S {
    void foo() {
      waldo();
    }
  };

Find References on 'waldo' finds one result, which is presented as follows:

  S::foo, line 5: waldo();

Notice how the presentation includes the name of the containing class and function.

Now, replace the function with a macro:

  #define waldo()

  struct S {
    void foo() {
      waldo();
    }
  };

If you search again, the presentation of the result is now:

  line 5: waldo();

Notice how the containing class and function is no longer there. I think it should be; it's useful information.
Comment 1 Nathan Ridge CLA 2016-12-07 16:38:15 EST
The containing class and function is derived from IIndexName.getEnclosingDefinition(). PDOMName (used for bindings like functions) implements this, but PDOMMacroReferenceName (used for macros) does not.

The solution is to implement getEnclosingDefinition() for PDOMMacroReferenceName. This requires storing an extra field in the PDOMMacroReferenceName record, but we are not increasing the effective size of the record.
Comment 2 Eclipse Genie CLA 2016-12-07 16:39:25 EST
New Gerrit change created: https://git.eclipse.org/r/86671
Comment 4 Nathan Ridge CLA 2016-12-19 13:26:10 EST
Fixed for 9.3.
Comment 5 Nathan Ridge CLA 2017-01-05 01:54:30 EST
I mentioned this in the 9.3 N&N: https://wiki.eclipse.org/CDT/User/NewIn93#Enclosing_definition_of_macro_reference
Comment 6 Simeon Andreev CLA 2020-03-31 10:04:41 EDT
Any option to disable this fix? We are updating an old product to CDT 9.6 and we are seeing a lot of time spent in org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor.Definition.search(int, int).
Comment 7 Nathan Ridge CLA 2020-03-31 16:16:42 EDT
The closest thing would be Preferences -> C/C++ -> Indexer -> "Skip type and macro references".

I'm not sure why type and macro references are lumped together into a single option in the UI; at the level of the CDT API, there are separate options for type references and macro references. I would accept a patch that exposes the two options separately in the UI.
Comment 8 Simeon Andreev CLA 2020-04-01 02:46:46 EDT
(In reply to Nathan Ridge from comment #7)
> The closest thing would be Preferences -> C/C++ -> Indexer -> "Skip type and
> macro references".
> 
> I'm not sure why type and macro references are lumped together into a single
> option in the UI; at the level of the CDT API, there are separate options
> for type references and macro references. I would accept a patch that
> exposes the two options separately in the UI.

Thanks!

I was able to disable the macro search with this in the product customization ini:

+org.eclipse.cdt.core/indexer/skipTypeReferences=true
+org.eclipse.cdt.core/indexer/skipMacroReferences=true

We'll leave it at that, if our user base complains we can look into adding a separate checkbox and disable for macros only.