-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Feat request: extract code (not only function) to file (resolving needed imports) #331
Comments
Hi @danielo515 Extract block extracts everything in the current block scope to another function (the block scope is typically the entire function body, though sometimes it changes). Right now, the functionality you're looking for (extracting entire functions themselves to different files, while updating imports) is not supported. The closest thing that exists right now would be "Extract Block/Function to File", which extracts block of code to a function, and puts that function in another file. Hopefully that clears up why it didn't work in this case. While we don't support that feature now, we can keep this issue open so that we can track it and perhaps implement it in the future. If you'd like to try making a contribution as well, feel free to do so, and we can review it for you! |
Hello @pranavrao145 , thank you for your answer
That is not exactly what I wanted. What I want is a bit more advanced than that. I wanted to be able to select a visual region, which may include constants, variables, function declarations etc, and extract those into a separate file, adding only the requried exports. So for example, if there is a constant used only by the function that I am moving to a new file, then only the function will need to be re-imported. But even without that functionality, and if it ended importing all the things that have been moved that will still be valuable to me. |
Hi @danielo515, sorry for the late reply - but yes, that makes sense. Sadly, we don't have support for that right now, but I will label this as a feature request so we can work on it later on! |
Hello.
First, thanks for this plugin, seems to be what I need, albeit I am not yet sure.
For some weird reason, there is no tool when you want to extract a bunch of code to a new file. I'm not talking about a single function, but a group of functions, variables, etc.
I am trying to use Block refactor, but it is always failing everything I tried with typescript. I first tried to refactor a constant, asks me for the file name, then something I don't know what it is, and then fails.
I just tried within a function body, and that seems to be understood as a block, and, to my surprise, rather than extracting the entire function, only the function body is extracted. Am I misunderstood the usage of the plugin? I want to be able to
Not sure if it is worth explaining the errors I'm getting if I didn't understood the purpose of the plugin properly.
Regaards
The text was updated successfully, but these errors were encountered: