golang/go

x/tools/gopls: rename fails with "no object found" when the old identifier is missing a declaration

Open

#41,851 opened on Oct 7, 2020

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Go (19,008 forks)batch import
FeatureRequestToolsgoplshelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

What version are you using?

~$ go version -m $(which gopls)
/usr/local/google/home/bcmills/bin/gopls: devel +186f0220d0 Mon Oct 5 11:12:24 2020 -0400
        path    golang.org/x/tools/gopls
        mod     golang.org/x/tools/gopls        v0.5.1  h1:AF3Uh7HF08SZpKFfgJO6zfF3bbxyDXWqdkK4kMXiQ1o=
        dep     github.com/BurntSushi/toml      v0.3.1  h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
        dep     github.com/google/go-cmp        v0.5.1  h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
        dep     github.com/sergi/go-diff        v1.1.0  h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
        dep     golang.org/x/mod        v0.3.0  h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
        dep     golang.org/x/sync       v0.0.0-20200625203802-6e8e738ad208      h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
        dep     golang.org/x/tools      v0.0.0-20200930165741-f1523d29dbb9      h1:1R38tQp22dcHpTKJPjgVa16FhlDy/kHEaCM/ndi/FIc=
        dep     golang.org/x/xerrors    v0.0.0-20200804184101-5ec99f83aff1      h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
        dep     honnef.co/go/tools      v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=
        dep     mvdan.cc/gofumpt        v0.0.0-20200802201014-ab5a8192947d      h1:t8TAw9WgTLghti7RYkpPmqk4JtQ3+wcP5GgZqgWeWLQ=
        dep     mvdan.cc/xurls/v2       v2.2.0  h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Does this issue reproduce with the latest release?

Yes

What did you do?

(https://play.golang.org/p/OSPW1IIzNCs)

  1. Using emacs with gopls via eglot, start with a program with an existing undeclared identifier used in several places. (For this example, errNo.)
  2. Add a declaration for a new identifier in local scope, but choose a better name for it (errno).
  3. Remember that you also need to rename the existing uses of that identifier.
  4. Place the point at an occurrence of the old identifier and execute M-x eglot-rename.
  5. Type in the name of the identifier from step (2).

What did you expect to see?

References to the (now-undeclared) variable at the point should be renamed so that they now refer to the identifier in step (2).

What did you see instead?

gopls returns a no object found error.

As reported by M-x eglot-events-buffer:

[client-request] (id:9) Wed Oct  7 14:42:34 2020:
(:jsonrpc "2.0" :id 9 :method "textDocument/rename" :params
					(:textDocument
					 (:uri "file:///tmp/tmp.Ih8P4GysfM/example.com/main.go")
					 :position
					 (:line 13 :character 23)
					 :newName "errno"))
[server-reply] (id:9) ERROR Wed Oct  7 14:42:34 2020:
(:jsonrpc "2.0" :error
					(:code 0 :message "no object found for \"errNo\": no object found")
					:id 9)

Contributor guide