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/refactor: "Extract" features #10736

Open
jmhodges opened this issue May 7, 2015 · 3 comments
Open

x/tools/refactor: "Extract" features #10736

jmhodges opened this issue May 7, 2015 · 3 comments
Labels
Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@jmhodges
Copy link
Contributor

jmhodges commented May 7, 2015

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.

@jmhodges
Copy link
Contributor Author

jmhodges commented May 7, 2015

A modern example of this tooling, including the determination of arguments and return values, can be found in IntelliJ's Extract Method when writing Java code.

(IntelliJ's Extract Method, Extract Constant, etc. will also look for nearby code in the same scope as the containing method that has the same AST structure and ask if the user would like to use the method for that code as well. That would be great extra magic, but I wouldn't want to gate a first version on that.)

@blinsay
Copy link

blinsay commented May 7, 2015

It would also be awesome to have the ability to extract a constant too.

@akavel
Copy link
Contributor

akavel commented Feb 4, 2016

For the record, a tool implementing this seems now to be available at:

https://github.com/godoctor/godoctor (see: http://gorefactor.org/doc.html#refactoring-extract)

(reportedly created under Alan's guidance)

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
@adonovan adonovan added the Refactoring Issues related to refactoring tools label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

7 participants