vscode-bazel icon indicating copy to clipboard operation
vscode-bazel copied to clipboard

Add "Run" command to binary targets in Codelens

Open mawallace opened this issue 4 years ago • 0 comments
trafficstars

Given a binary rule, for example

rust_binary(
    name = "hello_word",
    srcs = ["main.rs"],
)

there is no option to run this Bazel target in Codelens. Codelens only offers build for this target (see image) binary only offers

It would be helpful to add the capability to run binary targets using Codelens.

This should be a fairly straightforward change. Here is the current code for adding Codelens commands: https://github.com/bazelbuild/vscode-bazel/blob/12c20773c5bbbdbbd30cc393c414622059c05537/src/codelens/bazel_build_code_lens_provider.ts#L116-L135

I think all we'd have to do is to conditionally add a run command for targets that end in _binary.

As an aside, it seems useful to add build and test for _test targets, so the code would end up more like:

// add build command
if (ruleClass.endsWith("_binary") {
  // add run command
}
if (ruleClass.endsWith("_test") || ruleClass === "test_suite") {
  // add test command
}

mawallace avatar Oct 22 '21 19:10 mawallace