Skip to content
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

x/tools/gopls: improve method rename functionality in face of errors #71908

Open
danvolchek opened this issue Feb 23, 2025 · 3 comments
Open
Labels
gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools ToolProposal Issues describing a requested change to a Go tool or command-line program. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@danvolchek
Copy link

danvolchek commented Feb 23, 2025

gopls version

Build info

golang.org/x/tools/gopls v0.18.0
golang.org/x/tools/[email protected] h1:oBmnrmi0Uk7Ea+ZPK16BdcjnpEJX8ciBCSp9S90GULo=
github.com/BurntSushi/[email protected] h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0=
golang.org/x/[email protected] h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/[email protected] h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/[email protected] h1:L2k9GUV2TpQKVRGMjN94qfUMgUwOFimSQ6gipyJIjKw=
golang.org/x/[email protected] h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/[email protected] h1:4+it9JYqVd2wIAapscAb5mUAI1yHY0u4B4idYPigWeE=
golang.org/x/[email protected] h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
honnef.co/go/[email protected] h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.24.0

go env

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/dan/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/dan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build274943017=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/dan/Desktop/Stuff/development/go-rw2/go.mod'
GOMODCACHE='/home/dan/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/dan/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/dan/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Using vscode, right clicked a method on a type, clicked rename symbol, typed in the new symbol name. In this case, a file in the same package had errors, but not the file containing the renaming

Minimal repro of the file layout: https://go.dev/play/p/FlfMX-TSaGt

What did you see happen?

renaming "doFoo" to "reallyDoFoo" not possible because "foobar.go" in "play.ground/foo" has errors

What did you expect to see?

I expected the renaming to succeed. Renaming doFoo does not affect foobar.go at all - foobar.go does not reference doFoo anywhere.

I'm mostly used to IntelliJ IDEA and my license expired so I can't test, I'm pretty sure it succeeded the renaming in this case.

Or rather, I've never had a renaming fail that I can remember when using IntelliJ, but when using vscode/gopls I run into this error multiple times per day because I'm starting a new project and a lot of files are changing at once - it's frustrating!

Editor and settings

Vscode: code -v:

1.97.2
e54c774e0add60467559eb0d1e229c6452cf8447
x64

settings.json:

{
    "gopls": {
        "ui.diagnostic.staticcheck": true
    },
    "[go]": {
        "editor.formatOnSave": true
    },
    "go.toolsManagement.autoUpdate": true
}

Go extension version 0.44.0.

Logs

(verbose logging enabled)

[Trace - 16:53:26.525 PM] Sending request 'textDocument/prepareRename - (45)'.
Params: {"textDocument":{"uri":"file:///path/to/code/foo/foo.go"},"position":{"line":5,"character":16}}


[Trace - 16:53:26.526 PM] Received response 'textDocument/prepareRename - (45)' in 0ms.
Result: {"range":{"start":{"line":5,"character":14},"end":{"line":5,"character":19}},"placeholder":"doFoo"}


[Trace - 16:53:29.131 PM] Sending request 'textDocument/rename - (46)'.
Params: {"textDocument":{"uri":"file:///path/to/code/foo/foo.go"},"position":{"line":5,"character":16},"newName":"reallyDoFoo"}


[Error - Received] 16:53:29.131 PM #46 renaming "doFoo" to "reallyDoFoo" not possible because "foobar.go" in "play.ground/foo" has errors


[Error - 4:53:29 PM] Request textDocument/rename failed.
  Message: renaming "doFoo" to "reallyDoFoo" not possible because "foobar.go" in "play.ground/foo" has errors
  Code: 0 
@danvolchek danvolchek added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Feb 23, 2025
@gopherbot gopherbot added this to the Unreleased milestone Feb 23, 2025
@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Feb 23, 2025
@findleyr findleyr changed the title x/tools/gopls: improve rename functionality in face of errors x/tools/gopls: improve method rename functionality in face of errors Feb 23, 2025
@findleyr
Copy link
Member

This error message is specific to renaming methods, because the 'satisfy' constraint checker is strict about type errors, since they may affect the set of other methods that need to be renamed in order to preserve assignability.

However, elsewhere we've just removed the error and let the renaming proceed, and it has generally been fine. In this case, a best-effort renaming would probably succeed most of the time.

@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Feb 23, 2025
@findleyr findleyr added the Refactoring Issues related to refactoring tools label Feb 24, 2025
@adonovan
Copy link
Member

adonovan commented Feb 24, 2025

Also: if #70638 makes it into go1.25, the satisfy package will become a trivial wrapper around types.Info, making it much more robust in the face of type errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools ToolProposal Issues describing a requested change to a Go tool or command-line program. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants