Does VS code retain some non-environment variables created from other windows?

Viewed 15

I was working in one VS Code window which had the mapping package in OtherProject. Given that I didn't understand what was going on there, I decided to create another directory in another window and create some toy/test code to experiment with. The relative file structure is.

- GoPractice
  - osTest.go
  - assignments.go
- OtherProject
  - src
    - main
      - mapping.go

To continue with probing and trying to understand in OtherProject, I tried to use dlv debug. I couldn't build because I kept getting an error so I decided to start small with files in my GoPractice directory and searched for tutorials and landed on Digital Ocean's. I created a launch.json file but when I launched the debugger, I got this error that refers to mapping that isn't related to the directory I have.

found packages main (assignments.go) and osTest (osTest.go) in C:\Users\User\Documents\GoPractice
strconv.go:6:2: cannot find package "mapping" in any of:
    C:\Program Files\Go\src\mapping (from $GOROOT)
    C:\Users\User\go\src\mapping (from $GOPATH) (exit status 1)

Running go env in the window of:

  • OtherProject I get:
set GOPATH=C:/Users/User/OtherProject
...
set GOROOT=C:\Program Files\Go

I don't understand why the file paths for GOPATH and GOROOT alternate between UNIX and Windows paths from the same command, go env.

  • GoPractice I get:
set GOPATH=C:\Users\User\go
...
set GOROOT=C:\Program Files\Go

So mapping isn't coming from GOPATH even though I modified it in the original window. And here lies my confusion, it seems that there is a link to the original window's bash session but I can't tell what it is as my initial hunch of the environment variable is wrong based on go env output.

Here's my launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "DebugServer",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}",
            "dlvFlags": ["--check-go-version=false"]
        }
    ]
}

I am running on Go 1.19.1 and I needed to suppress the warning for dlv

0 Answers
Related