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: support renaming a package #41567

Open
golopot opened this issue Sep 23, 2020 · 4 comments
Open

x/tools/gopls: support renaming a package #41567

golopot opened this issue Sep 23, 2020 · 4 comments

Comments

@golopot
Copy link

@golopot golopot commented Sep 23, 2020

What did you do?

  1. Open a go file in vscode
  2. Put keyboard cursor on the line package somepackage.
  3. Press F2 (rename symbol)

What did you expect to see?

Let me rename package.

What did you see instead?

This element cannot be renamed.

Build info

golang.org/x/tools/gopls v0.5.0
go version go1.15 linux/amd64

@gopherbot gopherbot added this to the Unreleased milestone Sep 23, 2020
@stamblerre stamblerre changed the title x/tools/gopls: rename package feature request x/tools/gopls: support renaming a package Sep 23, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Sep 23, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@msAlcantara
Copy link

@msAlcantara msAlcantara commented Jun 26, 2021

There is some tips to implement this? I think that this could be super useful and I would like to implements. I think that the implementation should be in qualifiedObjsAtProtocolPos function, I'm in the right way?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 28, 2021

@msAlcantara: Thanks for your interest! I think this is slightly more complicated than that because the package name declaration does not have a types.Object, so I don't think it would work in the framework of qualifiedObjsAtProtocolPos. Still, renaming a package should be a lot simpler than a standard rename, because you can access the position of the package name by looking at the AST of each file in the package (https://pkg.go.dev/go/ast#File.Package). There will be some complexity with test packages, but hopefully it's as simple as updating their names too. Does that help at all?

@msAlcantara
Copy link

@msAlcantara msAlcantara commented Jul 7, 2021

Thanks very much for your awnser, but I have some question about it.

  1. There something that tell me that the rename is of package name?
  2. Do you think that is better change qualifiedObjsAtProtocolPos to support rename a package or is better do something like this: if isPackageRename(...) { ... }?

Sorry is this questions is too dump, I'm a just getting started with gopls source code and I'm trying to understand

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jul 13, 2021

Please don't apologize--this is a tricky issue! I think the easiest thing would be to do something like if isPackageRename(...) in the rename logic itself (not in qualifiedObjsAtProtocolPos).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants