Skip to content

x/tools/gopls: incorrect rewrite import for "error" #63592

Closed
@pierrre

Description

@pierrre

gopls version

➜  ~ gopls version
golang.org/x/tools/gopls v0.13.2
    golang.org/x/tools/[email protected] h1:Pyvx6MKvatbX3zzZmdGiFRfQZl0ohPlt2sFxO/5j6Ro=

go env

go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/pierre/.cache/go-build'
GOENV='/home/pierre/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/pierre/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/pierre/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/pierre/.gimme/versions/go1.21.3.src'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/pierre/.gimme/versions/go1.21.3.src/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/pierre/Git/pierrre/assert/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1722284209=/tmp/go-build -gno-record-gcc-switches'

What did you do?

My code contains this global variable:

var ErrorStringer = error.Error

error refers to the pre-declared error interface.
So error.Error is the function implemented by this interface that returns a string.

What did you expect to see?

When I save my code in my editor, it should save it without changing my imports.

What did you see instead?

When I save the file, gopls rewrites my imports and adds github.com/coreos/etcd/error, which breaks my code.

Editor and settings

{
	"window.titleBarStyle": "custom",

	"workbench.startupEditor": "none",
	"workbench.settings.editor": "json",
	"workbench.settings.useSplitJSON": true,
	"workbench.list.horizontalScrolling": true,
	"workbench.colorTheme": "Deepdark Material Theme | Full Black Version",

	"editor.fontFamily": "Monospace",
	"editor.fontSize": 12,
	"editor.lineHeight": 14,
	"editor.fontLigatures": "'ccmp' off", // Fix for https://github.com/microsoft/vscode/issues/106583
	"editor.renderWhitespace": "all",
	"editor.wordWrap": "on",
	"editor.insertSpaces": false,
	"editor.smoothScrolling": true,
	"editor.minimap.enabled": false,
	"editor.minimap.autohide": true,
	"editor.minimap.renderCharacters": false,
	"editor.inlineSuggest.enabled": true,
	"editor.stickyScroll.enabled": true,

	"files.enableTrash": false,
	"files.autoSave": "onFocusChange",
	"files.trimTrailingWhitespace": true,
	"files.insertFinalNewline": true,
	"files.trimFinalNewlines": true,
	"files.associations": {
		"Dockerfile*": "dockerfile"
	},

	"terminal.integrated.fontSize": 12,
	"terminal.integrated.scrollback": 100000,

	"search.showLineNumbers": true,

	"git.autofetch": true,
	"git.allowForcePush": true,
	"git.confirmForcePush": false,
	"git.enableSmartCommit": true,
	"git.pruneOnFetch": true,

	"redhat.telemetry.enabled": false,

	"github.copilot.enable": {
		"*": true,
		"yaml": true,
		"plaintext": true,
		"markdown": true
	},

	"go.buildFlags": [
		"-gcflags=-e"
	],
	"go.testOnSave": true,
	"go.testExplorer.showOutput": false,
	"go.testFlags": [
		"-v",
		"-fullpath",
		"-short"
	],
	"go.testEnvVars": {
		"ASSERTAUTO_UPDATE": "true",
		"UPDATE_GOLDENS": "true",
	},
	"go.coverOnSave": true,
	"go.coverageDecorator": {
		"type": "gutter",
		"coveredGutterStyle": "blockgreen",
		"uncoveredGutterStyle": "blockred",
		"coveredHighlightColor": "rgba(0,255,0,0.08)",
		"uncoveredHighlightColor": "rgba(255,0,0,0.08)"
	},
	"go.lintOnSave": "package",
	"go.lintTool": "golangci-lint",
	"go.lintFlags": [
		"--fix"
	],
	"gopls": {
		"verboseOutput": true,
		"ui.completion.usePlaceholders": true,
		"ui.codelenses": {
			"gc_details": true
		},
		"ui.semanticTokens": true,
	},
	"go.toolsManagement.autoUpdate": true,
	"go.toolsEnvVars": {
		"GOPRIVATE": "",
		"GOGC":"10",
	},
	/*
	"go.inlayHints.assignVariableTypes": true,
	"go.inlayHints.compositeLiteralFields": true,
	"go.inlayHints.compositeLiteralTypes": true,
	"go.inlayHints.constantValues": true,
	"go.inlayHints.functionTypeParameters": true,
	"go.inlayHints.parameterNames": true,
	"go.inlayHints.rangeVariableTypes": true,
	*/
	"[python]": {
		"editor.formatOnType": true
	},
}

Logs

[Info  - 15:34:21] 2023/10/17 15:34:21 fixImports(filename="/home/pierre/Git/pierrre/assert/error.go"), abs="/home/pierre/Git/pierrre/assert/error.go", srcDir="/home/pierre/Git/pierrre/assert" ...

[Info  - 15:34:21] 2023/10/17 15:34:21 loading package names for 48 packages

[Info  - 15:34:21] 2023/10/17 15:34:21 done loading package names for 48 packages

[Info  - 15:34:21] 2023/10/17 15:34:21 error candidate 1/1: github.com/coreos/etcd/error in /home/pierre/go/pkg/mod/github.com/coreos/[email protected]+incompatible/error

[Info  - 15:34:21] 2023/10/17 15:34:21 loading exports in dir /home/pierre/go/pkg/mod/github.com/coreos/[email protected]+incompatible/error (seeking package error)

[Info  - 15:34:23] 2023/10/17 15:34:23 fixImports(filename="/home/pierre/Git/pierrre/assert/error.go"), abs="/home/pierre/Git/pierrre/assert/error.go", srcDir="/home/pierre/Git/pierrre/assert" ...

[Info  - 15:34:23] 2023/10/17 15:34:23 loading package names for 48 packages

[Info  - 15:34:23] 2023/10/17 15:34:23 done loading package names for 48 packages

[Info  - 15:34:23] 2023/10/17 15:34:23 loading exports in dir /home/pierre/go/pkg/mod/github.com/coreos/[email protected]+incompatible/error (seeking package error)

[Info  - 15:34:23] 2023/10/17 15:34:23 error candidate 1/1: github.com/coreos/etcd/error in /home/pierre/go/pkg/mod/github.com/coreos/[email protected]+incompatible/error

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/imports

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions