Skip to content

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

@Iristyle

Description

@Iristyle

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/[email protected] h1:q5nDpRopYrnF4DN/1o8ZQ7Oar4Yd4I5OtGMx5RyV2/8=
    github.com/BurntSushi/[email protected] h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/[email protected] h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/[email protected] h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
    golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/[email protected] h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/[email protected] h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/[email protected] h1:AOqgMGxa5hFduIlFkKEX87HoRPO9wjyfhqf1yqwybeg=
    golang.org/x/[email protected] h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/[email protected] h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
    mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/[email protected] 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DebugIssues related to the debugging functionality of the extension.FrozenDueToAgedebug/configIssues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions