antlr / antlr/jetbrains-plugin-sample
Leaf nodes should not implement INamedElement (bug fix for find usages)
- Dominant language
- Java
- Stars
- 120
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
`IdentifierPSINode` is a leaf node in your AST, and it implements `PsiNamedElement`.
https://github.com/antlr/jetbrains-plugin-sample/blob/0b8d515b5d38e4240d79d69a5e00c7ead0bf301a/src/main/java/org/antlr/jetbrains/sample/psi/IdentifierPSINode.java#L39
It should not implement `PsiNamedElement`.
The [Custom Language tutorial says](https://plugins.jetbrains.com/docs/intellij/references-and-resolve.html#psireference:~:text=While%20the%20referencing%20element%20and%20the%20referenced%20element%20both%20may%20have%20a%20name%2C)
> While the referencing element and the referenced element both may have a name, only the element which introduces the name (e.g., the definition int `x = 42`) needs to implement `PsiNamedElement`. The referencing element at the point of usage (e.g., the `x` in the expression `x + 1`) should not implement `PsiNamedElement` since it does not _have_ a name.
I based my leaf node implementations on `IdentifierPSINode`, so I had my leaves implement `PsiNamedElement`. I just realized that this was causing a bug with "Find Usages". When searching for usages from a declaration, there were no results. Changing my leaves to not implement this interface fixed this problem.
Before I found this fix, I found the following workaround. I had my declaration be a reference to itself. In this case, "right-click -> Find Usages" works correctly, but "right-click -> Go To -> Declaration or Usages" does not. If there was only one usage, then the correct behavior would be to go to that usage. Instead, the behavior in this case is that the cursor moves to the beginning of the declaration (which is the current behavior for the current ANTLR plugin https://github.com/antlr/intellij-plugin-v4/issues/580).
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with src/main/java/org/antlr/jetbrains/sample/psi/IdentifierPSINode.java at the referenced declaration and compare it with the IntelliJ PSI guidance linked in the issue. Confirm that the leaf node no longer implements PsiNamedElement, then verify that Find Usages from a declaration returns the expected references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100