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: rename fails with "no object found" when the old identifier is missing a declaration #41851

Open
bcmills opened this issue Oct 7, 2020 · 1 comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@bcmills
Copy link
Contributor

bcmills commented Oct 7, 2020

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)
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Oct 7, 2020
@gopherbot gopherbot added this to the Unreleased milestone Oct 7, 2020
@bcmills bcmills changed the title x/tools/gopls: rename fails when the old identifier is missing a declaration x/tools/gopls: rename fails with "no object found" when the old identifier is missing a declaration Oct 7, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Oct 8, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@muirdm
Copy link

muirdm commented Nov 21, 2020

Renaming without complete type information will always be somewhat dicey because we can't be certain of the user's intent starting with an invalid program. Renaming an undeclared identifier to a declared name may be an exception, but I'm not sure. Consider this contrived example:

func _() {
  oldName = "hi"
  {
    var newName int
    {
      oldName = "hello"
    }
    {
      oldName = 123
    }
}

Does it make sense to try to rename any of the oldNames in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants