Skip to content

fix bazel: prefer .bazelbsp/.bazelproject and fix import/jdeps issues#391

Open
tboernerapex wants to merge 3 commits intoJetBrains:261from
tboernerapex:fix/prefer-bazelbsp-bazelproject
Open

fix bazel: prefer .bazelbsp/.bazelproject and fix import/jdeps issues#391
tboernerapex wants to merge 3 commits intoJetBrains:261from
tboernerapex:fix/prefer-bazelbsp-bazelproject

Conversation

@tboernerapex
Copy link
Copy Markdown

Summary

  • When a persisted project view path points to a root-level .bazelproject, override it to use .bazelbsp/.bazelproject if the latter exists — ensuring the plugin-managed file always takes precedence on sync
  • Pre-refresh imported .bazelproject files into IntelliJ's VFS before PSI parsing so that import directives resolve correctly on first open of a large monorepo (without this, the import silently fails and the sync falls back to the entire workspace)
  • Fix conflicting Bazel actions when two java_test targets in the same BUILD package share the same basename: use sibling = raw_jdeps_file in declare_file so each materialized .jdeps file lands next to its source rather than colliding in the package root

Test plan

  • Open a monorepo with .bazelbsp/.bazelproject that imports a package-level .bazelproject; verify sync only indexes the directories listed in the import chain, not the whole workspace
  • Verify that a project with two java_test targets sharing the same simple name in the same package no longer fails with a conflicting actions error during BSP sync
  • Verify that previously persisted root-level project view paths are transparently overridden by .bazelbsp/.bazelproject on next sync

🤖 Generated with Claude Code

tboernerapex and others added 3 commits May 6, 2026 12:09
…roject view path

When a project is reopened after clicking the load bazel project balloon, a previously
persisted projectViewPath (e.g. root.bazelproject from a prior session with a different
project identity) caused RegenerateProjectViewFileContentPreSyncHook to return early
without switching to .bazelbsp/.bazelproject.

Fix by checking if .bazelbsp/.bazelproject exists when the early-return condition fires
and overriding the persisted path if it differs. Also add calculateExistingBazelbspProjectViewFile
to ProjectViewFileUtils so that an existing .bazelbsp/.bazelproject is preferred over
arbitrary root-level .bazelproject files in the selection priority chain.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…arsing

On first open of a monorepo, imported .bazelproject files may not be in
IntelliJ's in-memory VFS cache yet. resolveFromRootOrRelative() only
searches that cache, so unresolved imports silently fell back to the
whole workspace. preRefreshImports() reads import/try_import paths from
raw file text and calls refreshAndFindVirtualFile() to force-load them
before the PSI read action.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When two java_test targets in the same BUILD package share the same
basename (e.g. TypesTest), declare_file("materialized_TypesTest.jdeps")
would place both outputs in the package root, causing a conflicting
actions error. Using sibling=raw_jdeps_file places each materialized
file next to its source, which is unique per target subdirectory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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