referencesSearch and scope management

Answered

Hello,

I'm developing an IntelliJ plugin to support reference resolution and "find usages" functionality for DataTable rows in Gherkin files. The plugin aims to facilitate mapping between DataTable headers in Gherkin and fields in Java classes or records.

You can find the plugin source code here: GitHub Repository.

Problem Overview

I have successfully implemented the reference support using a ReferenceContributor. However, I'm encountering issues when trying to implement the "find usages" feature across all relevant scenarios.

I have opened a PR that attempts to add this feature: PR #5.

Expected Behavior of the QueryExecutor

The QueryExecutor is expected to:

  1. Identify Fields in Annotated Classes: Apply to fields present in classes or records annotated with @DataTableWithHeader. (This part works as expected.)
  2. Search Step Definitions in Java Methods: Search all Cucumber step definition methods (Java methods) that reference the class. (This part also works as expected.)
  3. Search Gherkin Files: Search all steps in Gherkin files. (This is where the issue arises.)
  4. Match DataTable Headers: Within those steps, identify DataTable headers that match the field name being searched, and return the reference. (This works, but is blocked by the issue described below.)

The Issue

When searching for references to a field in a class (but not a record), the QueryExecutor is invoked, but the effectiveSearchScope does not encompass all files in the project. As a result, Gherkin files (.feature) are excluded from the search scope, and references in these files are not found.

I have attached a screenshot (reference id 2024_08_22_28bk33zUZdEjgdnbiiXbYg) showing that the scope is limited to Groovy files. For some reason, when dealing with records, the QueryExecutor is correctly called with a scope that includes all files in the project, including Gherkin files. This issue only occurs with classes.

In a different project setup, the code works correctly for both classes and records, suggesting that the behavior might be context-dependent.

Workaround Attempted

Using queryParameters.scopeDeterminedByUser resolves the "find references" issue, but don't resolve the issue for the field renaming function.

 

I am unable to determine whether this issue stems from a problem in my QueryExecutor implementation or if it's related to IntelliJ configuration. Any insights or suggestions to resolve this inconsistency would be greatly appreciated.

Thank you for your help.

Thomas Deblock

0
3 comments

Hi Thomas,

It's hard to tell the reason for this, but I suggest implementing com.intellij.psi.search.UseScopeEnlarger EP to return Gherking files scope from getAdditionalUseScope.

0

Hi, 

 

Thank you, It seem that with the `UseScopeEnlarger` the `QueryExecutor` become useless. 

It's a good news thanks. There is a documentation about the ScopeEnlarger usage? I have not find it. 

 

Thanks

0

Hi,

It has a simple Javadoc and should be used as a regular EP. So implement the interface and register it in the com.intellij.useScopeEnlarger EP.

You can also search for existing implementations in https://github.com/JetBrains/intellij-community and https://jb.gg/ipe.

0

Please sign in to leave a comment.