Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism to automatically infer current file for build / test #4

Open
dbarnett opened this issue Jan 13, 2017 · 2 comments
Open

Mechanism to automatically infer current file for build / test #4

dbarnett opened this issue Jan 13, 2017 · 2 comments

Comments

@dbarnett
Copy link
Contributor

It would be nice if the bazel plugin could infer "the target for the current file" automatically so you could just invoke :Bazel build or :Bazel test as a shortcut for "build this file's build target" and "run the test defined in this file".

@dbarnett
Copy link
Contributor Author

Also inferring "current test method" would be good, but we can ignore that for v1 since there's some complexity getting that right and exposing it cleanly as a feature.

@manneorama
Copy link

@dbarnett
I don't know vimscript nearly well enough to make a pull request (also, i use Vundle which this plugin doesn't seem to support), but I made these functions for doing just that in my .vimrc.

function! BazelGetCurrentBufTarget()
    let bazel_file_label=system("bazel query " . bufname("%") . " --color no --curses no --noshow_progress | tr -d '[:space:]'")
    let bazel_file_package=split(bazel_file_label, ":")[0]
    let g:current_bazel_target=system("bazel query \"attr('srcs', " . bazel_file_label . ", " . bazel_file_package . ":*)\" --color no --curses no --noshow_progress | tr -d '[:space:]'")
endfunction

function! BazelBuildHere()
    :call  BazelGetCurrentBufTarget()
    :execute '!bazel build ' . g:current_bazel_target
endfunction

function! BazelTestHere()
    :call BazelGetCurrentBufTarget()
    :execute '!bazel test ' . g:current_bazel_target
endfunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants