Repository navigation
feat: Find Usages shows a reference that both the language plugin and the language server find once, on one line - #2228
Merged
lagergren merged 1 commit intoNov 25, 2026
Conversation
… the language server find once, on one line Find Usages of a language plugin's element, such as a Scala class with Metals as language server, lists the usages of the language plugin's own search and those of the language server. The usage view merges the usages of a line only within one group, and groups a usage by its usage type and by the PSI around it, such as its method. A reference that both find was therefore listed twice: in the language plugin's group, such as "Method call", and under References. A reference of the language server at the range of a reference of the language plugin is now reported as the language plugin's search reports that reference, a usage of the reference's element, so that the usage view groups both alike and shows them on one line. Its read or write access, when an integration gives it, is kept. A reference that only the language server finds is still listed: in the language plugin's group when the language plugin has a reference at its range, and under References otherwise. The usages of LSP4IJ's own symbol, as in a file without a language plugin, are listed as before. This is the second request of redhat-developer#729. Fixes redhat-developer#2227
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2228 +/- ##
==========================================
+ Coverage 55.52% 55.56% +0.03%
==========================================
Files 843 843
Lines 35939 35955 +16
Branches 5638 7437 +1799
==========================================
+ Hits 19955 19978 +23
+ Misses 13097 13083 -14
- Partials 2887 2894 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2227
This is the second request of #729, whose first was fixed in #2219.
What
When Find Usages searches a language plugin's element, such as a Scala class with Metals, IntelliJ runs the plugin's own search and LSP4IJ's
CustomUsageSearcher(FindUsagesManager.createUsageSearcher). Usages on the same line are merged only within one group (GroupNode.tryMerge), and the view groups by usage type and by file structure:UsageTypehas identity equality);LSPUsageViewElement) had no file-structure parent, while the plugin's usage sits under its method or class.So a reference that both found was listed twice, for example under "Method call" and under "References". That happened even with "Group by usage type" off, because the file-structure groups differed too.
Change
LSPUsageSearcher.toUsage(usage, searchedElement)handles a reference from the language server specially when the searched element is not LSP4IJ's own, that is when the plugin's handler searched it:file.findReferenceAt(start). The reference must not be LSP4IJ's own PSI, such as the semantic tokens, and itsgetAbsoluteRange()must equal the language server's range exactly.UsageInfoof the reference's element converted withUsageInfoToUsageConverter.convert, asFindUsagesManagerdoes. The usage view then puts both in the same groups and shows them on one line.ReadWriteAccessUsageInfo2UsageAdapter).Dropping LSP4IJ's copy "when the plugin already reported it" isn't possible exactly. The plugin's usages go through a private
UniqueProcessor, and its word-index results come after all custom searchers (processRequests(fastTrack)). So merging through the same groups is the safe way.Not in this PR:
Tests
New
LSPUsageMergeWithLanguagePluginTest, 3 tests:PsiReferences and a "Method call"UsageTypeProvider, which gives Find Usages a plugin handler.FindUsagesManager.createUsageSearcher, and renders the realUsageViewImpltree.[Definitions 1 ArgNode, Method call 2 first(ArgNode), Method call 3 second(ArgNode), References 2 first(ArgNode), References 4 third(ArgNode), References 5 // ArgNode], with line 2 twice.[Definitions 1 ArgNode, Method call 2 first(ArgNode), Method call 3 second(ArgNode), Method call 4 third(ArgNode), References 5 // ArgNode].The new class passes headless on IC 2024.2, 2025.3 and IU 2026.3.
usages.*andfeatures.references.*pass on all three: 30 tests each, 0 failures, 0 skipped.Behaviour change