You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
java.project.sourcePaths Setting Fails to Exclude Test Directory from References and Call Hierarchy #1408
When configuring the java.project.sourcePaths setting in settings.json to exclude the test directory (e.g., src/test/java) from being indexed, the "Find All References" and "Call Hierarchy" features still include results from the test directory. This persists even after cleaning the language server workspace and restarting VS Code.
To Reproduce
Steps to reproduce the behavior:
Open a Java project in VS Code (e.g., a Maven project with src/main/java and src/test/java).
Add the following to settings.json (workspace scope):
json
Wrap
Copy
{
"java.project.sourcePaths": ["src/main/java"]
}
Run Java: Clean Language Server Workspace and restart VS Code.
Right-click a class in src/main/java and select "Find All References" or "Call Hierarchy."
Observe that references from src/test/java are still included in the results.
Expected behavior
The java.project.sourcePaths setting should limit the scope of "Find All References" and "Call Hierarchy" to only the specified directories (e.g., src/main/java), excluding src/test/java.
Actual behavior
References and call hierarchy results still include files from src/test/java, despite the java.project.sourcePaths configuration.
No .classpath file exists in the project.
Cleaning the language server cache (Java: Clean Language Server Workspace) and manually deleting the cache folder (e.g., ~/.vscode/extensions/redhat.java-/server/data) did not resolve the issue.
The project structure is standard (e.g., src/main/java for source, src/test/java for tests).
Possible workaround
Manually removing src/test/java from the source path via the "Java Projects" view works temporarily, but this is not a persistent solution across sessions.
Suggested fix
Ensure the java.project.sourcePaths setting is respected by the language server when generating references and call hierarchy, excluding unspecified directories like src/test/java.
Hi xiemin (@peterxiemin), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Current status
This is a known limitation: java.project.sourcePaths controls which folders are imported as compilation sources but isn’t yet respected by the language server when computing references or call hierarchies. There is no built-in setting to exclude test code from those features.
Workarounds
Use VS Code’s folder-exclusion settings to keep tests out of search and navigation:
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!
Activity
github-actions commentedon Nov 4, 2025
Hi xiemin (@peterxiemin), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Current status
This is a known limitation:
java.project.sourcePathscontrols which folders are imported as compilation sources but isn’t yet respected by the language server when computing references or call hierarchies. There is no built-in setting to exclude test code from those features.Workarounds
src/test/javain the Java Projects view after each workspace start (not persistent).Next steps
This is a feature request/bug for the Java language server. Please star or comment on the issue to track progress:
(Feature: respect
java.project.sourcePathsfor reference & call-hierarchy)Other references with low confidence
Issue 584: Debug classpath mishandles test scope across multi-module projects; talks about excluding test dependencies at runtime but not relevant to source path indexing.
Wrong classpath at runtime when the maven project is in a folder vscode-java-debug#584 (comment)
Issue 3332: Test code can’t resolve main imports due to missing
.classpathentries; indicates how.classpathis generated but doesn’t affect the LSP indexing for references.imports of class from src/main/java cannot be resolved in class src/test/java redhat-developer/vscode-java#3332
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!