Skip to content

fix: Find Usages no longer lists the declaration again as a reference and a type definition - #2215

Closed
lagergren wants to merge 1 commit into
redhat-developer:mainfrom
lagergren:fix/references-skip-declaration-duplicates
Closed

lagergren wants to merge 1 commit into
redhat-developer:mainfrom
lagergren:fix/references-skip-declaration-duplicates

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #729

What

LSP4IJ asks for references with includeDeclaration set, so the reference list repeats the declaration. The declaration of a type also comes back as its type definition. IntelliJ merges the usages of a line only within one usage-type group, so Find Usages listed the declaration three times: under Definitions, Type Definitions and References. That's what the Scala/Metals screenshot in the issue shows. The existing dedup drops only ranges that strictly contain another, so equal ranges stayed.

Change

After the existing dedup, LSPUsageSearcher.removeRepeatedDeclarations collects the file and range of every declaration and definition. It drops the references and type definitions found at one of those locations. includeDeclaration and its TODO are unchanged.

Not in this PR: a declaration and a definition at the same location are both kept, as before.

Tests

New LSPUsageDeclarationOnceTest: the mock answers definition, type definition and references with the declaration's location.

  • Without the change: [Definitions (6,13), Type Definitions (6,13), References (6,13), References (17,24), References (36,43)].
  • With it: [Definitions (6,13), References (17,24), References (36,43)].

The new test passes headless on IC 2024.2, 2025.3 and IU 2026.3. usages.* and features.references.* pass on all three platforms: 27 tests each, 0 failures, 0 skipped.

Behaviour change

Before After
The declaration appears under Definitions, Type Definitions and References It appears once, under Definitions, with the real references

… and a type definition

LSP4IJ asks for the references with includeDeclaration, so the references of
a symbol include its declaration, and the type definition of a type is the
type itself. The usage view merges the usages of a line only within a group
of the same usage type, so Find Usages showed the declaration of a type three
times: as a definition, as a reference and as a type definition. The
deduplication dropped only a range that strictly contains another, so equal
ranges stayed.

A reference or a type definition whose file and range are those of a
declaration or a definition is now skipped. The declarations, definitions,
implementations and other references are listed as before.

Fixes redhat-developer#729
@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the enhancement New feature or request label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c913c627-d0c6-4882-a1ea-a5fc75ef09e4
Commits

Reviewing files that changed from the base of the PR and between d592c89 and f2c20a9.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/usages/LSPUsageSearcher.java
  • src/test/java/com/redhat/devtools/lsp4ij/usages/LSPUsageDeclarationOnceTest.java

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.69%. Comparing base (1b0b053) to head (f2c20a9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...edhat/devtools/lsp4ij/usages/LSPUsageSearcher.java 76.92% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2215      +/-   ##
==========================================
+ Coverage   54.59%   54.69%   +0.09%     
==========================================
  Files         834      834              
  Lines       35385    35398      +13     
  Branches     7300     5549    -1751     
==========================================
+ Hits        19320    19360      +40     
+ Misses      13223    13195      -28     
- Partials     2842     2843       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

Combined, unchanged, with the other small fixes into #2219, one commit each, so that they take one review instead of six.

@lagergren lagergren closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

option "merge search results from the same line" is not effective on Scala + metaLS

1 participant