Direct navigation for single reference
Description: When navigating to a method or variable that has only one reference, VSCode Java extension should directly navigate to the target location instead of showing the reference list.
Current behavior:
- When using "Go to Definition" or "Find References" on a method/variable with single reference
- VSCode shows a reference list with only one item
- User needs to click on the reference to navigate
Expected behavior:
- When using "Go to Definition" or "Find References" on a method/variable with single reference
- VSCode should directly navigate to the target location
- No reference list should be shown
Benefits:
- Improves developer productivity
- Reduces unnecessary clicks
- Better user experience
- Consistent with common IDE behavior
Example:
// Current behavior
public class Example {
public void method() {
singleReference(); // Go to Definition shows reference list
}
private void singleReference() {
// implementation
}
}
// Expected behavior
public class Example {
public void method() {
singleReference(); // Go to Definition directly navigates
}
private void singleReference() {
// implementation
}
}
Additional context:
- This feature would be particularly useful in large codebases
- It would make navigation more efficient
- It's a common feature in other IDEs like IntelliJ IDEA
I tried in typescript and it seemed to work, so it's definitely possible. Just couldn't figure out why it wasn't jumping when clearly I had chosen things with a single reference. Then I realized that the current default is to include the declaration (as well as the single reference) in the reference lookup, so that's 2 things. If you set "java.references.includeDeclarations": "false", it should work.
I tried in typescript and it seemed to work, so it's definitely possible. Just couldn't figure out why it wasn't jumping when clearly I had chosen things with a single reference. Then I realized that the current default is to include the declaration (as well as the single reference) in the reference lookup, so that's 2 things. If you set
"java.references.includeDeclarations": "false", it should work.
ok, "java.references.includeDeclarations": "false" is work
Yeah, the decision to include that as an option comes from https://github.com/redhat-developer/vscode-java/issues/3850#issuecomment-2465294841 . Closing for now as there's a clear explanation, although it's unfortunate using that setting blocks this functionality.