Cannot search for usages in Gherkin like language

Answered

I'm struggling to get "Find Usages" feature working in my custom language plugin for a Gherkin like language. The syntax is as follows

Composite: Given I have a step
...

Composite: Given some other composite step
Given I have a step

In the above example when I click on "Given I have step" (last line), the entire line and the matching part of the first line are highlighted and I can use Ctrl+B to jump to the definition. However, the reverse direction with "Find usages" (Alt+F7) is only partially working. As long as my caret is in the "Given" token find usage works (and also the highlighting works), however if I place my cursor e.g. in the "have" of the first line and then try to find usages I get:

"Cannot search for usages. Position to an element to find usages for, and try again"

I found a similar question from 2014 (https://intellij-support.jetbrains.com/hc/en-us/community/posts/206765815-FindUsage-for-PsiNamedElement-with-multiple-PsiElement-children) however I'm unsure if it still applies, especially since the IntelliJ documentation seems to tell me it should work the way I implemented it. It says in https://www.jetbrains.org/intellij/sdk/docs/reference_guide/custom_language_support/find_usages.html:

When the user invokes the Find Usages action, the IDE locates the PSI element the references to which will be searched. The PSI element at the cursor (the direct tree parent of the token at the cursor position) must be either a PsiNamedElement or a PsiReference which resolves to a PsiNamedElement

My PSI Tree looks as follows:

CompositeDefintion
| - GWT_KEYWORDS_TOKEN (Given)
| - PsiWhiteSpace
| - WORD (I)
| - PsiWhiteSpace
| - WORD (have)
| - PsiWhiteSpace
| - WORD (a)
| - PsiWhiteSpace
| - WORD (step)

From the documentation I would interpret the sentence in bold that e.g. at the cursor/caret "have" I get the token WORD and its direct parent, in my case CompositeDefinition should e.g. be a PsiNamedElement and everything should work. But for me it only does as long as the cursor/caret is in the "Given", e.g. the GWT_KEYWORDS_TOKEN.

Any help is very much appreciated!

 

3
3 comments

Please link to full sources of your plugin, thanks

0

You can find a minimal version of the plugin that showcases the issue here: https://github.com/sischnei/gherkin-language-example

Run the plugin and create a file "Example.steps" containing the following content

Composite: Given I have a step
When I have a step

Composite: Given some other composite step
Given I have a step

When Ctrl+clicking on the last line you should jump to the first line. You can use "Find usages" on the first "Given" keyword (first line) - but the same doesn't work when positioning the caret e.g. in th "have" word (still first line).

0

Hey - sorry to bump, but I'm still struggling with this. Can anybody give some more insight into how the documentation for this should be interpreted / how this feature is supposed to work?

0

Please sign in to leave a comment.