eclipsegogoclipse

Renaming package in goclipse causes problems


I use Eclipse as IDE for Go (I guess it's called "Goclipse"), developing a web application. All went good and nice until I started to split functionality in smaller packages. Initially I had a package gitserver/user/project/portal. File main.go imported it and everything was working. I suddenly realized, that it should be called gitserver/user/project/webserver instead, and some other files and functionality should go into .../portal. So I did "Rename", by right clicking in Project Explorer.

main.go:

package main
import(
  "gitserver/user/project/webserver"
)

func main(){
  webserver.DoSomeStuff()
}

Compiler complains that

[...]

How to untie the "webserver" package from its old name?


Solution

  • GoClipse doesn't actually do any tracking of the old name after the rename is done. Based on what you describe and the error imported and not used "gitserver/user/project/webserver" as portal you probably have an import line along the lines of portal "gitserver/user/project/webserver" somewhere, and probably in the same file it uses webserver.. Double check all your imports because these errors absolutely sound like the rename just got a little mixed up (something that's not uncommon when doing a rename and reusing the old name).

    Goclipse may not find every kind of reference to the package when renaming; the change might not be cascaded throughout the project, or even the package files. When you rename a folder, check that the package line has been changed in the package files, and update them if not.