gointellij-ideaautomated-refactoringvim-go

How to safe delete the usages of struct field on all files from Intellij?


Though we have refactoring tool to rename the struct field we do not have refactoring tool for deleting the struct field & its usages.

How to safely delete the struct field and its usages[Write & read access] across the files from any IDE that supports golang?

As far as I have seen none of the IDE(vim-go, intellij) supports this.

I had thought of deleting the struct field & run

go vet

which will return all error(along with line number) on every file & write a script to delete those lines but unfortunately vet stops reporting errors after very first error encountered in a file.


Solution

  • This is not something that could be fully automated. Let's say you remove the field X from the type Point struct {X, Y int}. What should the IDE do when it's used like this:

    p := Point{X: 1, Y: 2}
    r := p.X / p.Y
    

    Or like this:

    func f(x, y int) {}
    
    f(p.X, p.Y)
    

    What's needed is obviously not something the IDE could "guess".

    To delete a struct field, delete it from the type definition and proceed to fix the compiler errors manually.