Skip to content

feat: add Explorer context menu to add directory to Bazel project scope#32

Merged
monkey666-cr merged 1 commit into
monkey666-cr:mainfrom
dang-nguyen-cp:feat/add-directory-context-menu
Jun 3, 2026
Merged

feat: add Explorer context menu to add directory to Bazel project scope#32
monkey666-cr merged 1 commit into
monkey666-cr:mainfrom
dang-nguyen-cp:feat/add-directory-context-menu

Conversation

@dang-nguyen-cp

@dang-nguyen-cp dang-nguyen-cp commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add "Bazel: Add to Project" context menu item when right-clicking a directory in VS Code Explorer
  • Clicking the item appends the directory to .bazelproject (or creates the file if absent), which triggers the existing file watcher to reimport with the expanded scope
  • Validates that a BUILD or BUILD.bazel file exists in the selected directory before modifying .bazelproject

Changes

  • vscode-extension/package.json: register bazel-jdt.addDirectoryToProject command and explorer/context menu contribution (group bazel-jdt@1, when: explorerResourceIsFolder)
  • vscode-extension/src/bazelproject.ts: add addDirectoryToBazelproject() — inserts directory into existing directories: section or creates a minimal .bazelproject
  • vscode-extension/src/commands.ts: add registerAddDirectoryCommand() — validates BUILD file exists, computes relative path, calls addDirectoryToBazelproject
  • vscode-extension/src/extension.ts: register new command in both activation paths (with and without existing .bazelproject)

Test plan

  • Right-click a directory with a BUILD file → "Bazel: Add to Project" appears in context menu under a bazel-jdt group
  • Click → directory is appended to .bazelproject, reimport triggers automatically
  • Debug a class from the newly added directory — no "Main class does not exist" error
  • Right-click a directory without BUILD file → warning message shown, no change to .bazelproject
  • Right-click a directory already in scope → "already in scope" info message, no duplicate entry

🤖 Generated with Claude Code

Right-clicking a directory in VS Code Explorer now shows "Bazel: Add to
Project" under a dedicated bazel-jdt group. The action appends the
directory to the existing .bazelproject (or creates one), which triggers
the file watcher to reimport with the expanded scope.

Also fix handleImportProject() to create Eclipse projects for newly
discovered targets — previously only BazelProjectImporter (run once at
JDT.LS startup) created projects, so targets from a scope-change reimport
were never registered with JDT, causing "Main class does not exist" errors
when debugging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dang-nguyen-cp dang-nguyen-cp force-pushed the feat/add-directory-context-menu branch from 09c9cf9 to ff6cb56 Compare June 2, 2026 03:30

@runchen0919 runchen0919 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@monkey666-cr monkey666-cr merged commit 5363135 into monkey666-cr:main Jun 3, 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.

3 participants