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

envFile setting for debugger does not default to ${workspaceFolder}/.env #2128

Closed
Iristyle opened this issue Mar 21, 2022 · 3 comments
Closed
Labels
debug/config Issues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test Debug Issues related to the debugging functionality of the extension. FrozenDueToAge
Milestone

Comments

@Iristyle
Copy link

Iristyle commented Mar 21, 2022

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.

go version go1.17.6 linux/amd64

  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.8.1
    golang.org/x/tools/gopls@v0.8.1 h1:q5nDpRopYrnF4DN/1o8ZQ7Oar4Yd4I5OtGMx5RyV2/8=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.10-0.20220315142906-0c66750444e6 h1:AOqgMGxa5hFduIlFkKEX87HoRPO9wjyfhqf1yqwybeg=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.17.6
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
1.65.2
c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
x64
  • Check your installed extensions to get the version of the VS Code Go extension

v0.32.0

  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: /home/iristyle/projects/go/bin
toolsGopath: 
gopath: /home/iristyle/projects/go
GOROOT: /usr/local/go-1.17
PATH: /usr/local/go-1.17/bin:/home/iristyle/.vscode-server/bin/c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1/bin/remote-cli:/home/iristyle/.krew/bin:/home/iristyle/.local/bin:/home/iristyle/.krew/bin:/home/iristyle/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Python27/:/mnt/c/Python27/Scripts:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/ethan/AppData/Local/Microsoft/WindowsApps:/snap/bin:/home/iristyle/projects/go/bin
PATH (vscode launched with): /home/iristyle/.vscode-server/bin/c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1/bin/remote-cli:/home/iristyle/.krew/bin:/home/iristyle/.local/bin:/home/iristyle/.krew/bin:/home/iristyle/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Python27/:/mnt/c/Python27/Scripts:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/ethan/AppData/Local/Microsoft/WindowsApps:/snap/bin:/usr/local/go-1.17/bin:/home/iristyle/projects/go/bin

	go:	/usr/local/go-1.17/bin/go: go version go1.17.6 linux/amd64

	go-outline:	/home/iristyle/projects/go/bin/go-outline	(version: v0.0.0-20210608161538-9736a4bde949 built with go: go1.17.6)
	gotests:	/home/iristyle/projects/go/bin/gotests	(version: v1.6.0 built with go: go1.17.6)
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/home/iristyle/projects/go/bin/dlv	(version: v1.8.2 built with go: go1.17.6)
	staticcheck:	/home/iristyle/projects/go/bin/staticcheck	(version: v0.2.2 built with go: go1.17.6)
	gopls:	/home/iristyle/projects/go/bin/gopls	(version: v0.8.1 built with go: go1.17.6)

go env
Workspace Folder (data-ingestion): /home/iristyle/source/data-ingestion
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN="/home/iristyle/projects/go/bin"
	GOCACHE="/home/iristyle/.cache/go-build"
	GOENV="/home/iristyle/.config/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/home/iristyle/projects/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="linux"
	GOPATH="/home/iristyle/projects/go"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/usr/local/go-1.17"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/usr/local/go-1.17/pkg/tool/linux_amd64"
	GOVCS=""
	GOVERSION="go1.17.6"
	GCCGO="gccgo"
	AR="ar"
	CC="gcc"
	CXX="g++"
	CGO_ENABLED="1"
	GOMOD="/home/iristyle/source/data-ingestion/go.mod"
	CGO_CFLAGS="-g -O2"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-g -O2"
	CGO_FFLAGS="-g -O2"
	CGO_LDFLAGS="-g -O2"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2166652709=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.

    "go.testEnvFile": "${workspaceFolder}/.env",
    "go.testFlags": ["-v"],
    "go.delveConfig": {
        "showGlobalVariables": true,
        "showLog": true
    },
    "go.toolsManagement.autoUpdate": true,

Describe the bug

Documentation at https://github.com/golang/vscode-go/blob/master/docs/debugging.md#launchjson-attributes states that envFile value defaults to ${workspaceFolder}/.env. However, I found this to not be true. To properly set env vars (when running the debugger via F5 or with the green play button in the RUN AND DEBUG VSCode Panel), I found it necessary to define a launch.json containing

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run The Jewels",
            "envFile": "${workspaceFolder}/.env"
        }
    ]
}

Steps to reproduce the behavior:

  1. Create a file called .env in the root of the workspace and and make it contain
FOO=bar
  1. Put the cursor inside a function in a XXX_test.go file
  2. Press F9 to to set a breakpoint on the first line of the function
  3. Press F5 to run the application / launch the debugger
  4. Add a watch for `call os.Getenv("FOO")
  5. Notice there is no value set for the FOO environment variable

Also note that if you click the debug test code lens link that hovers over a specific test, the envFile value from settings.json is properly consumed and used for the tests. So there's also a bit of inconsistency there. I would expect the following precedence when hitting F5 to run / launch the debugger:

  • default of ${workspaceFolder}/.env when nothing defined in settings.json or launch.json
  • go.testEnvFile if defined in settings.json
  • envFile if defined in launch.json

Screenshots or recordings

This is pretty trivial to reproduce, but if you need screenshots, let me know!

@gopherbot gopherbot added this to the Untriaged milestone Mar 21, 2022
@findleyr findleyr added the Debug Issues related to the debugging functionality of the extension. label Mar 25, 2022
@polinasok
Copy link
Contributor

@Iristyle
Some quick thoughts. There is indeed inconsistency with debug test. Please see #855 and #860.
The documentation that you referenced refers to launch.json settings, not settings.json. The two sets of flags do have a lot in common, but are not the same. I will take a look at this discrepancy and report back. If they cannot be easily addressed/explained, at the very least we should be covered in our docs or even better hoover descriptions.

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/395795 mentions this issue: docs/debugging.md: fix the default of envFile

@Iristyle
Copy link
Author

@polinasok thanks for the response. Yes, I understand that launch.json and settings.json are different / have different settings. My bigger point was that I think it's desirable to always fallback to settings.json global settings where possible, rather than requiring that each project have a separately defined launch.json.

As for the change that landed - I think it would have been better to implement the default of ${workspaceFolder}/.env than to remove it. Having this default prevents having to add a launch.json to each project just for the sake of consuming environment variables.

Thanks!

@polinasok polinasok added the debug/config Issues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test label Mar 30, 2022
@golang golang locked and limited conversation to collaborators Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug/config Issues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test Debug Issues related to the debugging functionality of the extension. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

4 participants