# "Find Usages" doesn't work despite "Go to Declaration" works

**URL:** <https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116>\
**Category:** IntelliJ Platform\
**Tags:** plugin-development\
**Created:** [June 26, 2025, 6:31am UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116 "2025-06-26T06:31:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [June 26, 2025, 6:31am UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/1 "2025-06-26T06:31:59Z")

</div>

Hi, everyone!  
I am working on plugin for custom language working in pair with \*.lua files from EmmyLua.  
It went pretty good until I faced a challenge where “Find Usages” from my custom language file \*.simple unable to find reference in the \*.lua file despite “Go to Declaration” can lead me from \*.lua file to \*.simple.

For sake of testing I figured out that something wrong with `ReferenceContributor` because I had to re-write it to support psiElements from EmmyLua. The only one change from `simple_language_plugin` you can find here - [contributor · SaloEater/simple\_language\_plugin@ab9d7b9 · GitHub](https://github.com/SaloEater/simple_language_plugin/commit/ab9d7b9d3cf39c8854377a1b35061f856fdb7b9a)

To reproduce issue, just clone the repo, run `runIde` gradle, open test\_folder and try to find usages for s.simple:prop (it doesn’t work). And try to get reference from file.lua:simple:prop (it works)

I am so desperate and lost that I am willing to do anything to get this weird issue solved.

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [June 26, 2025, 8:01am UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/2 "2025-06-26T08:01:48Z")

</div>

Have you implemented `com.intellij.psi.PsiElement#getUseScope` and `com.intellij.psi.PsiElement#getResolveScope` for your PsiElements in your \*.ltx files, which are the target of references?

Are these implementing `PsiNameIdentifierOwner` or `PsiNamedElement`?

Have you properly implemented `com.intellij.psi.PsiReference#isReferenceTo` for your references?

Just a few thoughts without checking your sources, but these are common problems with “Find Usages”.

---

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [June 26, 2025, 3:57pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/3 "2025-06-26T15:57:38Z")

</div>

Thanks for the answer!  
Gonna research about `PsiElement#getUseScope` and `PsiElement#getResolveScope`.  
Unfortunately, `isReferenceTo` set just to `return true` and even with that it’s not called when i am `Find Usages` for elements from \*.ltx files

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [June 26, 2025, 4:14pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/4 "2025-06-26T16:14:55Z")

</div>

“Find usages” on a reference first locates the definition of the reference and then collects usages for this definition. The scopes mentioned above are used for these lookups. Without proper scopes, “Find Usages” won’t work as expected. So hopefully this should fix it.  
Also experiment with the named elements, there were a few assumptions in the platform code about definition elements, as far as I remember.

---

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [June 26, 2025, 4:43pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/5 "2025-06-26T16:43:50Z")

</div>

Will try to dig in this direction, appreciate it!

It’s just very weird that while demo plugin `simple_language_plugin` works fine with Java, “Find Usages” no longer works when I switch to Lua language and there is no point where we can debug the difference due to huge amount of hidden frames T\_T

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [June 26, 2025, 6:26pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/6 "2025-06-26T18:26:16Z")

</div>

The sources you linked seem incomplete, there isn‘t a plugin.xml file for example.

I can only guess why there‘s a difference. There‘s a find usage handler in your repo, perhaps that‘s inactive?  
Is the resolve of your references returning PsiNamedElement?

---

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [June 26, 2025, 6:56pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/7 "2025-06-26T18:56:08Z")

</div>

My bad for doing poor with the repository.  
Here is fixed link and it was updated in the first message - [GitHub - SaloEater/simple\_language\_plugin at cumulative](https://github.com/SaloEater/simple_language_plugin/tree/cumulative)

Yes, resolve results in picking corrent elements from \*.simple file

---

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [June 27, 2025, 9:13pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/8 "2025-06-27T21:13:06Z")

</div>

Hi, I tried my best with copilot to apply your previous answers but still unable to make it work.  
Is there anything else I can research or maybe there are dedicated marketplace where I can hire/talk to actual plugins developers?  
Or maybe I can ask you to clone and debug that plugin?

Thank you in advance

P.S. I figured out PsySearchHelperImpl: `this.processVirtualFile(vfile, stopped, localProcessor);` doesn’t even work with .lua file, looking deeper

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [June 30, 2025, 9:24am UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/9 "2025-06-30T09:24:25Z")

</div>

Although I’m offering consulting for plugin development, this wouldn’t be a fit for a single problem.

Your repository is not buildable (not build file) and is apparently not the original repository, because it doesn’t have any file type associations for \*.ltx file you mentioned.

---

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [June 30, 2025, 4:41pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/10 "2025-06-30T16:41:29Z")

</div>

Thank you very much for returning to this thread again!  
Just pushed files required to build the project, please, take another look.

Please, forget about `*.ltx` file format, it’s only `*.simple`. Repository is literally official [custom language support tutorial](https://plugins.jetbrains.com/docs/intellij/custom-language-support-tutorial.html) but instead of \*.java just trying to use \*.lua.

Please, use `test-folder` directory to test plugin functionality.

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [July 1, 2025, 3:45pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/11 "2025-07-01T15:45:21Z")

</div>

This was a bit tricky.

Find usages first resolves to the definition of the current element.  
Then the definition is the start to find references in the project.  
Because parsing every file is too slow, find usages relies on a word index. Any file with a word matching the name of the definition is searched.  
The words are provided by `com.intellij.lang.findUsages.FindUsagesProvider#getWordsScanner`.

Because the word scanner used by Lua doesn’t provide `"simple:my_key"` as multiple, separate words the word index does not contain `my_key` and find usages has no result.

A possible workaround (not safe for production) is this:

- Register this instead for Lua. You registered `SimpleFindUsagesProvider` for Lua, which is incorrect. `SimpleFindUsagesProvider` is only working for the Simple language.

- Implementation using a very basic scanner. For production, a better word scanner is needed, e.g. similar to `DefaultWordScanner`, but splitting literal content at `:`. There may be alternative solutions by providing more low-level find usages extensions, but I wouldn’t do that.

```java
final class LuaFindUsagesProvider implements FindUsagesProvider {
  private final FindUsagesProvider delegate = new com.tang.intellij.lua.usages.LuaFindUsagesProvider();

  @Override
  public WordsScanner getWordsScanner() {
    return new SimpleWordsScanner();
  }

  @Override
  public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
    return delegate.canFindUsagesFor(psiElement);
  }

  @Nullable
  @Override
  public String getHelpId(@NotNull PsiElement psiElement) {
    return delegate.getHelpId(psiElement);
  }

  @NotNull
  @Override
  public String getType(@NotNull PsiElement element) {
    return delegate.getType(element);
  }

  @NotNull
  @Override
  public String getDescriptiveName(@NotNull PsiElement element) {
    return delegate.getDescriptiveName(element);
  }

  @NotNull
  @Override
  public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
    return delegate.getNodeText(element, useFullName);
  }
}

```

The java language’s find usage implementation is more complex, that’s why it probably worked but Lua did not.

---

<div class="post-metadata">

**Author:** ![danil.lazarev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/danil.lazarev/32/1569_2.png) [@danil.lazarev](https://platform.jetbrains.com/u/danil.lazarev)\
**Post date:** [July 1, 2025, 4:23pm UTC](https://platform.jetbrains.com/t/find-usages-doesnt-work-despite-go-to-declaration-works/2116/12 "2025-07-01T16:23:06Z")

</div>

> [@jansorg](#):
>
> `LuaFindUsagesProvider `

That’s straightforward cool!  
Appreciate your patience and working example very much!

Will definitely spend development time on making a dedicated `DefaultWordScanner` when other parts are done.

Thanks again!
