Description
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. - Run
gopls -v version
to get version of Gopls from the VS Code integrated terminal. - Run
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders. - Check your installed extensions to get the version of the VS Code Go extension
- Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Tools
command.
$ go version
go version go1.22.2 darwin/arm64
$ code -v
1.88.1
e170252f762678dec6ca2cc69aba1570769a5d39
arm64
$ gopls -v
golang.org/x/tools/gopls v0.15.3
- Go extension version:
v0.41.3
- Located Configured Go Tools
## Tools
go: /usr/local/go/bin/go: go version go1.22.2 darwin/amd64
gopls: ~/go/bin/gopls (version: v0.15.3 built with go: go1.22.2)
gotests: ~/go/bin/gotests (version: v1.6.0 built with go: go1.22.2)
gomodifytags: ~/go/bin/gomodifytags (version: v1.16.0 built with go: go1.22.2)
impl: ~/go/bin/impl (version: v1.1.0 built with go: go1.22.2)
goplay: ~/go/bin/goplay (version: v1.0.0 built with go: go1.22.2)
dlv: ~/go/bin/dlv (version: v1.22.1 built with go: go1.22.2)
golangci-lint: ~/go/bin/golangci-lint (version: v1.57.2 built with go: go1.22.2)
## Go env
Workspace Folder (go-sandbox): ~/src/adhoc/go-sandbox
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='~/Library/Caches/go-build'
GOENV='~/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='~/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='~/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='~/src/adhoc/go-sandbox/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9w/3rt1brls67l_mv2m7_r5djcc0000gn/T/go-build2558003629=/tmp/go-build -gno-record-gcc-switches -fno-common'
Share the Go related settings you have added/edited
Run Preferences: Open Settings (JSON)
command to open your settings.json file.
Share all the settings with the go.
or ["go"]
or gopls
prefixes.
{
"[go.mod]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnSave": true
},
"[go]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnSave": true,
"editor.insertSpaces": false,
"editor.suggest.snippetsPreventQuickSuggestions": false
},
"[go][go.mod]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"go.addTags": {
"options": "",
"promptForTags": true,
"tags": "db,json",
"transform": "snakecase"
},
"go.diagnostic.vulncheck": "Imports",
"go.editorContextMenuCommands": {
"addImport": true,
"addTags": true,
"benchmarkAtCursor": false,
"debugTestAtCursor": true,
"fillStruct": false,
"generateTestForFile": false,
"generateTestForFunction": true,
"generateTestForPackage": false,
"playground": true,
"removeTags": false,
"testAtCursor": true,
"testCoverage": true,
"testFile": false,
"testPackage": false,
"toggleTestFile": true
},
"go.formatFlags": [
"-w"
],
"go.inlayHints.assignVariableTypes": false,
"go.inlayHints.compositeLiteralFields": true,
"go.inlayHints.compositeLiteralTypes": false,
"go.inlayHints.constantValues": false,
"go.inlayHints.functionTypeParameters": false,
"go.inlayHints.parameterNames": false,
"go.inlayHints.rangeVariableTypes": false,
"go.installDependenciesWhenBuilding": true,
"go.lintTool": "golangci-lint",
"go.toolsManagement.autoUpdate": true,
"go.useLanguageServer": true,
"gopls": {
"allowImplicitNetworkAccess": false,
"analyses": {
"fillreturns": true,
"fillstruct": true,
"httpresponse": true,
"ST1005": false,
"unmarshal": true,
"unreachable": true,
"unusedparams": true,
"unusedwrite": true
},
"annotations": {
"bounds": true,
"escape": true,
"inline": true,
"nil": true
},
"buildFlags": [],
"codelenses": {
"gc_details": true,
"generate": true,
"regenerate_cgo": false,
"tidy": true,
"upgrade_dependency": false,
"vendor": true
},
"completionBudget": "100ms",
"diagnosticsDelay": "250ms",
"directoryFilters": [],
"env": {},
"hoverKind": "FullDocumentation",
"importShortcut": "Both",
"linksInHover": true,
"linkTarget": "pkg.go.dev",
"matcher": "Fuzzy",
"semanticTokens": true,
"symbolMatcher": "caseSensitive",
"symbolStyle": "package",
"ui.completion.experimentalPostfixCompletions": true,
"usePlaceholders": true,
"verboseOutput": false
}
}
Describe the bug
A clear and concise description of what the bug.
A clear and concise description of what you expected to happen.
I wanted to setup dubugger with configuration docs and set environment value at launch.json
.
But this is not reflected and when I set up environment values via go.testsEnvVars
these are reflected.
Is the configuration docs correct?
If my sequence to reproduce is light, can I update the configuration docs below?
Lines 453 to 454 in d0d95ab
Steps to reproduce the behavior:
The minimum code is below.
// main.go
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("Hello World")
}
func Echo(str string) {
env1 := os.Getenv("ENV1")
fmt.Println("ENV1: ", env1)
env2 := os.Getenv("ENV2")
fmt.Println("ENV2: ", env2)
fmt.Println(str)
}
// main_test.go
package main
import (
"testing"
)
func TestEcho(t *testing.T) {
Echo("Hello World")
}
Not reflected case 1: set env at launch.json
Setup launch.json below.
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {
"ENV1": "test1",
"ENV2": "test2"
}
}
]
}
Run dubug test
, the output was below.
Starting: ~/go/bin/dlv dap --listen=127.0.0.1:50448 --log-dest=3 from ~/src/adhoc/go-sandbox
DAP server listening at: 127.0.0.1:50448
Type 'dlv help' for list of commands.
ENV1:
ENV2:
Hello World
PASS
Process 92287 has exited with status 0
Detaching
Not reflected case 2: add envFile to the root dir.
Set this envFile, the same directory with go.mod.
ENV1=test1
ENV2=test2
Run dubug test
, the output was below.
Starting: ~/go/bin/dlv dap --listen=127.0.0.1:50448 --log-dest=3 from ~/src/adhoc/go-sandbox
DAP server listening at: 127.0.0.1:50448
Type 'dlv help' for list of commands.
ENV1:
ENV2:
Hello World
PASS
Process 92287 has exited with status 0
Detaching
Reflected Case: set go.testsEnvVars
Set env vars at workspace setting.json (or user setting.json)
{
"go.testEnvVars": {
"ENV1": "test1",
"ENV2": "test2"
}
}
Run dubug test
, the output was below.
Starting: ~/go/bin/dlv dap --listen=127.0.0.1:50681 --log-dest=3 from ~/src/adhoc/go-sandbox
DAP server listening at: 127.0.0.1:50681
Type 'dlv help' for list of commands.
ENV1: test1
ENV2: test2
Hello World
PASS
Process 96791 has exited with status 0
Detaching
Screenshots or recordings
If applicable, add screenshots or recordings to help explain your problem.