emacs-bazel-mode icon indicating copy to clipboard operation
emacs-bazel-mode copied to clipboard

Use bazel query to provide completion on target names

Open blais opened this issue 5 years ago • 4 comments

This CL enhances the build commands by automatically inferring the name of the target from the current buffer. If multiple targets match, completion is provided with the list.

This also changes the commands to run from the root of the workspace with a cd before the command name. There's an option to turn that behavior on. I think this is the most natural way to work with bazel (cwd at root of workspace).

If the current buffer is

  • A file, bazel query is used to figure out the name of the target that the file is a src of.
  • A directory (dired mode), the list of targets in the package is provided with default :all
  • A BUILD file, the targets in the package as well.

Note that I did not add unit tests. I did check locally on all three files that it works. This PR for your consideration. I'll be running this on my box for a while. Happy to move to a branch if you prefer to work that way (let me know0.

Some further improvements are possible for the future:

  • Adding an option to disable this might be useful, as it can be a little slow.
  • When computing the completion list over a file, it may be a good idea to actually fetch it for the enclosing package, so that if the user wants to edit it there's completion from packages nearby.
  • If a single target matches the file, maybe the command should just run. Using a prefix argument to allow the user to edit the target before running, perhaps.

blais avatar Jun 10 '20 04:06 blais

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

googlebot avatar Jun 10 '20 04:06 googlebot

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

googlebot avatar Jun 10 '20 04:06 googlebot

@googlebot I signed it!

blais avatar Jun 10 '20 04:06 blais

This CL enhances the build commands by automatically inferring the name of the target from the current buffer. If multiple targets match, completion is provided with the list.

This also changes the commands to run from the root of the workspace with a cd before the command name.

Would you mind splitting up these two changes into separate PRs? They seem pretty unrelated to each other.

phst avatar Jul 18 '20 17:07 phst