bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://ij.bazel.build/
Apache License 2.0
763 stars 305 forks source link

Current directory not correctly set when debugging Go #3097

Closed Enrico2 closed 1 year ago

Enrico2 commented 2 years ago

This issue was reported here a while ago: https://github.com/bazelbuild/intellij/issues/319 I'm seeing the exact behavior again, in IntelliJ ultimate, with Golang.

bazel: 2021.11.09.0.2-api-version-212 image

Specifically, when using "Run" on a go_binary target I see

os.Getwd():
/private/var/tmp/_bazel_ranmagen/68a892d02d10473428c53fc867ebfbd4/execroot/coinbazel/bazel-out/darwin-fastbuild/bin/xyz/xyz/xyz/server.runfiles/coinbazel

But when using "Debug" I see

os.Getwd():
/Users/ranmagen/src/monorepo
hansonap commented 2 years ago

I am seeing the exact same issue as #319 with CLion 2021.2.3 (Build #CL-212.5457.51, built on October 14, 2021)

alice-ks commented 2 years ago

This is not exactly the same issue as #319. #319 was about debugging in C++. What you're describing is for Go debugging.

For Go debugging, there are two code paths. The default one uses a script file generated by Bazel. That code path uses the workspace directory as working directory.

An alternative code path directly runs the test. That code path sets the working directory to the 'runfiles' directory. This alternative code path doesn't support args, though, and hence isn't used by default.

Before we update the working directory for the script file version, we'd need to figure out what would be the right working directory for that case. In the meantime, you can use a workaround to enable the alternative code path. Do so by creating ~/.intellij-experiments (if that file doesn't exist for you) and specify blaze.go.script.path.enabled.2=false.

JamesRTaylor commented 2 years ago

@alice-ks, your workaround isn't working for me. I'm using GoLand 2022.1.4 on macOS with the latest bazel plugin. Is there somewhere I can put this setting in a project file that I could check-in instead (so I don't have to ask everyone on my team to make a change)?

alice-ks commented 2 years ago

@JamesRTaylor I'm not working on the project anymore.

@mai93 FYI.

JamesRTaylor commented 2 years ago

@mai93 - would it be possible to switch the default to use the alternate code path so that the debugger and runtime use the same current working directory, essentially change the default value of this variable to false?

sgowroji commented 2 years ago

Hello @JamesRTaylor, Thank you for sharing the above details. Would you be interested in sharing the above changes in a PR. I Could arrange a review from google team.

JamesRTaylor commented 2 years ago

Hi @sgowroji - here you go: https://github.com/bazelbuild/intellij/pull/4043

mhthrh commented 1 year ago

I had same issue, Please change go.mod location

blorente commented 1 year ago

As @alice-ks said, I don't think flipping the experiment flag default is a good idea, for the reasons outlined in https://github.com/bazelbuild/intellij/pull/4043#issuecomment-1516042850.

We could instead:

I don't have time to implement either (hence the P3 tag), but I'd love to review PRs for it.

github-actions[bot] commented 1 year ago

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

github-actions[bot] commented 1 year ago

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!