vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

Plugin installs and starts Go language server and related modules in non-Go workspaces

Open Cobinja opened this issue 2 months ago • 0 comments

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.
    • go1.25.1 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • v0.20.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.104.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.50.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    Tools Configuration

Environment

GOBIN: undefined toolsGopath: gopath: /home/lmueller/programmieren/zig/testapp GOROOT: /home/lmueller/golang PATH: /home/lmueller/.bun/bin:/home/lmueller/.symfony5/bin:/home/lmueller/.bun/bin:/home/lmueller/.symfony5/bin:/home/lmueller/.local/bin:/home/lmueller/bin:/home/lmueller/.cargo/bin:/usr/local/bin:/usr/bin:/home/lmueller/.dotnet/tools:/home/lmueller/Android/Sdk/tools:/home/lmueller/Android/Sdk/platform-tools:/home/lmueller/Android/Sdk/emulator:/home/lmueller/Android/Sdk/tools/bin:/home/lmueller/.pub-cache/bin:/home/lmueller/programmieren/depot_tools:/home/lmueller/flutter/bin:/home/lmueller/dextools:/home/lmueller/golang/bin:/home/lmueller/zig:/home/lmueller/Android/Sdk/tools:/home/lmueller/Android/Sdk/platform-tools:/home/lmueller/Android/Sdk/emulator:/home/lmueller/Android/Sdk/tools/bin:/home/lmueller/.pub-cache/bin:/home/lmueller/programmieren/depot_tools:/home/lmueller/flutter/bin:/home/lmueller/dextools:/home/lmueller/golang/bin:/home/lmueller/go/bin:/home/lmueller/zig

Tools

go:	/home/lmueller/golang/bin/go: go version go1.25.1 linux/amd64

gopls:	/home/lmueller/go/bin/gopls	(version: v0.20.0 built with go: go1.25.0)
gotests:	not installed
impl:	not installed
goplay:	not installed
dlv:	/home/lmueller/go/bin/dlv	(version: v1.25.2 built with go: go1.25.1)
staticcheck:	/home/lmueller/go/bin/staticcheck	(version: v0.6.1 built with go: go1.25.0)

Go env

Workspace Folder (testapp): /home/lmueller/programmieren/zig/testapp

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/lmueller/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/lmueller/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2151716327=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/lmueller/programmieren/zig/testapp/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/lmueller/programmieren/zig/testapp'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/lmueller/golang'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/lmueller/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/lmueller/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'

Share the Go related settings you have added/edited

"[go]": { "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.organizeImports": "never" }, }, "go.inferGopath": true,

Describe the bug

In non-Go workspaces, when clicking "create a launch.json file", the Go language server gopls is started, even though there's not a Go file in sight. If gpls is not found, it's even installed inside the non-Go workspace, together with modules that get root ownership so you have to have sudo rights to delete them. This kind of installation is not being done in Go workspaces (even without gopls in $PATH).

Steps to reproduce the behavior:

  1. In a non-Go workspace without a launch.json file, go to the debug tab
  2. Click on 'create a launch.json file'
  3. As per the output tab, gopls is started (after installation if it's not found in $PATH).

Expected behavior

Neither install nor start gopls in non-Go workspaces. As can be seen when comparing the displayed launch options when creating a launch.json file in a Go workspace vs. a non-Go workspace, the extension clearly knows if it's a Go workspace or not.

Cobinja avatar Oct 04 '25 19:10 Cobinja