0

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.

Mani
  • 2,599
  • 4
  • 30
  • 49

1 Answers1

4

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.

icza
  • 389,944
  • 63
  • 907
  • 827
  • Is there any tool that can give me all error lines of each file reporting unknown literal by parsing whole project? – Mani Jun 23 '21 at 07:35
  • 2
    @Mani Build the project with `go build ./...` and it'll give you the errors. IDEs will also show you all the lines where compilation fails. – icza Jun 23 '21 at 07:36