intellij icon indicating copy to clipboard operation
intellij copied to clipboard

Current directory not correctly set when debugging Go

Open Enrico2 opened this issue 4 years ago • 5 comments

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

Enrico2 avatar Dec 03 '21 22:12 Enrico2

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

hansonap avatar Jan 12 '22 19:01 hansonap

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.

alice-ks avatar Jan 21 '22 10:01 alice-ks

@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)?

JamesRTaylor avatar Aug 07 '22 04:08 JamesRTaylor

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

@mai93 FYI.

alice-ks avatar Aug 08 '22 07:08 alice-ks

@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?

JamesRTaylor avatar Aug 09 '22 01:08 JamesRTaylor

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.

sgowroji avatar Oct 14 '22 04:10 sgowroji

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

JamesRTaylor avatar Oct 24 '22 21:10 JamesRTaylor

I had same issue, Please change go.mod location

mhthrh avatar Jan 02 '23 15:01 mhthrh

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:

  • Figure out if pointing the script to the runfiles directory is the right thing to do, and make the script cd there before running. To test this, we could just make the change, and see if dlv picks up the right source files in Debug mode.
  • Have a mechanism to check in experiment flags, maybe as fields in the .bazelproject files.

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

blorente avatar Apr 20 '23 09:04 blorente

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] avatar Oct 21 '23 01:10 github-actions[bot]

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!

github-actions[bot] avatar Nov 04 '23 01:11 github-actions[bot]