Inlay hints for usages not always present

Answered

I find that the "Usages" inlay hint in recent versions of IDEA for certain Java fields, classes, methods, constructors, etc. to be quite useful. But these Usages hint are not always there, and I haven't detected why they are there for only some methods. Is there a way to get these inlay hints for all methods? Thanks.

3
7 comments

I am writing in Kotlin. I do never see inlay hints for `usages` or `inheritors`.

But I can see `code author` hints.

Btw, `usages` inlay hints do not show up even in the little showcase editor tab in the settings tab.

(What I mean is that even the example, which is supposed to show how the inlay hint looks like, does not work.)

0

Jxt could you please provide a code sample when it doesn't work for you?

Deprecatednull do you mean that you don't see "3 usages" like on the screenshot?

0

Well, I cannot give you source code, but I can provide a screen shot. In the screen shot below you can see that there are two methods that have no "usages" inlay. For the first, IDEA knows that it has zero usages because it uses a gray font color for the method name, but the second method does have usages, as can be detected by using the Find Usages command. The third method in the screen shot has the usages inlay showing two usages, which is in agreement with the Find Usages command. I have many many examples in my code of the inlay not showing up. Handy to have when it's there, but frustrating when it's not once I've gotten used to it. (By the way, I have turned off the Code author inlay, explaining why no authors are shown in the screenshot.) I am running the latest 2022.2 Community Edition: Build #IC-222.3345.118, built on July 26, 2022, but the missing usages inlays was occurring in 2022.1 too. Thanks for looking into it.

 

1

Sergei Riabinin

Yes, I don't see the "$n usages" inlay hint like the one on your screenshot.

Sorry for the late reply(

0

Deprecatednull you can follow the existing issue for Kotlin here: https://youtrack.jetbrains.com/issue/KTIJ-21847
You can vote for it and maybe add your example in comments
For the usages not shown in the usages sample - looking into it

Jxt we have the following open tickets for code vision in Java: https://youtrack.jetbrains.com/issue/IDEA-294761 and https://youtrack.jetbrains.com/issue/IDEA-274596, but the first one is probably not related to the issue.
Could you please describe the structure of your class and from where the usage is coming from? So we can reproduce on our side

0

Hello. Yes, the second open ticket you mentioned seems to apply to my observations as well. Whether or not the Usages inlay hints appear seems mostly random. My code is large (over 11 MB of source code alone) and consists of dozens of packages and many many classes, many of which were not written by me. But it is almost entirely POJOs. I tried to extract just one of the classes that exhibits the problem and strip it of all proprietary content and make a new IDEA project. Alas, that class now shows the Usages inlay hints on every method, including those for which no inlay hint appears in the real code. The only exception is that toString() does not get an inlay hint, perhaps it is one of those "too common" names mentioned at the end of issue IDEA-274596, or perhaps because it is not actually used directly but only in a construct like System.out.println (""+InstanceOfClass) in which toString() is only called implicitly.

In general, my methods that don't get Usages inlay hints would not fall into the category of too common names. Perhaps the call chain is just too complicated for the online analysis to detect and show the usages. Still, it's odd that two similar methods like, say, getThisProperty() and getThatProperty() that appear side by side in the code and are called from similar call chains have different behaviors. One gets the Usages inlay hint and one doesn't. The screen shot below is an example. Method getAspectName() gets the inlay hint. Method getUnitname() does not.

Using Find Usages on getAspectName() returns those same seven usages, including three in the class itself and four in another class (let's call it class X). Running Find Usages on getUnitname() returns one usage, and that one usage is in class X. So the inlay hints found the usages of getAspectName() in class X but did not find the one usage of getUnitname() in class X, for which the call chain would be no more complicated than for getAspectName(). As mentioned above, I tried to replicate that behavior in a small example stripped of all actual proprietary content, but then getUnitname() picked up its inlay hint.

Oh well, the inlay hints are handy when they work. Thanks again for looking into it.

 

0

I've seen what Jxt has detailed above for quite a while in IntelliJ Ultimate, can't even tell you when I first saw it it's been so long. Still seeing it right now in the latest version:

IntelliJ IDEA 2023.1.2 (Ultimate Edition)
Build #IU-231.9011.34, built on May 15, 2023
Licensed to ********************
Subscription is active until *****************.
Runtime version: 17.0.6+10-b829.9 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Registry:
    debugger.new.tool.window.layout=true
    ide.experimental.ui=true

Non-Bundled Plugins:
    com.github.leomillon.uuidgenerator (4.5.1)
    CFML Support (231.8770.17)
    com.kevinlinxp.sublimeSnippetsSupport (1.4.0)
    com.intellij.guice (231.8109.90)
    CheckStyle-IDEA (5.79.0)
    com.github.vilinfield.dust (0.4.2)
    dev.flikas.idea.spring.boot.assistant.plugin (0.14.3)
    izhangzhihao.rainbow.brackets (2023.2.7)
    com.intellij.lang.jsgraphql (4.0.1)
    org.intellij.scala (2023.1.18)
    uk.co.ben-gibson.remote.repository.mapper (4.3.2)
    org.sonarlint.idea (8.2.0.68615)
    com.chuntung.plugin.mybatisbuilder (1.2.4)
    com.intellij.spring.batch (231.8770.17)
    com.baomidou.plugin.idea.mybatisx (1.5.5)
    com.intellij.plugins.html.instantEditing (231.8770.15)

Kotlin: 231-1.8.21-IJ9011.34

0

Please sign in to leave a comment.