You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "harshaindunil (via GitHub)" <gi...@apache.org> on 2026/04/01 23:30:24 UTC

[D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

GitHub user harshaindunil created a discussion: CodeLens-style reference count hint to the NetBeans Java editor.

I have been working on a prototype for [#8230](https://github.com/apache/netbeans/issues/8230), and before opening a PR I would like to get feedback on the overall direction and scope.


<img width="671" height="493" alt="image" src="https://github.com/user-attachments/assets/f8f824a1-0ffd-47bf-82d2-dc638110d858" />


## Summary

The feature adds a CodeLens-style reference count hint to the NetBeans Java editor.

For Java methods and named types, the editor shows an above-line hint such as:

- `1 reference`
- `5 references`

Clicking the hint opens a lightweight popup with grouped references, and from there the user can navigate to usages or open the full existing Find Usages results.

## Scope of the current implementation

This is currently limited to the **Swing Java editor only**.

Implemented behavior:

- shows reference counts above Java methods and named types
- aligns the hint with the declaration start
- hides zero-reference entries
- excludes constructors in the current version
- uses the existing Java Find Usages infrastructure for correctness and navigation
- opens a popup on click, with an option to open the full Find Usages UI
- adds a setting under `Tools > Options > Editor > Inline Hints > Show reference counts`

## Main implementation areas

The current implementation touches these areas:

- Java editor task to discover declarations and publish above-line hints
- editor rendering support for block-style hints above a line
- integration with Java Find Usages / Where Used
- popup UI for quick navigation
- settings/UI integration for enabling or disabling the feature

## Performance work done

I initially observed noticeable editor slowdown, especially on larger files.

To address that, the current implementation now:

- computes counts in the background
- avoids running while scan/indexing is still in progress
- caches computed counts
- only computes counts for declarations visible in the current editor viewport
- avoids full cache invalidation on every index event
- handles split editors correctly
- keeps existing hints visible while recomputation is deferred

With these changes, the feature now appears stable in my testing and no longer shows obvious scrolling or split-editor issues.

## Areas where I would like feedback

Before I submit a PR, I would especially like feedback on these points:

1. **Feature scope**
   - Is Java-editor-only a reasonable first step?
   - Is it acceptable that this is editor functionality only, not LSP / generic editor support?

2. **UI direction**
   - Is the above-line block hint approach acceptable for NetBeans?
   - Is the popup-on-click interaction preferred over directly opening Find Usages?

3. **Reuse of Find Usages**
   - The current implementation reuses the existing Java Where Used behavior for correctness.
   - Is this the right direction for v1, even if a future optimization could use a lighter counting backend?

4. **Performance expectations**
   - The current implementation is much better after viewport-based computation and cache improvements.
   - Is this sufficient for an initial contribution, or would reviewers expect a lighter-weight count mechanism before merge?

## Current intent

If there are no major objections to the approach, I plan to open a PR for #8230 with:

- the editor hint support
- popup navigation
- settings integration
- tests and documentation/screenshots

I would appreciate feedback before I finalize the PR.


GitHub link: https://github.com/apache/netbeans/discussions/9318

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
GitHub user Chris2011 edited a comment on the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

Hey @harshaindunil, anything new here? :)

GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-18147342

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "harshaindunil (via GitHub)" <gi...@apache.org>.
GitHub user harshaindunil added a comment to the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

Thanks, this is helpful feedback.

I agree with keeping the initial scope limited to the swing Java editor. The current implementation is Java-only, and i have tried to keep the counting/popup path separate enough that a future extension would still be possible.

On the UI side, i think your point is reasonable. The current implementation focuses on inline reference hints, but I agree there is room for a second interaction mode later, for example a lazy on-demand usage popup similar in spirit to ctrl+click navigation, but reversed toward usages. That would also be useful from a performance perspective. I would treat that as a follow-up rather than part of this first contribution.

For click behavior, I’m glad the popup direction makes sense. The current flow is:
- inline reference hint
- click opens a lightweight popup
- popup still allows opening the full Find Usages view

so users can choose between quick navigation and the complete tree view.

On performance, i agree this should be treated carefully. I would not argue for enabling it broadly by default beyond the current inline-hints model. The implementation now does background computation, viewport based limiting, caching, and deferred refresh during scanning, but I agree predictability is still the main concern.

I’ll prepare a draft PR next so the code can be reviewed directly.


GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-16669421

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
GitHub user Chris2011 added a comment to the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

i really like the feature, thank you very much for this. I'm curious how you implement the virtual-text above. I couldn't handle it.

One thing: In vs code, the virutal test, which starts above is not the beginning of the line. This should be the same behaviour, becuase it is not the line that start. The code starts at 3 and the line should be part of above. When you call "Go to line" and hit 3, it will jump to this one I guess.

<img width="463" height="54" alt="image" src="https://github.com/user-attachments/assets/e9a16ad3-1d04-4163-a35e-158b9624f3d6" />


GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-16643004

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "harshaindunil (via GitHub)" <gi...@apache.org>.
GitHub user harshaindunil added a comment to the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

thanks, I appreciate the feedback.

for the virtual text above part, I implemented it in the swing editor rendering layer rather than inserting real lines into the document. The hint is painted as an above, line block in the editor view, so it is only visual and does not become part of the file contents.

Because of that, line numbers and actions like _Go to Line_ should still map to the real source lines, not to the reference hint. So if the declaration is on line 3, “Go to Line 3” should still jump to that declaration line.

I also agree with your VS Code comparison. The hint should not behave like a new full line starting at column 1. It should visually belong to the declaration and align with the code start, not replace the actual line start or interfere with line numbering. I have already adjusted the current implementation in that direction.

GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-16669287

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
GitHub user mbien added a comment to the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

> Feature scope

sounds good to me. First integration wouldn't have to cover all aspects (e.g LSP server) as long the implementation doesn't make future extension impossible which is probably not the case. Its good to keep scope small at first.

> UI direction

This would be NetBeans first inline hint which is drawn between lines I believe. I know this is popular and don't have anything against it, but I believe it would be worth considering a usage mode which does not rely on inline text too. Lets say it would work analog to the ctrl+click of the goto-declaration feature, but backwards, opening the usage popup instead. This mode would also avoid some of the performance concerns since it is lazy/on-demand. But since you already started with inline hints, its probably too late to reduce the scope to simple popup action first - which would likely be a smaller change. Lets see how the code looks we can add that later too.

 > Is the popup-on-click interaction preferred over directly opening Find Usages?

popup is probably the most convenient solution here.

> opens a popup on click, with an option to open the full Find Usages UI

right, you seem to have already accounted for that. User can still chose based on preference to get the full tree view -> excellent

> Performance expectations

this is something we _likely_ can't enable by default for now since performance wouldn't be predictable. (knowing how find usages works atm https://github.com/apache/netbeans/pull/8957).

But inline hints are already off by default and mapped to a hotkey, so it would already be covered I think.

feel free to open a draft PR - even if it isn't done yet.

GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-16431861

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
GitHub user Chris2011 added a comment to the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

Thx, I'm pointing to this pr here: #1247 because I already knew that we have inline-text/virtual-text. Jan added this feauture just for append and prepend and I couldn't find a solution for above. I'm very happy that you found a solution. Looking forward to it :). With his implementation I already can handle all other mimetypes. Hope that this is possible with yours too.

GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-16675303

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] CodeLens-style reference count hint to the NetBeans Java editor. [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
GitHub user Chris2011 added a comment to the discussion: CodeLens-style reference count hint to the NetBeans Java editor.

Anything new here? :)

GitHub link: https://github.com/apache/netbeans/discussions/9318#discussioncomment-18147342

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists