Use bazel query to provide completion on target names - #79
Conversation
… with Bazel. {1b3a6b2fd5e0}
|
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). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
Would you mind splitting up these two changes into separate PRs? They seem pretty unrelated to each other. |
|
|
||
| (defun bazel-build--read-target (prompt &optional filename) | ||
| "Read a target name for the given or current file or dired directory name." | ||
| ;; Bazel query invocation can be slow, issue a message. |
There was a problem hiding this comment.
I think especially for large repositories or when the Bazel server needs to be restarted, this approach can be too slow for an interactive command. I think there should at least be a customization option to switch between the precise-but-slow bazel query method and a faster-but-imprecise method like the one used before.
| (defvar bazel-query-args '("query" "--noblock_for_lock") | ||
| "Bazel query subcommand and arguments.") | ||
|
|
||
| (defvar bazel-run-commands-from-root nil |
There was a problem hiding this comment.
I'd suggest making this a customization option and instead of a (non-extensible) Boolean provide choices such as workspace-root and default-directory.
| (if (/= status 0) | ||
| (with-temp-buffer | ||
| (insert-file-contents stderr-file) | ||
| (error "Error running command: %s" (buffer-string))))))) |
There was a problem hiding this comment.
I don't think the entire standard error should be part of the error message, since it can be arbitrarily long.
I'd also suggest singaling a specific error symbol, so that callers can catch and handle the error.
There was a problem hiding this comment.
What summarization would you like to see?
There was a problem hiding this comment.
So, looking at this "holistically", I'd probably just return nil here and handle that accordingly in the completion prompt. This isn't a critical condition in the context of completion, as the user can always enter the target manually, so we souldn't fail hard here or pop up a warning.
| (let* ((default-directory dirname) | ||
| (results (split-string | ||
| (bazel-query "kind('.*rule', ':*')"))) | ||
| (package (car (split-string (car results) ":")))) |
There was a problem hiding this comment.
This will fail if there are no rules in the current package
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
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: