Skip to content

Resolve names in annotation values for navigation - #12

Merged
l0ng-ai merged 1 commit into
mainfrom
fix/annotation-value-navigation
Nov 20, 2026
Merged

l0ng-ai merged 1 commit into
mainfrom
fix/annotation-value-navigation

Conversation

@l0ng-ai

@l0ng-ai l0ng-ai commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Go to definition on a name inside an annotation value, such as MediaType or TEXT_PLAIN in @Produces(MediaType.TEXT_PLAIN), reported no target. These expressions are not part of any body's inference, so classify_name_ref had nothing to look up.

When body resolution finds nothing inside an annotation argument list, the name is now resolved as a constant expression name. A simple name is looked up as a field of the enclosing classes (inherited fields included), then a statically imported field (single imports before on-demand ones), then a type, then a package. A qualified name resolves its qualifier to a class or package, then finds a field, member class, class in the package or subpackage.

How it was verified

  • New test goto_definition_in_annotation_values covers method and class annotations, a fully qualified name, a static import, an array value with named elements, an enum constant, a nested class field and a constant of the enclosing class. Before the change every case returned no target.
  • cargo test -p hir -p ide -p ide-db -p ide-diagnostics -p ide-completion passes. cargo clippy -p hir -p ide --all-targets -- -D warnings is clean, and cargo fmt --all --check passes.

Names in annotation element values (@produces(MediaType.TEXT_PLAIN), @foo(BAR))
are not part of any body's inference, so go to definition found nothing for them.
Resolve them as constant expression names: fields of the enclosing classes,
statically imported fields, then types and packages, following qualified names
through classes and packages.
@l0ng-ai
l0ng-ai merged commit c8c9c66 into main Nov 20, 2026
10 of 12 checks passed
@l0ng-ai
l0ng-ai deleted the fix/annotation-value-navigation branch November 20, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant