Skip to content

VSCode Go Debugger configuration env document is collect? #3358

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

Closed
emahiro opened this issue Apr 23, 2024 · 2 comments
Closed

VSCode Go Debugger configuration env document is collect? #3358

emahiro opened this issue Apr 23, 2024 · 2 comments

Comments

@emahiro
Copy link

emahiro commented Apr 23, 2024

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 or code-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?

vscode-go/docs/debugging.md

Lines 453 to 454 in d0d95ab

| `env` | Environment variables passed to the launched debuggee program. Format as string key:value pairs. Merged with `envFile` and `go.toolsEnvVars` with precedence `env` > `envFile` > `go.toolsEnvVars`.<br/> | <center>_n/a_</center> |
| `envFile` | Absolute path to a file containing environment variable definitions, formatted as string key=value pairs. Multiple files can be specified by provided an array of absolute paths. Merged with `env` and `go.toolsEnvVars` with precedence `env` > `envFile` > `go.toolsEnvVars`. <br/> | <center>_n/a_</center> |

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.

@gopherbot gopherbot added this to the Untriaged milestone Apr 23, 2024
@hyangah
Copy link
Contributor

hyangah commented Apr 23, 2024

That is because debug test does not use launch.json. (#855)
If you trigger debugging with Start Debugging (F5), you will see the launch.json configuration being used.

@hyangah
Copy link
Contributor

hyangah commented Apr 26, 2024

Duplicate of #855

@hyangah hyangah marked this as a duplicate of #855 Apr 26, 2024
@hyangah hyangah closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2024
@golang golang locked and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants