golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.85k stars 738 forks source link

Add Bazel Run/Debug Support to GoTestRunner #2539

Open mnoah1 opened 1 year ago

mnoah1 commented 1 year ago

Is your feature request related to a problem? Please describe. Our team uses Bazel with our Go projects. Currently, this extension is able to discover tests but the run/debug functionalities do not work correctly since they run go commands instead of Bazel.

Describe the solution you'd like Allow customizable user option to use Bazel to run/debug tests. Override a few of the methods in GoTestRunner with an alternate implementation that runs the Bazel version of the needed command. Add parsing of Bazel build events to report pass/fail status.

Describe alternatives you've considered 1) Add this to the Bazel for VS Code extension - not ideal because that extension is more focused on Starlark / BUILD file creation, and does not offer language-specific Go support or integration with VS Code's testing API. 2) Create a separate extension that depends on several of the classes in this vs-code extension, and sets up an alternate version of the GoTestExplorer with the missing Bazel functionality. Users that wish to use this functionality could then turn off the test explorer setting on this extension, then run the separate extension side-by-side with this one. Not ideal due to the overhead of maintaining a separate extension / project where only a few areas of functionality actually differ.

Additional context Would also be open to any other general feedback about how other teams are supporting Run/Debug functionality in the IDE for Bazel users (other than command line, which is our current state).

jamalc commented 1 year ago

/cc @hyangah for any feedback on supporting run/debug for Bazel.

mnoah1 commented 1 year ago

@hyangah @jamalc - Just wanted to see if you have any feedback on this issue? We have a working version on our fork and wanted to confirm that you would be interested in having me submit a PR?

oakad commented 1 year ago

Interestingly enough, this need not be a bazel specific thing. Rather, vscode-go could be made a somewhat more flexible:

  1. vscode-go could add an ability to run a command via launch.json config, while having a desired DAP address in a well known environment variable. It should also be able to wait a little for the server to become available at the specified DAP address (instead of bailing out immediately, like it is doing now). This will allow people to define simple actions of the form bazel run run_under="dlv -l $MY_DAP_ADDR --headless exec" -c dbg //bazel/target -- args. Should not be difficult to implement, will take care of the most pressing need.
  2. Symbol path substitution: also should not be too big of a deal. bazel info output_base will return a path for the bazel build dir. vscode-go should simply provide a hook allowing to invoke this sort of pre-launch task and an ability to produce a bunch of substitute-path items out of it.

To my opinion, making vscode-go work with bazel like build system does not seem like a major undertaking and it's a pity something like this was not done already.