x/tools/refactor: "Extract" features #10736
Labels
Refactoring
Issues related to refactoring tools
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
This is a feature request, not a bug.
It would be nice to have a command that makes it easy to extract methods and functions from code.
Something like: a command that takes a range of code in a file that should be replaced with a function or method call and a name for that function or method (let's just call it "func").
The code in the given range would be replaced in the file with a call to the new func (with return values, too) and a definition of the func would be inserted into the current file next door to the current func (or, wherever the struct is defined in the current package if it's only in one place). The arguments and return value for the func would be inferred from the variables the code range uses.
It would be nice for the command to infer whether to build a function or method by looking to see if the range of code given is inside a method and if the code refers to the method's target.
More magic would be to allow the addition of functions and methods to structs in other packages with this tool.
The text was updated successfully, but these errors were encountered: