Skip to content

x/tools/gopls: deprecate the "allowModfileModifications" setting #56570

@JensSkipr

Description

@JensSkipr

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.18.7 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.10.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.73.0 (8fa188b2b301d36553cbc9ce1b0a146ccb93351f)
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.35.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
      GOBIN: undefined
      toolsGopath: /home/skipr/go
      gopath: /home/skipr/go
      GOROOT: /usr/lib/golang
      PATH: /home/skipr/.local/bin:/home/skipr/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/go/bin:/home/skipr/go/bin:/usr/local/go/bin:/home/skipr/go/bin
    
      go:    /usr/bin/go: go version go1.18.7 linux/amd64
    
      gotests:    /home/skipr/go/bin/gotests    (version: v1.6.0 built with go: go1.18.2)
      gomodifytags:    /home/skipr/go/bin/gomodifytags    (version: v1.16.0 built with go: go1.18.2)
      impl:    /home/skipr/go/bin/impl    (version: v1.1.0 built with go: go1.18.2)
      goplay:    /home/skipr/go/bin/goplay    (version: v1.0.0 built with go: go1.18.2)
      dlv:    /home/skipr/go/bin/dlv    (version: v1.8.3 built with go: go1.18.2)
      staticcheck:    /home/skipr/go/bin/staticcheck    (version: v0.3.2 built with go: go1.18.2)
      gopls:    /home/skipr/go/bin/gopls    (version: v0.10.1 built with go: go1.18.7)
    
      go env
      Workspace Folder (workspace): /home/skipr/Dev/workspace
      GO111MODULE="auto"
      GOARCH="amd64"
      GOBIN=""
      GOCACHE="/home/skipr/.cache/go-build"
      GOENV="/home/skipr/.config/go/env"
      GOEXE=""
      GOEXPERIMENT=""
      GOFLAGS=""
      GOHOSTARCH="amd64"
      GOHOSTOS="linux"
      GOINSECURE=""
      GOMODCACHE="/home/skipr/go/pkg/mod"
      GONOPROXY=""
      GONOSUMDB=""
      GOOS="linux"
      GOPATH="/home/skipr/go"
      GOPRIVATE=""
      GOPROXY="direct"
      GOROOT="/usr/lib/golang"
      GOSUMDB="off"
      GOTMPDIR=""
      GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
      GOVCS=""
      GOVERSION="go1.18.7"
      GCCGO="gccgo"
      GOAMD64="v1"
      AR="ar"
      CC="gcc"
      CXX="g++"
      CGO_ENABLED="1"
      GOMOD="/home/skipr/Dev/workspace/go.mod"
      GOWORK="/home/skipr/Dev/workspace/go.work"
      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-build3105188839=/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.
Share all the settings with the go. or ["go"] or gopls prefixes.

{
  "go.buildTags": "integration",
  "go.toolsGopath": "~/go",
  "go.toolsManagement.autoUpdate": true,
  "gopls": {
    "build.allowModfileModifications": true
  },
}

Describe the bug

I faced the issue in a large project, but was able to reproduce minimally following: https://go.dev/doc/tutorial/workspaces

Once you add a Golang Workspace by creating a go.work file, every go.mod file returns error: no go.mod file found in /home/skipr/Dev/workspace go list. Where /home/skipr/Dev/workspace is the root of the workspace.
image

Steps to reproduce the behavior:

  1. Start with a blank directory
  2. Create a folder hello
  3. Start a Go module using go mod init example.com/hello (run inside hello directory)
  4. Create hello/main.go containing
package main

func main() {}
  1. Start a Go workspace using go work init ./hello (run inside root/workspace directory)
  2. Open hello/go.mod

Adding a go.mod to the root doesn't solve the issue. Nor adding . to the go.work. When doing the latter, you even get the same error in the root go.mod:
image
image

Screenshots or recordings

See above

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/metadataIssues related to metadata loading in gopls

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions