Skip to content

fix: use actual rule kind from aspect output instead of heuristic name matching#23

Merged
monkey666-cr merged 2 commits into
monkey666-cr:mainfrom
runchen0919:fix/target-kind-inference
May 21, 2026
Merged

fix: use actual rule kind from aspect output instead of heuristic name matching#23
monkey666-cr merged 2 commits into
monkey666-cr:mainfrom
runchen0919:fix/target-kind-inference

Conversation

@runchen0919
Copy link
Copy Markdown
Contributor

@runchen0919 runchen0919 commented May 21, 2026

Summary

  • Bug: infer_target_kind() used label.contains("_import") to classify targets as java_import, causing false positives for targets like funds_csv_importer whose names contain "import" but are actually java_library rules
  • Impact: Affected targets got only their own JARs (no transitive dependencies), breaking IDE resolution for all imports
  • Fix: Store the actual rule kind from Bazel aspect output in DependencyGraph.target_kinds, then look it up during classpath computation instead of guessing from the label name

Changes

File What changed
graph.rs Added target_kinds: HashMap<String, String> field, set_target_kind/get_target_kind methods, populate kind during aspect ingestion
classpath.rs Replaced infer_target_kind(label) calls with graph.get_target_kind(label), removed the heuristic function and its tests
lib.rs Removed infer_target_kind from public re-exports
jni_exports.rs Updated two call sites to use graph.get_target_kind() inside the graph lock

Test plan

  • Added unit tests for get_target_kind (java_library, java_import, unknown, unrecognized)
  • Added integration test: funds_csv_importer target now correctly gets transitive deps
  • cargo test --workspace — all 113 tests pass
  • cargo clippy --workspace — clean
  • cargo build -p bazel-jdt-core --release — builds successfully
  • Manual verification with urbancompass project (requires VS Code environment)

🤖 Generated with Claude Code

runchen0919 and others added 2 commits May 21, 2026 13:07
…e matching

The `infer_target_kind` function used `contains("_import")` to detect
`java_import` targets, which falsely matched any target whose name
contained "import" (e.g., `funds_csv_importer`). Misclassified targets
were routed to `compute_for_import` which returns only the target's own
JARs without BFS traversal, causing all imports in affected source files
to show "cannot be resolved" in the IDE.

Replace the heuristic with a graph-based lookup: store the actual Bazel
rule kind string from aspect output in `DependencyGraph.target_kinds`
during `populate_from_aspects`, and look it up via `get_target_kind()`
during classpath computation. Targets without stored kind data fall back
to `Unknown`, which routes to `compute_for_library` (the safe default).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix rustfmt formatting in set_target_kind method
- Regenerate package-lock.json with official npm registry (was using
  npmmirror.com which times out from GitHub Actions runners)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@monkey666-cr monkey666-cr merged commit 8070b14 into monkey666-cr:main May 21, 2026
3 checks passed
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.

2 participants